Skip to main content

A lib to define pydantic models extendable at runtime.

Project description

CI codecov

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']}

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-0.0.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

extendable_pydantic-0.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: extendable_pydantic-0.0.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for extendable_pydantic-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f04199a9f9cc3f9cdd7265ff26a34baae43bf4c3a98a8ff60a92205fe7369576
MD5 4e713b3f8caa0abe1937f4471a61868a
BLAKE2b-256 831f00ac1775aebeff9eb0ca9dd2446faf00d41434914a23e8673fa0339efc98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for extendable_pydantic-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37d52291bbcbc10ad778891bf50f27ffcecaa441138ad5656c12ff10a2c66599
MD5 f6a558445285e0f8a0b472dbaefc7162
BLAKE2b-256 0f52c0f086d920f2c8f7782df159d0098ce93968caf12002b52cc3a3745db26e

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