django-pydantic-field
Type-Safe Pydantic Schemas for Django JSONFields
What it is and what it does
django-pydantic-field bridges Pydantic and Django by allowing you to use Pydantic models as schemas for Django's JSONField. Instead of storing raw JSON and manually validating it, you define a Pydantic model and attach it to a SchemaField—the package then automatically parses incoming JSON into typed Pydantic instances and validates them against your schema. It handles both Pydantic v1 and v2 through a unified API, so you don't need to rewrite code if you upgrade.
The package integrates deeply with Django's ecosystem: it works with Django Forms and the Admin interface for validation and editing, provides typed serializers and parsers for Django REST Framework with automatic OpenAPI schema generation, and supports forward references for schemas defined later in your code. Type checkers like mypy and pyright can infer the correct types for your model fields, making it safe to use in statically typed codebases.
Use it for:
- Store complex nested configuration objects in a Django model with automatic Pydantic validation and type safety.
- Build Django REST Framework APIs where request/response bodies are strongly typed Pydantic models with auto-generated OpenAPI docs.
- Migrate from raw JSON storage to typed schemas without rewriting your entire data layer.
- Use Django Admin to edit JSON data with form validation powered by Pydantic field constraints.
- Define forward-referenced schemas that resolve lazily, allowing circular dependencies between models.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides type-safe Pydantic model schemas for Django JSONFields with automatic validation, supporting both Pydantic v1 and v2, and integrating with Django Forms, Admin, and Django REST Framework.
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a real friction point—type-safe JSON storage in Django. It's particularly valuable if you use Django REST Framework and need automatic schema generation, or if you want static type checking on JSON data. The dual Pydantic v1/v2 support makes it safe to adopt even if your environment is in transition.
Install
django-pydantic-field on PyPI
pip
pip install django-pydantic-fielduv
uv add django-pydantic-fieldpoetry
poetry add django-pydantic-fieldInstalling django-pydantic-field
Before you install
Low friction install with three straightforward runtime dependencies. Actively maintained with a recent commit on 2026-02-22 and no known vulnerabilities.
License in practice
MIT license permits unrestricted use, modification, and distribution in commercial and private projects with minimal restrictions.
Quickstart
pip install django-pydantic-field
from django.db import models
from django_pydantic_field import SchemaField
import pydantic
class Foo(pydantic.BaseModel):
count: int
slug: str = "default"
class MyModel(models.Model):
foo: Foo = SchemaField()
model = MyModel(foo={"count": 42})
model.save()
assert isinstance(model.foo, Foo)
Requires Python 3.10 or later.
Verify before relying
- Whether forward reference resolution handles all edge cases in complex schema hierarchies.
- Performance characteristics when handling large nested Pydantic structures in JSONFields.
- Compatibility with custom Pydantic validators and field serializers in both v1 and v2.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — pydantic, django, typing-extensions |
| Maintenance | actively maintained — 173 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,560,320/month — #3,760 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_pydantic_field-0.5.4-py3-none-any.whl
Keywords: django, pydantic, json, schema
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
jsonschema-pydanticConverts JSON Schema definitions into Pydantic…
unclear · top 15,000 on PyPI
pydantic-extra-typesProvides additional type validators and…
permissive · top 1,000 on PyPI
pydantic-partialConverts pydantic models into partial variants…
permissive · top 15,000 on PyPI
safety-schemasProvides Pydantic models and schemas for Safety…
permissive · top 5,000 on PyPI
drf-pydanticBridges pydantic models and Django REST…
permissive · top 15,000 on PyPI
pydantic-function-modelsWraps Python functions to validate their…
permissive · top 15,000 on PyPI
sigstore-modelsProvides Pydantic-based data models that mirror…
unclear · top 15,000 on PyPI
pydantic_yamlPydantic-YAML adds YAML serialization and…
permissive · top 5,000 on PyPI
json-schema-to-pydanticAutomatically generates Pydantic v2 models from…
permissive · top 5,000 on PyPI
pydantic-compatProvides compatibility mixins and adapters to…
permissive · top 15,000 on PyPI