django-stubs
Mypy stubs for Django
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-stubsuv
uv add django-stubspoetry
poetry add django-stubsInstalling 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
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
django-stubs-extProvides runtime monkey-patching extensions for…
permissive · top 5,000 on PyPI
django-typesProvides type stubs for Django to enable static…
permissive · top 5,000 on PyPI
djangorestframework-typesProvides type stubs for Django Rest Framework,…
permissive · top 15,000 on PyPI
sqlalchemy-stubsProvides type stubs and a mypy plugin to enable…
permissive · top 5,000 on PyPI
djangorestframework-stubsProvides PEP-484 type stubs for Django REST…
permissive · top 5,000 on PyPI
google-auth-stubsProvides type stubs for the google-auth…
permissive · top 5,000 on PyPI
django-localflavorProvides country-specific form fields,…
permissive · top 5,000 on PyPI
django-dirtyfieldsTracks which fields on a Django model instance…
permissive · top 15,000 on PyPI
google-api-python-client-stubsProvides type stubs for…
permissive · top 5,000 on PyPI
mypyMypy is a static type checker for Python that…
permissive · top 1,000 on PyPI