Registry /
type-stubs / djangorestframework-stubs
Install & Compatibility
Where this runs
tested against v3.18.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 72.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 4.2s · import 0.000s · 73MB
72MB installed
● package 72MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ModelSerializer
✓ from rest_framework_stubs.serializers import ModelSerializer
✗ from rest_framework_stubs.serializers import ModelSerializer
This example showcases type-hinted Django REST Framework components. When `djangorestframework-stubs` is installed alongside `django-stubs` and `mypy` with the respective plugins configured, your static type checker will enforce type correctness for DRF-specific constructs like `serializers`, `views`, and `requests` at development time.
import os
from django.db import models
from rest_framework import serializers, viewsets
from rest_framework.response import Response
from rest_framework.request import Request # For type hinting
# A minimal Django model (assuming Django and django-stubs are installed)
class MyModel(models.Model):
name: models.CharField = models.CharField(max_length=100)
value: models.IntegerField = models.IntegerField()
def __str__(self) -> str:
return self.name
# A DRF ModelSerializer for MyModel
class MyModelSerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = ['id', 'name', 'value']
# A DRF ViewSet for MyModel
class MyModelViewSet(viewsets.ModelViewSet):
queryset = MyModel.objects.all()
serializer_class = MyModelSerializer
# Example of a custom action with type hints
def list(self, request: Request, *args, **kwargs) -> Response:
# With djangorestframework-stubs installed, MyPy can check types here.
# For instance, ensuring 'request.user' (if present) is accessed correctly.
queryset = self.filter_queryset(self.get_queryset())
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
# To utilize these stubs, configure MyPy (e.g., in pyproject.toml or mypy.ini):
# [tool.mypy]
# plugins = [
# "mypy_django_plugin.main",
# "mypy_drf_plugin.main"
# ]
# strict = true
# Then run: `mypy your_app_name/`
# This code focuses on demonstrating type hinting for DRF components,
# not on running a live Django/DRF application.
Upgrade
Version history
3.18.1latest on PyPI · released Aug 25, 2026
Audit
Dependencies
django-stubsrequiredProvides type stubs for Django, which DRF depends on.
djangorestframeworkrequiredThe core library for which these stubs are provided.
mypyrequiredThe primary static type checker these stubs are designed for.
types-requestsoptionalOptional dependency for type hints related to `rest_framework.test.RequestsClient`.