drf-pydantic
Use pydantic with the Django REST framework
What it is and what it does
drf-pydantic lets you use pydantic models as the source of truth for data validation in Django REST framework APIs. Instead of writing separate DRF serializers, you define a pydantic model using drf-pydantic's BaseModel, and the package automatically generates an equivalent DRF serializer accessible via the model's drf_serializer attribute. The translation happens at class creation time, so there is no runtime overhead during request handling.
The package supports pydantic v2 and integrates pydantic's validation rules into DRF's serializer validation pipeline. You can enable full pydantic validation by setting validate_pydantic to True in the model's drf_config, which runs pydantic's validators whenever the DRF serializer validates data. It also handles nested models, field customization, and error wrapping so that pydantic ValidationErrors appear as DRF ValidationErrors in your API responses.
Use it for:
- Build REST APIs where pydantic models define both your data schema and validation logic, eliminating duplicate serializer definitions.
- Migrate existing pydantic-based services to Django REST framework without rewriting validation rules.
- Leverage pydantic's validation within DRF views for complex field or model-level validation.
- Extend existing pydantic models with DRF serialization by adding drf_pydantic.BaseModel as a parent class.
- Access the fully validated pydantic instance via the pydantic_instance property after validation succeeds.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Bridges pydantic models and Django REST framework by automatically generating DRF serializers from pydantic model definitions, enabling pydantic validation within DRF views.
Yes. The package is production-stable (Development Status 5), has no known vulnerabilities, and solves a real friction point for teams using both pydantic and Django REST framework. Low install friction and active maintenance make it a straightforward addition. Install it if you are building DRF APIs and want to unify your validation layer around pydantic models.
Install
drf-pydantic on PyPI
pip
pip install drf-pydanticuv
uv add drf-pydanticpoetry
poetry add drf-pydanticInstalling drf-pydantic
Before you install
Low friction install with only two runtime dependencies (djangorestframework and pydantic). Repository shows active maintenance with recent commits and no archived status, though the aging signal suggests releases are spaced further apart.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for commercial and open-source projects alike.
Quickstart
pip install drf-pydantic
from drf_pydantic import BaseModel
class MyModel(BaseModel):
name: str
addresses: list[str]
my_serializer = MyModel.drf_serializer(data={"name": "Van", "addresses": ["Gym"]})
my_serializer.is_valid(raise_exception=True)
Verify before relying
- Whether the translation from pydantic to DRF serializers handles all pydantic field types and validators without gaps.
- Performance characteristics when validate_pydantic is enabled on large or deeply nested models.
- Compatibility guarantees with specific versions of djangorestframework beyond the runtime dependency declaration.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — djangorestframework, pydantic |
| Maintenance | aging — 243 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 173,258/month — #10,313 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drf_pydantic-2.9.1-py3-none-any.whl
Keywords: api, django, drf, pydantic, rest, typing
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
djangorestframework-dataclassesAutomatically generates Django REST Framework…
permissive · top 5,000 on PyPI
django-pydantic-fieldProvides type-safe Pydantic model schemas for…
permissive · top 5,000 on PyPI
pydantic_yamlPydantic-YAML adds YAML serialization and…
permissive · top 5,000 on PyPI
drf-recaptchaAdds reCAPTCHA v2 and v3 field validation to…
permissive · top 15,000 on PyPI
pydantic-collectionsProvides a `BaseCollectionModel` class that…
permissive · top 15,000 on PyPI
drf-jsonschema-serializerConverts Django REST Framework serializers to…
permissive · top 15,000 on PyPI
pydantic-extra-typesProvides additional type validators and…
permissive · top 1,000 on PyPI
Flask-PydanticAdds Pydantic model validation to Flask route…
permissive · top 15,000 on PyPI
pydantic-function-modelsWraps Python functions to validate their…
permissive · top 15,000 on PyPI
drf-dynamic-fieldsProvides a Django REST Framework mixin that…
permissive · top 15,000 on PyPI