--- id: django-stubs-ext version: "6.1.0" license: MIT license_treatment: permissive maintenance: active --- # django-stubs-ext — Monkey-patching and extensions for django-stubs License: permissive · Maintenance: active · Downloads: 12.1M/mo ## 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 above — 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 pip install django-stubs-ext uv add django-stubs-ext poetry add django-stubs-ext ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 12.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags django type hints runtime, django-stubs extensions, django generic class patching, django typing support, django __class_getitem__ monkey patch, django-typing, type-hints, monkey-patching [View on SkillFed](https://skillfed.io/packages/django-stubs-ext) · [View on PyPI](https://pypi.org/project/django-stubs-ext/)