Bring version control and history to your Pydantic schemas
Project description
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 (
dump_versioned,
field_default,
field_removed,
migration,
schema_version,
validate_versioned,
versioned_schema,
)
@versioned_schema(
name="app_config",
versions=["1", "2"],
current="2",
version_field="schema_version",
missing_version="1",
)
@schema_version("1", patches=[
field_default("timeout", 5.0),
field_removed("new_feature"),
])
class AppConfig(BaseModel):
timeout: float = 10.0
retries: int = 3
new_feature: bool = False
@migration(AppConfig, "1", "2")
def migrate_v1_to_v2(data: dict) -> dict:
data.setdefault("new_feature", False)
return data
result = validate_versioned(AppConfig, {"schema_version": "1", "retries": 2})
assert result.current_model == AppConfig(timeout=5.0, retries=2, new_feature=False)
v1_config = dump_versioned(AppConfig, version="1")
assert v1_config == {"timeout": 5.0, "retries": 3, "schema_version": "1"}
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 docs include a larger nested config example and adoption guidance for deciding when to use patches, migrations, nested version fields, 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: runty.make test: run pytest.make docs-build: build the docs site.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_versions-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_versions-0.1.0.tar.gz
- Upload date:
- Size: 899.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b515be7922467d6b4dc333580c43b48044f16af03005893746e987a0544cb25
|
|
| MD5 |
a3ea7a876cc5e3682562fe34d20a0a62
|
|
| BLAKE2b-256 |
4ad97805790d531cf75c51d1eda05471a91f00ae03023498fc79c6d8c956ce7c
|
Provenance
The following attestation bundles were made for pydantic_versions-0.1.0.tar.gz:
Publisher:
release.yml on dariuszpanas/pydantic-versions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_versions-0.1.0.tar.gz -
Subject digest:
3b515be7922467d6b4dc333580c43b48044f16af03005893746e987a0544cb25 - Sigstore transparency entry: 1565244524
- Sigstore integration time:
-
Permalink:
dariuszpanas/pydantic-versions@5b6f2bf417188bb85a44a6d7891c6ae96d094902 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dariuszpanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5b6f2bf417188bb85a44a6d7891c6ae96d094902 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_versions-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_versions-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
621070075311178de0e1ee3ed624d9c9851a090abbdc4b30be27f918e5f38e9b
|
|
| MD5 |
a734c5017e0788c575ca541ef605c7b0
|
|
| BLAKE2b-256 |
1adc7ea88765aedf2e58d4ab8f2ef0a9e1a062c39acc8f6159bbeb01fd7e9060
|
Provenance
The following attestation bundles were made for pydantic_versions-0.1.0-py3-none-any.whl:
Publisher:
release.yml on dariuszpanas/pydantic-versions
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_versions-0.1.0-py3-none-any.whl -
Subject digest:
621070075311178de0e1ee3ed624d9c9851a090abbdc4b30be27f918e5f38e9b - Sigstore transparency entry: 1565244641
- Sigstore integration time:
-
Permalink:
dariuszpanas/pydantic-versions@5b6f2bf417188bb85a44a6d7891c6ae96d094902 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dariuszpanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5b6f2bf417188bb85a44a6d7891c6ae96d094902 -
Trigger Event:
push
-
Statement type: