Pydantic model migrations and schemas
Project description
pyrmute
Pydantic model migrations and schema management with semantic versioning.
Pyrmute helps you evolve your data models over time without breaking changes. Version your Pydantic models, define migrations between versions, and automatically transform legacy data to current schemas. Export JSON schemas for all versions to maintain API contracts.
Key features:
- Version your models - Use semantic versioning to track model evolution
- Automatic migrations - Chain migrations across multiple versions (1.0.0 → 2.0.0 → 3.0.0)
- Validated transformations - Migrations return validated Pydantic models by default
- Schema export - Generate JSON schemas for all versions, with support for
$refto external schemas and custom schema generators - Nested model support - Automatically migrates nested Pydantic models
Help
See documentation for more details.
Installation
Install using pip install -U pyrmute.
Simple Example
from pydantic import BaseModel
from pyrmute import ModelManager, MigrationData
manager = ModelManager()
@manager.model("User", "1.0.0")
class UserV1(BaseModel):
"""Version 1.0.0: Initial user model."""
name: str
age: int
@manager.model("User", "2.0.0")
class UserV2(BaseModel):
"""Version 2.0.0: Split name into first/last."""
first_name: str
last_name: str
age: int
@manager.model("User", "3.0.0")
class UserV3(BaseModel):
"""Version 3.0.0: Add email, make age optional."""
first_name: str
last_name: str
email: str
age: int | None = None
# Define migrations
@manager.migration("User", "1.0.0", "2.0.0")
def split_name(data: MigrationData) -> MigrationData:
parts = data["name"].split(" ", 1)
return {
"first_name": parts[0],
"last_name": parts[1] if len(parts) > 1 else "",
"age": data["age"],
}
@manager.migration("User", "2.0.0", "3.0.0")
def add_email(data: MigrationData) -> MigrationData:
return {**data, "email": f"{data['first_name'].lower()}@example.com"}
# Migrate old data forward, from raw data or dumped from the Pydantic model
legacy_data = {"name": "John Doe", "age": 30}
# Returns a validated Pydantic model
current_user = manager.migrate(legacy_data, "User", "1.0.0", "3.0.0")
print(current_user)
# first_name='John' last_name='Doe' email='john@example.com' age=30
# Export schemas for all versions
manager.dump_schemas("schemas/")
# Creates: schemas/User_v1.0.0.json, schemas/User_v2.0.0.json, schemas/User_v3.0.0.json
Contributing
For guidance on setting up a development environment and how to make a contribution to pyrmute, see Contributing to pyrmute.
Reporting a Security Vulnerability
See our security policy.
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 pyrmute-0.1.0.tar.gz.
File metadata
- Download URL: pyrmute-0.1.0.tar.gz
- Upload date:
- Size: 51.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a678d416a937a10b089014f3b53154d54ba9f182cccdc981e7bde66517b43400
|
|
| MD5 |
5ead4ee146a2f2629b1d89e3cf1efb2f
|
|
| BLAKE2b-256 |
739bb2eddf12883e4f179aafb99e8234b1a1278d71d9e79af2b232464fc84c4a
|
Provenance
The following attestation bundles were made for pyrmute-0.1.0.tar.gz:
Publisher:
publish.yml on mferrera/pyrmute
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrmute-0.1.0.tar.gz -
Subject digest:
a678d416a937a10b089014f3b53154d54ba9f182cccdc981e7bde66517b43400 - Sigstore transparency entry: 584423753
- Sigstore integration time:
-
Permalink:
mferrera/pyrmute@5a12801a5083b9b3be96ae7a962ea60ef528cbd5 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/mferrera
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a12801a5083b9b3be96ae7a962ea60ef528cbd5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyrmute-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyrmute-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69fc58421f9bf5cef6a337fb54ca597f2c775164794faac5f109addc9556328a
|
|
| MD5 |
76f9c03a45c7ac91531f16f5633cd663
|
|
| BLAKE2b-256 |
ddbe6d8fc917bd1daffb6fb3f01f49e824207ce45f024cde0c233aeccd182001
|
Provenance
The following attestation bundles were made for pyrmute-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on mferrera/pyrmute
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrmute-0.1.0-py3-none-any.whl -
Subject digest:
69fc58421f9bf5cef6a337fb54ca597f2c775164794faac5f109addc9556328a - Sigstore transparency entry: 584423761
- Sigstore integration time:
-
Permalink:
mferrera/pyrmute@5a12801a5083b9b3be96ae7a962ea60ef528cbd5 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/mferrera
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a12801a5083b9b3be96ae7a962ea60ef528cbd5 -
Trigger Event:
release
-
Statement type: