No project description provided
Project description
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
.
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-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cac18e374e5fda82d0b448c2f727c1d6a8cf646bdaea148f67ebc70817825529 |
|
MD5 | 2889179344cf2d710dff074130205cc8 |
|
BLAKE2b-256 | 2397aff5beaf1345e6182d19c922ce817f791d3ca86a18601f5b33d355afeeb3 |
Close
Hashes for extendable_pydantic-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 981ab7e0d31240a7addc41a4b1e262c4d24929dbd23df5e24d3fbe9ad4f3dd87 |
|
MD5 | 9eaad9825a02a750b7b4ee631a54ed6b |
|
BLAKE2b-256 | a9c6c8d35a6a9ff894d282f4fbe229f5e8f86149c33035eb37ca6c4b6c8104d6 |