django-stubs-ext
Monkey-patching and extensions for django-stubs
What it is and what it does
django-stubs-ext is a companion package to django-stubs that applies runtime monkey-patching to Django classes to support generic type hints. Django's built-in classes don't define the `__class_getitem__` method needed for proper typing with generic syntax, so this package adds that method at runtime. The package is designed to be called once during Django application initialization, typically in settings, and intelligently patches only the features needed for your specific Django version.
The package exists because django-stubs itself is a type-stub-only library that can't perform runtime modifications. By splitting the runtime extensions into a separate package, applications using django-stubs avoid needing mypy as a production dependency. The monkey-patching is minimal and safe—it adds a `__class_getitem__` method that returns the class itself, enabling type checkers to understand generic Django class usage without breaking runtime behavior.
Use it for:
- Enable type hints for Django generic classes in projects using django-stubs without mypy as a runtime dependency.
- Support proper typing of Django QuerySet and Manager generics in IDE autocomplete and type checking.
- Ensure compatibility across multiple Django versions by applying version-specific patches at runtime.
- Integrate type safety into existing Django projects that rely on django-stubs for static type checking.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides runtime monkey-patching extensions for django-stubs to enable generic Django class type hints without requiring mypy as a runtime dependency.
Yes. If you use django-stubs for type checking, this package is essential—it's a lightweight, actively maintained companion that enables the type hints django-stubs provides to work correctly at runtime. Install it alongside django-stubs and call monkeypatch() once in your settings. No known vulnerabilities, permissive license, and minimal dependencies make it a safe addition.
Install
django-stubs-ext on PyPI
pip
pip install django-stubs-extuv
uv add django-stubs-extpoetry
poetry add django-stubs-extInstalling django-stubs-ext
Before you install
Low install friction with only 2 runtime dependencies (django and typing-extensions). Active maintenance with a release 2 days old.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects.
Quickstart
pip install django-stubs-ext
import django_stubs_ext
django_stubs_ext.monkeypatch()
Requires Python 3.11 or later; call monkeypatch() once in your Django settings, not repeatedly.
Verify before relying
- Whether the __class_getitem__ implementation handles all Django versions supported or only a subset.
- Performance impact of the monkey-patching at application startup.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — django, typing-extensions |
| Maintenance | actively maintained — 2 days since the last release |
| First released | |
| Downloads | 12,136,688/month — #1,339 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_stubs_ext-6.1.0-py3-none-any.whl
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
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
celery-typesProvides type stubs for Celery and related…
permissive · top 5,000 on PyPI
django-htmxProvides Django integration utilities for htmx,…
permissive · top 5,000 on PyPI
patchyPatchy modifies Python functions at runtime by…
permissive · top 5,000 on PyPI
grpc-stubsProvides type stubs for gRPC Python, enabling…
permissive · top 5,000 on PyPI
forbiddenfruitForbiddenfruit allows you to dynamically add…
unclear · top 5,000 on PyPI
typishTypish provides runtime type checking and…
permissive · top 5,000 on PyPI
pytest-stubA pytest plugin that replaces package, module,…
permissive · top 15,000 on PyPI