skillfed

drf-pydantic

Use pydantic with the Django REST framework

drf-pydantic v2.9.1 173.3K downloads/30d#10,313 on PyPI147
Permissive license MIT AGING released

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-pydantic

uv

uv add drf-pydantic

poetry

poetry add drf-pydantic

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

pydantic django rest framework integrationdrf serializer from pydantic modeldjango rest framework validationpydantic drf bridgeautomatic serializer generationpydantic v2 drf supportrest api validation pydantic
django-rest-frameworkpydantic-v2serialization

More Python Modules packages

idna

Converts domain names between Unicode and…

permissive · top 100 on PyPI

setuptools

Setuptools is a Python build backend and…

permissive · top 100 on PyPI

PyYAML

PyYAML parses and emits YAML 1.1 data format,…

permissive · top 100 on PyPI

pydantic

Pydantic validates Python data structures…

permissive · top 100 on PyPI

annotated-types

Provides reusable metadata objects for use with…

permissive · top 100 on PyPI

typing-inspection

Provides runtime tools to inspect and…

permissive · top 100 on PyPI

djangorestframework-dataclasses

Automatically generates Django REST Framework…

permissive · top 5,000 on PyPI

django-pydantic-field

Provides type-safe Pydantic model schemas for…

permissive · top 5,000 on PyPI

pydantic_yaml

Pydantic-YAML adds YAML serialization and…

permissive · top 5,000 on PyPI

drf-recaptcha

Adds reCAPTCHA v2 and v3 field validation to…

permissive · top 15,000 on PyPI

pydantic-collections

Provides a `BaseCollectionModel` class that…

permissive · top 15,000 on PyPI

drf-jsonschema-serializer

Converts Django REST Framework serializers to…

permissive · top 15,000 on PyPI

pydantic-extra-types

Provides additional type validators and…

permissive · top 1,000 on PyPI

Flask-Pydantic

Adds Pydantic model validation to Flask route…

permissive · top 15,000 on PyPI

pydantic-function-models

Wraps Python functions to validate their…

permissive · top 15,000 on PyPI

drf-dynamic-fields

Provides a Django REST Framework mixin that…

permissive · top 15,000 on PyPI