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
.
Release
- Tag the sources:
git tag x.y.z
- Build the package:
hatch build
- Publish to pypi:
twine upload dist/*
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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d9239570e009e198e1e2e73c6b0cc053d267fef0426ff655bebefe609b6603f |
|
MD5 | 5ba3c9cff3ef12d5fd8c4bf840c86d89 |
|
BLAKE2b-256 | decd6578fa6861c4c502be0fa6475380a7fe3eb8d005fab7cea6b6a0a1867e97 |
Close
Hashes for extendable_pydantic-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4faa35e8d7871e879090a71b9b55d8a7ad44d5a5d9f6a06bf4ab7752482a040 |
|
MD5 | cc8cbe66eb2f77a64961e4f3507d5b88 |
|
BLAKE2b-256 | 1c999e526252bf146915739ddf7c13052b98a0463c596a7f78ebc3c218a70c1c |