Skip to main content

No project description provided

Project description

CI codecov

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extendable_pydantic-1.3.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

extendable_pydantic-1.3.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file extendable_pydantic-1.3.0.tar.gz.

File metadata

  • Download URL: extendable_pydantic-1.3.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for extendable_pydantic-1.3.0.tar.gz
Algorithm Hash digest
SHA256 bd79919b8cb28c570a2f41236c1dda7e5f006a39f4fa7df00ef732abd99d4fe0
MD5 aa915265eab5fccac749f173815c388c
BLAKE2b-256 d82c6cea6e94e82fa3daa8039fc2348117db8e09a2b18f5bb33becb2baf3a5bd

See more details on using hashes here.

File details

Details for the file extendable_pydantic-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for extendable_pydantic-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa3b10bcd0d274ef1c377b15ce56df89dbdc0c32ce5904daedf89c7f11dc40e5
MD5 7d6d88299827e0bbf7b75bc873150372
BLAKE2b-256 bb525daa4ce2598222f1732aad7023b55e34e6d0faf82b33d0b2d2b7315edc9e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page