skillfed

djangorestframework-stubs

PEP-484 stubs for django-rest-framework

djangorestframework-stubs v3.18.0 6.3M downloads/30d#1,926 on PyPI
Permissive license MIT Active released

What it is and what it does

djangorestframework-stubs is a collection of type stubs that teach mypy how to understand Django REST Framework's type signatures. It bridges the gap between DRF's dynamic nature and Python's static type system, allowing you to catch type errors at development time rather than runtime.

The package works by providing stub files (.pyi) that describe DRF's public API in terms mypy understands, plus a mypy plugin that enhances inference for common patterns. You install it alongside your project's type-checking setup, configure mypy to load the plugin, and then annotate your code with generic type parameters to get precise type information for model instances and method signatures. It depends on django-stubs, typing-extensions, and types-pyyaml.

Use it for:

  • Catch type errors in CI/CD before deployment by running mypy on code using Django REST Framework.
  • Get IDE autocomplete and type hints when writing custom methods and validators.
  • Ensure serializer subclasses correctly type-hint their related model class to prevent Any inference.
  • Validate that view methods receive and return the correct types.
  • Migrate a Django REST Framework codebase toward full type safety incrementally.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides PEP-484 type stubs for Django REST Framework to enable mypy static type checking of DRF code.

Yes, if you use Django REST Framework and mypy for type checking. The package is actively maintained, has no known vulnerabilities, and low install friction. It's essential for teams that want static type safety in DRF projects. Install it as part of your development dependencies and configure the mypy plugin in your mypy.ini.

Install

djangorestframework-stubs on PyPI

pip

pip install djangorestframework-stubs

uv

uv add djangorestframework-stubs

poetry

poetry add djangorestframework-stubs

Installing djangorestframework-stubs

Before you install

Low install friction with a pure-wheel distribution. Actively maintained with a release 2 days ago. Requires Python 3.10 or later and depends on django-stubs, typing-extensions, and types-pyyaml.

License in practice

MIT license is permissive; you can use this in commercial and private projects with minimal restrictions.

Quickstart

pip install djangorestframework-stubs

Add to mypy.ini:
[mypy]
plugins =
    mypy_drf_plugin.main

Requires Python 3.10 or later; mypy must be configured with the mypy_drf_plugin.main plugin in mypy.ini for full type support.

Verify before relying

  • Whether the plugin handles all serializer patterns or has known gaps in type inference.
  • Performance impact of the mypy plugin on type-checking speed for large projects.
  • Specific version compatibility with different versions of django-stubs and typing-extensions.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 3 — django-stubs, typing-extensions, types-pyyaml
Maintenance actively maintained — 2 days since the last release
First released
Downloads 6,340,396/month — #1,926 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: djangorestframework_stubs-3.18.0-py3-none-any.whl

Framework :: DjangoLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Typing :: Typed

Tags

mypy stubs django rest frameworktype checking drfdjangorestframework type hintsstatic typing django restdrf mypy plugindjango rest framework stubs
type-checkingmypy-plugin

More Quality Assurance packages

coverage

Coverage.py measures which lines of Python code…

permissive · top 1,000 on PyPI

ruff

Ruff is a Python linter and code formatter…

permissive · top 1,000 on PyPI

pexpect

Pexpect spawns and controls interactive console…

permissive · top 1,000 on PyPI

black

Black reformats Python source code to a…

permissive · top 1,000 on PyPI

pytest-xdist

pytest-xdist distributes pytest tests across…

permissive · top 1,000 on PyPI

cfn-lint

Validates AWS CloudFormation templates in YAML…

permissive · top 1,000 on PyPI

djangorestframework-types

Provides type stubs for Django Rest Framework,…

permissive · top 15,000 on PyPI

django-stubs

Provides type stubs and a mypy plugin to enable…

permissive · top 5,000 on PyPI

django-filter-stubs

Provides PEP-484 type stubs for django-filter…

permissive · top 15,000 on PyPI

djangorestframework-dataclasses

Automatically generates Django REST Framework…

permissive · top 5,000 on PyPI

sqlalchemy2-stubs

Provides PEP-484 typing stubs for SQLAlchemy…

permissive · top 5,000 on PyPI

djangorestframework-gis

Adds geographic and GeoJSON support to Django…

permissive · top 15,000 on PyPI

drf-dynamic-fields

Provides a Django REST Framework mixin that…

permissive · top 15,000 on PyPI

django-rest-polymorphic

Provides polymorphic serializers for Django…

permissive · top 5,000 on PyPI

drf-recaptcha

Adds reCAPTCHA v2 and v3 field validation to…

permissive · top 15,000 on PyPI

rest-framework-generic-relations

Provides Django REST Framework serializers that…

permissive · top 15,000 on PyPI