--- id: django-stubs version: "6.1.0" license: MIT license_treatment: permissive maintenance: active --- # django-stubs — Mypy stubs for Django License: permissive · Maintenance: active · Downloads: 11.1M/mo ## 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 above — 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 pip install django-stubs uv add django-stubs 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_current - Install friction: low - Maintenance: active - Downloads: 11.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags django type stubs mypy, django static type checking, mypy plugin django, django type hints, django typing support, django type annotations, mypy django types, type-checking, mypy-plugin [View on SkillFed](https://skillfed.io/packages/django-stubs) · [View on PyPI](https://pypi.org/project/django-stubs/)