pyrmute 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyrmute/__init__.py +20 -0
- pyrmute/_migration_manager.py +306 -0
- pyrmute/_registry.py +172 -0
- pyrmute/_schema_manager.py +350 -0
- pyrmute/_version.py +34 -0
- pyrmute/model_manager.py +264 -0
- pyrmute/model_version.py +60 -0
- pyrmute/py.typed +0 -0
- pyrmute/types.py +26 -0
- pyrmute-0.1.0.dist-info/METADATA +130 -0
- pyrmute-0.1.0.dist-info/RECORD +14 -0
- pyrmute-0.1.0.dist-info/WHEEL +5 -0
- pyrmute-0.1.0.dist-info/licenses/LICENSE +21 -0
- pyrmute-0.1.0.dist-info/top_level.txt +1 -0
pyrmute/py.typed
ADDED
File without changes
|
pyrmute/types.py
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
"""Type aliases needed in the package."""
|
2
|
+
|
3
|
+
from collections.abc import Callable
|
4
|
+
from typing import Any, TypeAlias, TypeVar
|
5
|
+
|
6
|
+
from pydantic import BaseModel
|
7
|
+
|
8
|
+
from .model_version import ModelVersion
|
9
|
+
|
10
|
+
DecoratedBaseModel = TypeVar("DecoratedBaseModel", bound=BaseModel)
|
11
|
+
|
12
|
+
JsonValue: TypeAlias = dict[str, Any] | list[Any] | str | int | float | bool | None
|
13
|
+
JsonSchema: TypeAlias = dict[str, JsonValue]
|
14
|
+
JsonSchemaDefinitions: TypeAlias = dict[str, JsonSchema]
|
15
|
+
JsonSchemaGenerator: TypeAlias = Callable[[type[BaseModel]], JsonSchema]
|
16
|
+
SchemaGenerators: TypeAlias = dict[ModelVersion, JsonSchemaGenerator]
|
17
|
+
|
18
|
+
MigrationData: TypeAlias = dict[str, Any]
|
19
|
+
MigrationFunc: TypeAlias = Callable[[MigrationData], MigrationData]
|
20
|
+
|
21
|
+
MigrationKey: TypeAlias = tuple[ModelVersion, ModelVersion]
|
22
|
+
MigrationMap: TypeAlias = dict[MigrationKey, MigrationFunc]
|
23
|
+
|
24
|
+
ModelName: TypeAlias = str
|
25
|
+
ModelMetadata: TypeAlias = tuple[ModelName, ModelVersion]
|
26
|
+
VersionedModels: TypeAlias = dict[ModelVersion, type[BaseModel]]
|
@@ -0,0 +1,130 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pyrmute
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Pydantic model migrations and schemas
|
5
|
+
Author-email: Matt Ferrera <mattferrera@gmail.com>
|
6
|
+
License: MIT
|
7
|
+
Project-URL: Homepage, https://github.com/mferrera/pyrmute
|
8
|
+
Project-URL: Repository, https://github.com/mferrera/pyrmute
|
9
|
+
Project-URL: Documentation, https://github.com/mferrera/pyrmute
|
10
|
+
Keywords: pydantic,migration,versioning,schema
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
12
|
+
Classifier: Topic :: Utilities
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
17
|
+
Classifier: Natural Language :: English
|
18
|
+
Requires-Python: >=3.11
|
19
|
+
Description-Content-Type: text/markdown
|
20
|
+
License-File: LICENSE
|
21
|
+
Requires-Dist: pydantic
|
22
|
+
Provides-Extra: dev
|
23
|
+
Requires-Dist: mypy; extra == "dev"
|
24
|
+
Requires-Dist: pytest; extra == "dev"
|
25
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
26
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
27
|
+
Requires-Dist: pytest-xdist; extra == "dev"
|
28
|
+
Requires-Dist: ruff; extra == "dev"
|
29
|
+
Dynamic: license-file
|
30
|
+
|
31
|
+
# pyrmute
|
32
|
+
|
33
|
+
[](https://github.com/mferrera/pyrmute/actions?query=event%3Apush+branch%3Amain+workflow%3Aci)
|
34
|
+
[](https://pypi.python.org/pypi/pyrmute)
|
35
|
+
[](https://github.com/mferrera/pyrmute)
|
36
|
+
[](https://github.com/mferrera/pyrmute/blob/main/LICENSE)
|
37
|
+
|
38
|
+
Pydantic model migrations and schema management with semantic versioning.
|
39
|
+
|
40
|
+
Pyrmute helps you evolve your data models over time without breaking changes.
|
41
|
+
Version your Pydantic models, define migrations between versions, and
|
42
|
+
automatically transform legacy data to current schemas. Export JSON schemas
|
43
|
+
for all versions to maintain API contracts.
|
44
|
+
|
45
|
+
**Key features:**
|
46
|
+
- **Version your models** - Use semantic versioning to track model evolution
|
47
|
+
- **Automatic migrations** - Chain migrations across multiple versions (1.0.0 → 2.0.0 → 3.0.0)
|
48
|
+
- **Validated transformations** - Migrations return validated Pydantic models by default
|
49
|
+
- **Schema export** - Generate JSON schemas for all versions, with support for `$ref` to external schemas and custom schema generators
|
50
|
+
- **Nested model support** - Automatically migrates nested Pydantic models
|
51
|
+
|
52
|
+
## Help
|
53
|
+
|
54
|
+
See [documentation](https://mferrera.github.io/pyrmute/) for more details.
|
55
|
+
|
56
|
+
## Installation
|
57
|
+
|
58
|
+
Install using `pip install -U pyrmute`.
|
59
|
+
|
60
|
+
## Simple Example
|
61
|
+
|
62
|
+
```python
|
63
|
+
from pydantic import BaseModel
|
64
|
+
from pyrmute import ModelManager, MigrationData
|
65
|
+
|
66
|
+
manager = ModelManager()
|
67
|
+
|
68
|
+
|
69
|
+
@manager.model("User", "1.0.0")
|
70
|
+
class UserV1(BaseModel):
|
71
|
+
"""Version 1.0.0: Initial user model."""
|
72
|
+
name: str
|
73
|
+
age: int
|
74
|
+
|
75
|
+
|
76
|
+
@manager.model("User", "2.0.0")
|
77
|
+
class UserV2(BaseModel):
|
78
|
+
"""Version 2.0.0: Split name into first/last."""
|
79
|
+
first_name: str
|
80
|
+
last_name: str
|
81
|
+
age: int
|
82
|
+
|
83
|
+
|
84
|
+
@manager.model("User", "3.0.0")
|
85
|
+
class UserV3(BaseModel):
|
86
|
+
"""Version 3.0.0: Add email, make age optional."""
|
87
|
+
first_name: str
|
88
|
+
last_name: str
|
89
|
+
email: str
|
90
|
+
age: int | None = None
|
91
|
+
|
92
|
+
|
93
|
+
# Define migrations
|
94
|
+
@manager.migration("User", "1.0.0", "2.0.0")
|
95
|
+
def split_name(data: MigrationData) -> MigrationData:
|
96
|
+
parts = data["name"].split(" ", 1)
|
97
|
+
return {
|
98
|
+
"first_name": parts[0],
|
99
|
+
"last_name": parts[1] if len(parts) > 1 else "",
|
100
|
+
"age": data["age"],
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
@manager.migration("User", "2.0.0", "3.0.0")
|
105
|
+
def add_email(data: MigrationData) -> MigrationData:
|
106
|
+
return {**data, "email": f"{data['first_name'].lower()}@example.com"}
|
107
|
+
|
108
|
+
|
109
|
+
# Migrate old data forward, from raw data or dumped from the Pydantic model
|
110
|
+
legacy_data = {"name": "John Doe", "age": 30}
|
111
|
+
# Returns a validated Pydantic model
|
112
|
+
current_user = manager.migrate(legacy_data, "User", "1.0.0", "3.0.0")
|
113
|
+
|
114
|
+
print(current_user)
|
115
|
+
# first_name='John' last_name='Doe' email='john@example.com' age=30
|
116
|
+
|
117
|
+
# Export schemas for all versions
|
118
|
+
manager.dump_schemas("schemas/")
|
119
|
+
# Creates: schemas/User_v1.0.0.json, schemas/User_v2.0.0.json, schemas/User_v3.0.0.json
|
120
|
+
```
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
For guidance on setting up a development environment and how to make a
|
125
|
+
contribution to pyrmute, see
|
126
|
+
[Contributing to pyrmute](https://mferrera.github.io/pyrmute/contributing/).
|
127
|
+
|
128
|
+
## Reporting a Security Vulnerability
|
129
|
+
|
130
|
+
See our [security policy](https://github.com/mferrera/pyrmute/security/policy).
|
@@ -0,0 +1,14 @@
|
|
1
|
+
pyrmute/__init__.py,sha256=wGuYwo2F3zPXnB_HLJsmjt7jbZVfCcyVwf0J78KvwzA,516
|
2
|
+
pyrmute/_migration_manager.py,sha256=Z9Ie-fxJmOsmBw7oGWGHDrcNvr0aANlO6AqnBmJyYSA,9521
|
3
|
+
pyrmute/_registry.py,sha256=_fZGRQtdkfCsrCrF6GLUuMmHmyq8up9hF6aS9FboQZA,5572
|
4
|
+
pyrmute/_schema_manager.py,sha256=UdDC9j5nI-ljy9zKnfjhukzM4zfF-Edwu6P7CsdI7Xw,12581
|
5
|
+
pyrmute/_version.py,sha256=5jwwVncvCiTnhOedfkzzxmxsggwmTBORdFL_4wq0ZeY,704
|
6
|
+
pyrmute/model_manager.py,sha256=6rh0hXzZAaGv245RpVaAgjIRJ9s5DLmaRbsJAgwGQuQ,8289
|
7
|
+
pyrmute/model_version.py,sha256=_vyLcIfOzHXrumPqzDSuNZMAZGqFh1ZYv6g933O_aH0,1801
|
8
|
+
pyrmute/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
pyrmute/types.py,sha256=NmlBA0ohFjpAIyZ6EvhbEigBV645LCZ-k8vaHjtB7Z4,978
|
10
|
+
pyrmute-0.1.0.dist-info/licenses/LICENSE,sha256=otWInySiZeGwhHqQQ7n7nxM5QBSBe2CzeGEmQDZEz8Q,1119
|
11
|
+
pyrmute-0.1.0.dist-info/METADATA,sha256=0t3BYtlBAYNORci6prJdVpgzA9Q8A0kjHvTrw8cJCNs,4515
|
12
|
+
pyrmute-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
13
|
+
pyrmute-0.1.0.dist-info/top_level.txt,sha256=C8QtzqE6yBHkeewSp1QewvsyeHj_VQLYjSa5HLtMiow,8
|
14
|
+
pyrmute-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 to present Matt Ferrera and individual contributors.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
pyrmute
|