--- id: drf-pydantic version: "2.9.1" license: MIT license_treatment: permissive maintenance: aging --- # drf-pydantic — Use pydantic with the Django REST framework License: permissive · Maintenance: aging · Downloads: 173.3K/mo ## 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 above — 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 pip install drf-pydantic uv add drf-pydantic 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_current - Install friction: low - Maintenance: aging - Downloads: 173.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pydantic django rest framework integration, drf serializer from pydantic model, django rest framework validation, pydantic drf bridge, automatic serializer generation, pydantic v2 drf support, rest api validation pydantic, django-rest-framework, pydantic-v2, serialization [View on SkillFed](https://skillfed.io/packages/drf-pydantic) · [View on PyPI](https://pypi.org/project/drf-pydantic/)