Skip to main content

pydantic-versions

Bring version control and history to your Pydantic schemas.

CI status PyPI version Supported Python versions Documentation status License

pydantic-versions logo

pydantic-versions lets projects register ordered schema versions, derive historical Pydantic models from a current model, validate historical payloads, render historical config shapes, and upgrade data to the current model.

Install

pip install pydantic-versions

With uv:

uv add pydantic-versions

Example

Schema versions are independent from software versions. A config payload can declare the schema it uses, and the latest software can still validate and upgrade it:

from pydantic import BaseModel
from pydantic_versions import (
    SchemaFamily,
    SchemaVersion,
    field_default,
    field_removed,
)


class AppConfig(BaseModel):
    timeout: float = 10.0
    retries: int = 3
    new_feature: bool = False


APP_CONFIG_SCHEMA = SchemaFamily(
    model=AppConfig,
    name="app_config",
    versions=(
        SchemaVersion(
            "1",
            patches=(
                field_default("timeout", 5.0),
                field_removed("new_feature"),
            ),
        ),
        SchemaVersion("2"),
    ),
    missing_version="1",
)


result = APP_CONFIG_SCHEMA.validate({"schema_version": "1", "retries": 2})
assert result.current_model == AppConfig(timeout=5.0, retries=2, new_feature=False)

v1_config = APP_CONFIG_SCHEMA.defaults_for(version="1")
assert v1_config == {"timeout": 5.0, "retries": 3, "schema_version": "1"}

defaults_for() constructs the requested wire version directly, so historical defaults do not depend on a downgrade route from the current version. Use dump(version=..., data=current_config) when converting actual current data.

missing_version is only for legacy config files that do not contain a schema version field. For example, missing_version="1" means "if a payload has no schema_version, treat it as an old v1 config." If you do not set it, unversioned input raises MissingSchemaVersionError.

The current model remains ordinary; its growing history can live in another module. The decorators remain available as a compact compatibility style. The docs include external-family guidance, a larger nested config example, and adoption guidance for choosing patches, migrations, metadata, and legacy unversioned fallbacks.

Development

Install dependencies:

uv sync

Run the main checks:

make ci

Useful commands:

  • make format: format with Ruff.
  • make lint: lint and auto-fix with Ruff.
  • make typecheck: run ty plus the external mypy consumer contract.
  • make dead-code: scan production code with Vulture and reviewed local exceptions.
  • make test: run pytest.
  • make docs-build: build the docs site.

Metadata

Release files for pydantic-versions 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-versions 1.0.1
File Size Uploaded Provenance
pydantic_versions-1.0.1.tar.gz 1.4 MB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-versions 1.0.1
File Interpreter ABI Platform
pydantic_versions-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / pydantic_versions-1.0.1.tar.gz

Download URL pydantic_versions-1.0.1.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
f37f1c90f53ede91a544d6db3866b21d3c4d5465a5a50fbe8e5048517131b6a3
BLAKE2b-256 checksum
How to use checksums
02fa0bfb12fdb06a1f1d19ae6aac8954013d9e29adaddcee7dc3f2962303b5d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

Release files / pydantic_versions-1.0.1-py3-none-any.whl

Download URL pydantic_versions-1.0.1-py3-none-any.whl
Size 114.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a12caf1520e262b22aa6a23b0385a976c2dce9ac1c76344fe3ad1e39443fadfe
BLAKE2b-256 checksum
How to use checksums
f5c630b0e05b1ee4abcc9e84a6d786d47e909c96026bc1b5c8f8689055bd097e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

Security for pydantic-versions 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_versions-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page