No project description provided
Project description
Extendable Pydantic
This addons provides a new type used to declare Pydantic model as Extendable class.
From release 1.0.0 it only supports Pydantic >= 2.0.0.
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.model_dump() == {"lat": 12.3, "lng": 13.2, "name": "My Loc"}
#> True
loc.model_json_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
- run ``bumpversion patch|minor|major --list
- Check the new_version value returned by the previous command
- run towncrier build.
- Inspect and commit the updated HISTORY.rst.
- git tag {new_version} ; git push --tags.
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
Close
Hashes for extendable_pydantic-1.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96537adc1da9e18a794f7b3ceb5ff86630d7f9c7d0ba0254d10e13bd94202171 |
|
MD5 | 7a2f9fcb1dd421c3f431c34e839b3edb |
|
BLAKE2b-256 | db2ec93f2866382fd042d0cc752b239fd9d43a649220829339fd1952081027a8 |
Close
Hashes for extendable_pydantic-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab2f7c9c656bb478713a2bf90340a9c4f3a7257b0d406ed4d859c8f3479970cc |
|
MD5 | a4ea39caf9e5356eb230bfbb76d06e93 |
|
BLAKE2b-256 | ab746644f9ea890f2cccb77f3412e58870867055f909dee47a2d8e22f8853e5e |