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.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8ad7ed8ea00d5f69608bbdde399fed1d438fc523e1cc1fb2a1b2b973a963936 |
|
MD5 | 152e3a11d1d7236d615a07c07d18a70e |
|
BLAKE2b-256 | b92f9ff196b143a2a3e441b5f4342c38536e09268ae496ef152dc57a6f877efd |
Close
Hashes for extendable_pydantic-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdd8c259a6d9aa575f0dc7b45410ea4071a5da796da00034f8197f9e64d44236 |
|
MD5 | 46b55ed5b008f6e6ec78e7ca4573d9ef |
|
BLAKE2b-256 | ed23d7c46e88128ecf73223e91aae9ad461797d786de5f9db40be1dc9c3e6d3a |