Skip to main content

No project description provided

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

Development

pip install -e .

Then, copy extendable_pydantic_patcher.pth to $VIRTUAL_ENV/lib/python3.10/site-packages.

Release

  • Tag the sources: git tag x.y.z
  • Build the package: hatch build
  • Publish to pypi: twine upload dist/*

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

Uploaded Source

Built Distribution

extendable_pydantic-0.0.4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: extendable_pydantic-0.0.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for extendable_pydantic-0.0.4.tar.gz
Algorithm Hash digest
SHA256 5d9239570e009e198e1e2e73c6b0cc053d267fef0426ff655bebefe609b6603f
MD5 5ba3c9cff3ef12d5fd8c4bf840c86d89
BLAKE2b-256 decd6578fa6861c4c502be0fa6475380a7fe3eb8d005fab7cea6b6a0a1867e97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for extendable_pydantic-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d4faa35e8d7871e879090a71b9b55d8a7ad44d5a5d9f6a06bf4ab7752482a040
MD5 cc8cbe66eb2f77a64961e4f3507d5b88
BLAKE2b-256 1c999e526252bf146915739ddf7c13052b98a0463c596a7f78ebc3c218a70c1c

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