skillfed

django-pydantic-field

Type-Safe Pydantic Schemas for Django JSONFields

django-pydantic-field v0.5.4 1.6M downloads/30d#3,760 on PyPI218
Permissive license MIT Active released

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

uv

uv add django-pydantic-field

poetry

poetry add django-pydantic-field

Installing 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

Development Status :: 4 - BetaFramework :: DjangoFramework :: Django :: 3Framework :: Django :: 3.1Framework :: Django :: 3.2Framework :: Django :: 4Framework :: Django :: 4.0Framework :: Django :: 4.1Framework :: Django :: 4.2Framework :: Django :: 5Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Framework :: PydanticFramework :: Pydantic :: 1Framework :: Pydantic :: 2Intended Audience :: DevelopersProgramming 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.14

Tags

django jsonfield pydantictype-safe django json schemapydantic django integrationdjango rest framework pydanticdjango admin pydantic modelsjson validation djangopydantic v1 v2 django
django-integrationpydantic-schemastype-safety

More Application Frameworks packages