pydantic-compat
Compatibility layer for pydantic v1/v2
What it is and what it does
pydantic-compat is a compatibility layer that lets you write pydantic models using either v1 or v2 API names while supporting both pydantic versions in a single codebase. It works by providing a mixin class and adapter functions that translate between the two APIs—for example, mapping `obj.dict()` to `obj.model_dump()` or vice versa depending on which pydantic version is installed. This eliminates the need for version-specific conditionals and boilerplate throughout your library code.
The package is not a full semantic bridge: it translates names and provides basic compatibility for common operations like validation, serialization, and schema access, but does not attempt to hide deeper behavioral differences between v1 and v2. You still need to test your code against both pydantic versions and understand what's changing under the hood. It's designed for library authors who want to support a range of pydantic versions without forcing users to pin a specific version.
Use it for:
- Library author supporting both pydantic v1 and v2 without version pinning or deprecation warnings
- Migrating a codebase from pydantic v1 to v2 incrementally while maintaining compatibility
- Defining models that work seamlessly when users have either pydantic version installed
- Reducing conditional version-checking code in model definitions and validation logic
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides compatibility mixins and adapters to use either pydantic v1 or v2 API names in a single codebase, regardless of which pydantic version is installed.
Yes, if you are a library author needing to support both pydantic v1 and v2 in the same codebase. The low install friction and active maintenance make it a practical choice. However, be aware that this is a name adapter, not a full semantic bridge—you will still need to test against both pydantic versions and handle any deeper API differences yourself. Not necessary if you can pin pydantic to a single version.
Install
pydantic-compat on PyPI
pip
pip install pydantic-compatuv
uv add pydantic-compatpoetry
poetry add pydantic-compatInstalling pydantic-compat
Before you install
Low install friction with only two runtime dependencies (importlib-metadata and pydantic). Actively maintained as of 2026-08-03, though the last release was in 2023-10-24.
License in practice
BSD 3-Clause License (permissive) allows use in most commercial and open-source projects without significant restrictions.
Quickstart
from pydantic import BaseModel
from pydantic_compat import PydanticCompatMixin, field_validator
class MyModel(PydanticCompatMixin, BaseModel):
x: int
@field_validator('x', mode='after')
def check_x(cls, v):
return v
obj = MyModel(x=42)
data = obj.model_dump() # works in both v1 and v2
Verify before relying
- Whether the package's API coverage is sufficient for your specific pydantic usage patterns beyond the documented examples
- How well custom type handling works across both pydantic versions when using this adapter
Package facts
| License | BSD 3-Clause License (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — importlib-metadata, pydantic |
| Maintenance | actively maintained — 1,025 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 80,268/month — #14,301 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pydantic_compat-0.1.2-py3-none-any.whl
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
bump-pydanticA CLI tool that automatically refactors…
permissive · top 15,000 on PyPI
prime-pydantic-configBuilds a command-line interface from Pydantic…
unclear · top 15,000 on PyPI
pydantic-function-modelsWraps Python functions to validate their…
permissive · top 15,000 on PyPI
django-pydantic-fieldProvides type-safe Pydantic model schemas for…
permissive · top 5,000 on PyPI
pylint-pydanticA Pylint plugin that extends Pylint's…
copyleft · top 5,000 on PyPI
pydantic-to-typescript2Converts Pydantic models to TypeScript…
permissive · top 15,000 on PyPI
pydantic-extra-typesProvides additional type validators and…
permissive · top 1,000 on PyPI
drf-pydanticBridges pydantic models and Django REST…
permissive · 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