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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe3ac1e10a901c005d342d9edaf2085163a318ab60b0782d3b76f18ad493f87a |
|
MD5 | 18faddd550bb06a5613a2e36660631a8 |
|
BLAKE2b-256 | b5f9137faf8b1ffd348e6840716316851e7289e5ef2153ff1cd8dc4e7ccecfbd |
Close
Hashes for extendable_pydantic-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 875ae14e38b29e03f535bb4552b7c097fd222aa7b9da583d1e56d8072e3bb016 |
|
MD5 | 58800d3c63f007ed7e600dd6cbd6aa52 |
|
BLAKE2b-256 | 6a93d3c9ef179bef0e779f2619d449554324597814866e805f5ce8a767b68209 |