Skip to main content

Pydantic BaseModel supercharged with helper methods for generic and annotation support

Project description

Super Model for Pydantic

Coverage

A lightweight extension of Pydantic's BaseModel that adds generic type introspection and retrieval of fields annotated with typing.Annotated.

Installation

Install with pip

pip install pydantic-super-model

Features

  • Generic support
  • Able to retrieve field(s) with a specific Annotation

Generic Example

from super_model import SuperModel

class UserWithType[T](SuperModel):
    """User model with a generic type."""

    id: T
    name: str

user = UserWithType[int](id=1, name="John Doe")

user_type = user.get_type() # int

Annotation Example

from typing import Annotated
from super_model import SuperModel


class _PrimaryKeyAnnotation:
    pass

PrimaryKey = Annotated[int, _PrimaryKeyAnnotation]

class UserWithAnnotation(SuperModel):
    """User model with an Annotation for a field."""

    id: PrimaryKey
    name: str

user = UserWithAnnotation(id=1, name="John Doe")

annotations = user.get_annotated_fields(PrimaryKey)
# {"id": 1}

Run Tests

  • Install with the dev extra: pip install pydantic-super-model[dev]
  • Run tests with pytest .

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

pydantic_super_model-1.0.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_super_model-1.0.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_super_model-1.0.0.tar.gz.

File metadata

  • Download URL: pydantic_super_model-1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pydantic_super_model-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c29a1e4d1ce0712f90732ba0f3072906f66c38c6f141c45e8829342e524e458d
MD5 5c6ee8d84866a9e6e370b11633bc3347
BLAKE2b-256 b060523affaeb285aec15ee3b00d85d048dab1850b8144a40d6dc6afcac5413a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_super_model-1.0.0.tar.gz:

Publisher: publish-to-pypi.yml on julien777z/pydantic-super-model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_super_model-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_super_model-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4de68974eebf5adde3dfcbea9bf37432b81be0ade59f9df039cfcdc27b0d3e3a
MD5 91f37a6bed5d288bec50bae49c3eb659
BLAKE2b-256 39c55fec282bf72ee0b14b40d743ea11549af946191dc0e1eaee9858ea94f312

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_super_model-1.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on julien777z/pydantic-super-model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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