pydantic-versions
Bring version control and history to your Pydantic schemas.
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: runtyplus 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.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydantic_versions-1.0.3.tar.gz | 1.4 MB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_versions-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.5 MB
Release files / pydantic_versions-1.0.3.tar.gz
| Download URL | pydantic_versions-1.0.3.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17231ba77d50eb3e7e78381a5a233fcbb40ae8b9ba849c360e27598fcb7ca725
|
|
BLAKE2b-256 checksum How to use checksums |
e60dbdacad53928f2ba66aaac3645dee7ee913680f5464261f3d8c80030f4c76
|
| 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 25, 2026.
Transparency logRelease files / pydantic_versions-1.0.3-py3-none-any.whl
| Download URL | pydantic_versions-1.0.3-py3-none-any.whl |
|---|---|
| Size | 118.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4dfe0825fc9ed57cd7a0810a47e6009391fdb38ffb1cdc0295c81d6aacaa12ac
|
|
BLAKE2b-256 checksum How to use checksums |
c3c0a3650fcfe615c9e0fe558aecdabdd522c54537f9da8ea5de29d140801caf
|
| 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 25, 2026.
Transparency logSecurity for pydantic-versions 1.0.3
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.
Attestation for pydantic_versions-1.0.3.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 25, 2026.
Transparency logA 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.