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.
Metadata
Release files for extendable-pydantic 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| extendable_pydantic-0.0.2.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| extendable_pydantic-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / extendable_pydantic-0.0.2.tar.gz
| Download URL | extendable_pydantic-0.0.2.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ea0746e32f06cdfa32350734827662f0bfa613ee297728b2524492c35a5654a
|
|
BLAKE2b-256 checksum How to use checksums |
46859a03b69f23ca9589f207fb7ba8b973ff37e49e6073103102dc6e0e39d533
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / extendable_pydantic-0.0.2-py3-none-any.whl
| Download URL | extendable_pydantic-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82d439ab0ef37c64bb8e1bd72cd7626d1842babba7670a08b9533dd49b2ab5ed
|
|
BLAKE2b-256 checksum How to use checksums |
226b3e3749828737bf308151f0c3b9a8d43518b97d488f9e47bf97660006fc29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|