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
File details
Details for the file extendable_pydantic-1.3.1.tar.gz
.
File metadata
- Download URL: extendable_pydantic-1.3.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c2d363b2fb3cdf9d27e4dc213efe427b138cb7f8c5e6bd65ef1aeae709a65d0 |
|
MD5 | 87d21727b407496718a8f214e99f1608 |
|
BLAKE2b-256 | 6bb9f4c8c1d2b56bf84eac404d685cd5430836b41aba5b71537d7e15fdfee1c8 |
File details
Details for the file extendable_pydantic-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: extendable_pydantic-1.3.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebffa3b8574146e2f328415018efa79b96f2f08c7a72ef9fb61acc9b652a5e9b |
|
MD5 | fefbd75600c41255a3822663ef297db9 |
|
BLAKE2b-256 | 6d7d6524a90461ecfa77fa5b6e2ab6e4d70a4c9cc794954ca9cd88891c5bc500 |