django-types
Type stubs for Django
What it is and what it does
django-types is a type stub package that adds static type information for Django, enabling type checkers like mypy and pyright to understand Django's API. It was forked from django-stubs specifically to remove the mypy plugin dependency, which means it works with multiple type checkers and avoids crashes caused by Django configuration issues.
The package helps developers annotate Django models, querysets, managers, and HTTP request objects with proper types. It includes guidance for common patterns like foreign key relationships, related managers, and authenticated request handlers. Since Django's ORM classes don't support runtime subscripting (e.g., QuerySet[MyModel]), the stubs document workarounds using string annotations or a companion monkeypatch utility.
Use it for:
- Add type hints to Django ORM models so foreign keys and related managers are properly typed for IDE autocomplete and type checking
- Enable pyright or other non-mypy type checkers to validate Django code without plugin crashes
- Annotate view functions with typed HttpRequest subclasses to enforce authentication requirements at the type level
- Catch type errors in Django querysets and manager calls during development rather than at runtime
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides type stubs for Django to enable static type checking with mypy, pyright, and other type checkers without requiring a mypy plugin.
Yes. django-types is actively maintained, has no known vulnerabilities, low install friction, and is essential for any Django project using static type checking. The MIT license is permissive. Install it if you use type checkers with Django; it's a standard practice for modern Django development.
Install
django-types on PyPI
pip
pip install django-typesuv
uv add django-typespoetry
poetry add django-typesInstalling django-types
Before you install
Low install friction with a single runtime dependency (types-psycopg2). Actively maintained with recent releases; last commit 2026-06-23 and latest release 2026-04-22.
License in practice
MIT license permits commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install django-types
# In your Django model:
from typing import Optional
from django.db import models
class User(models.Model):
team_id: Optional[int]
team = models.ForeignKey('Team', null=True, on_delete=models.SET_NULL)
Requires Python 3.10 or later. QuerySet and Manager generics do not support subscripting at runtime; use string annotations or django_stubs_ext.monkeypatch() as a workaround.
Verify before relying
- Whether type coverage is complete for all Django ORM features and edge cases
- Performance impact of type checking with these stubs on typical Django projects
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — types-psycopg2 |
| Maintenance | actively maintained — 114 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,069,134/month — #4,409 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_types-0.24.0-py3-none-any.whl
Keywords: django, mypy, stubs, types
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
django-stubsProvides type stubs and a mypy plugin to enable…
permissive · top 5,000 on PyPI
djangorestframework-typesProvides type stubs for Django Rest Framework,…
permissive · top 15,000 on PyPI
msgpack-typesProvides type stubs for msgpack to enable…
permissive · top 15,000 on PyPI
pytest-mypy-pluginsA pytest plugin that runs type-checking tests…
permissive · top 15,000 on PyPI
django-stubs-extProvides runtime monkey-patching extensions for…
permissive · top 5,000 on PyPI
celery-typesProvides type stubs for Celery and related…
permissive · top 5,000 on PyPI
pyre-extensionsProvides typing extensions for the Pyre type…
permissive · top 5,000 on PyPI
types-SQLAlchemyProvides PEP 561 type stubs for SQLAlchemy,…
permissive · top 15,000 on PyPI
tightwrapA drop-in replacement for `functools.wraps`…
permissive · top 15,000 on PyPI
types-Flask-SQLAlchemyProvides type stubs for Flask-SQLAlchemy to…
permissive · top 15,000 on PyPI