PEP-484 type stubs and a mypy plugin for precise static type checking in Django projects.
django-stubs is a collection of PEP-484 type stubs and a custom mypy plugin designed to provide precise static type checking for Django applications. It addresses Django's dynamic patterns that are problematic for standard type checkers, enabling developers to catch type-related errors early and improve code quality.
Django developers who use mypy for static type checking and want to enhance type safety in their projects, especially those working on large or complex codebases where maintainability is critical.
Developers choose django-stubs because it offers the most comprehensive and accurate type definitions for Django, along with a dedicated mypy plugin that understands Django's magic, reducing false positives and enabling type checking for patterns that are otherwise untyped.
PEP-484 stubs for Django
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides PEP-484 stubs for core Django modules and a custom mypy plugin that accurately infers types for models, querysets, and managers, as shown in the handling of TypedModelMeta and generics.
Only affects the mypy type checking process without impacting Django runtime performance, ensuring it's safe for production use, as confirmed in the FAQ.
Supports configuration via mypy.ini, setup.cfg, or pyproject.toml with settings like strict_settings for dynamic environments, allowing adaptability to various project structures.
Maintains detailed compatibility tables for Django, mypy, and Python versions, and integrates with related projects like djangorestframework-stubs for extended type coverage.
Requires installing and monkeypatching django-stubs-ext to enable generic types like QuerySet[MyModel], adding an extra step and potential maintenance burden.
The mypy plugin uses Django's runtime to extract model information, so broken Django code can cause mypy to crash, as noted in the FAQ about manage.py issues.
For patterns like QuerySet.annotate, types aren't fully inferred; manual annotations with WithAnnotations and TypedDict are needed, increasing complexity for advanced use cases.