skillfed

django-stubs

Mypy stubs for Django

django-stubs v6.1.0 11.1M downloads/30d#1,414 on PyPI
Permissive license MIT Active released

What it is and what it does

django-stubs bridges the gap between Django's dynamic runtime behavior and static type checkers by providing type stubs and a custom mypy plugin. Django uses Python "magic" patterns that make precise type inference difficult; this package adds explicit type information so mypy can understand model fields, managers, querysets, and other framework patterns correctly.

The package is installed as a development dependency and does not affect runtime behavior—it only enhances the mypy type-checking process. It supports mypy with full advanced features, and provides basic support for pyright, pyrefly, and other type checkers. Configuration is minimal: add the plugin to your mypy config and specify your Django settings module, and type checking will immediately become more precise for common Django patterns.

Use it for:

  • Enable mypy to type-check Django model definitions, catching errors in field declarations and Meta class configurations before runtime.
  • Provide type hints for QuerySet and Manager operations so IDE autocomplete and type checkers understand query results and method chains.
  • Validate custom database routers and other Django components that inherit from typed base classes.
  • Catch type errors in Django views and forms by giving type checkers knowledge of Django's request/response and form field types.
  • Use TypedModelMeta to enforce correct types on model Meta attributes like ordering and constraints.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides type stubs and a mypy plugin to enable precise static type checking for Django code, handling Django's dynamic patterns that would otherwise confuse type checkers.

Yes. If you use Django and mypy, this is essential. It transforms mypy from a tool that struggles with Django's dynamic patterns into one that catches real errors in model definitions, querysets, and views. The package is actively maintained, has no known vulnerabilities, and is permissively licensed. Install it as a development dependency with no runtime cost.

Install

django-stubs on PyPI

pip

pip install django-stubs

uv

uv add django-stubs

poetry

poetry add django-stubs

Installing django-stubs

Before you install

Low friction installation as a pure Python wheel with straightforward dependencies. Actively maintained with a release 2 days ago.

License in practice

MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects.

Quickstart

pip install django-stubs[compatible-mypy]

Then add to mypy.ini or pyproject.toml:
[mypy]
plugins = mypy_django_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = "myproject.settings"

Requires mypy to be installed and configured; the plugin needs django_settings_module to be specified either in config or via DJANGO_SETTINGS_MODULE environment variable.

Verify before relying

  • Whether the custom mypy plugin's advanced features beyond basic type stubs are documented or discoverable without reading source code.
  • Performance impact of the mypy plugin on type-checking speed for large Django projects.
  • Exact scope of support for pyright, pyrefly, and other type checkers beyond mypy.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.11)
Install friction low — pure-Python wheel
Runtime dependencies 4 — django, django-stubs-ext, types-pyyaml, typing-extensions
Maintenance actively maintained — 2 days since the last release
First released
Downloads 11,148,392/month — #1,414 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_stubs-6.1.0-py3-none-any.whl

Framework :: DjangoFramework :: Django :: 5.2Framework :: Django :: 6.0Framework :: Django :: 6.1Operating System :: OS IndependentProgramming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Typing :: Typed

Tags

django type stubs mypydjango static type checkingmypy plugin djangodjango type hintsdjango typing supportdjango type annotationsmypy django types
type-checkingmypy-plugin

More Quality Assurance packages