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.2.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.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_super_model-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 3c075c9ab3be5282c850fc5e4842292eb6a5f146d1c4863b0bd4987b14cea2d3
MD5 ac816a95a5e67b97feddcb663a5f9700
BLAKE2b-256 c3e50165cd4209647feb28043fc50b1e5423b445e006480c5122ca442164839e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pydantic_super_model-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e7ef4c31e0582957646eba6b4291c8626455cb0408755865be17b2412291e91e
MD5 83d4eef3e60ee902d10f1bccdec100b8
BLAKE2b-256 f1a94ca51ca6fb77708d82e9ecf94d605892c6e0a9175d6d90a5cd461ef664d0

See more details on using hashes here.

Provenance

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