Skip to main content

Pydantic BaseModel supercharged with helper methods for generic and annotation support

Project description

Super Model for Pydantic

I created this package because I needed a centralized place for a Pydantic BaseModel that can 1) return the generic type of the BaseModel and 2) return which field(s) have a certain Annotation.

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-0.0.3.tar.gz (3.0 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-0.0.3-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_super_model-0.0.3.tar.gz
  • Upload date:
  • Size: 3.0 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-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ed96b1215353a18c5e07dc9aa5b1ef4e763e70183b983bc0f38157d6a74992da
MD5 a967a2a85181fd5ffcef828226a05fdc
BLAKE2b-256 bcaca94db6f34d0730f45b1b0f46d8720b99337079f5e74f5de6369ed2218e4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_super_model-0.0.3.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-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_super_model-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1cd9b84caa10b546cda208746dd0d28659a67e81dfc8365c54226a0d16e4d6d5
MD5 e099b6af15fb27cb2a5b654c0b34ed59
BLAKE2b-256 ee1b0a911e9790a45cd9facbab8a7a6c56cc95107efa7014fc126b40b5862639

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_super_model-0.0.3-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