pydantic-ext
This addons provides a new type used to declare Pydantic model as Extendable class.
from pydantic import BaseModel
from extendable_pydantic import ExtendableModelMeta
from extendable import context, registry
class Location(BaseModel, metaclass=ExtendableModelMeta):
lat = 0.1
lng = 10.1
class ExtendedLocation(Location, extends=Location):
name: str
_registry = registry.ExtendableClassesRegistry()
context.extendable_registry.set(_registry)
_registry.init_registry()
loc = Location(**{"lat": 12.3, "lng": 13.2, "name": "My Loc"})
loc.dict() == {"lat": 12.3, "lng": 13.2, "name": "My Loc"}
#> True
loc.schema()
#> {'title': 'Location', 'type': 'object', 'properties': {'lat': {'title': 'Lat', 'default': 0.1, 'type': 'number'}, 'lng': {'title': 'Lng', 'default': 10.1, 'type': 'number'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['name']}
Development
pip install -e .
Then, copy extendable_pydantic_patcher.pth to $VIRTUAL_ENV/lib/python3.10/site-packages.
Release
- Tag the sources:
git tag x.y.z - Build the package:
hatch build - Publish to pypi:
twine upload dist/*
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 extendable_pydantic-0.0.4.tar.gz.
File metadata
- Download URL: extendable_pydantic-0.0.4.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d9239570e009e198e1e2e73c6b0cc053d267fef0426ff655bebefe609b6603f
|
|
| MD5 |
5ba3c9cff3ef12d5fd8c4bf840c86d89
|
|
| BLAKE2b-256 |
decd6578fa6861c4c502be0fa6475380a7fe3eb8d005fab7cea6b6a0a1867e97
|
File details
Details for the file extendable_pydantic-0.0.4-py3-none-any.whl.
File metadata
- Download URL: extendable_pydantic-0.0.4-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4faa35e8d7871e879090a71b9b55d8a7ad44d5a5d9f6a06bf4ab7752482a040
|
|
| MD5 |
cc8cbe66eb2f77a64961e4f3507d5b88
|
|
| BLAKE2b-256 |
1c999e526252bf146915739ddf7c13052b98a0463c596a7f78ebc3c218a70c1c
|