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.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28fc45dfa7dd214594632f53aa92532eb34cc70f14c1aa237d9152ab4e8cc2c1 |
|
MD5 | f7a0fd1e8f6c6a0bcd6b5e468644c1c5 |
|
BLAKE2b-256 | 8ff97003a39699780431be2bc709f6329fad93f4b1f1390bb509c298ebec79cc |
Close
Hashes for extendable_pydantic-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f04cb1b62275e398bf96f3f835ed82c12c5a0bd8dd7d6a1209cbbed4a24395a8 |
|
MD5 | 701561fcb63977890c23851b29191bf2 |
|
BLAKE2b-256 | ebe28aaf14cc11426b11cbb7a1801884d829f839e5350f4c81037f05baa78b7f |