Skip to main content

Pydantic Fabricated

A Python package that provides a metaclass for fabricating subclasses from dictionaries inside Pydantic models. This library seamlessly integrates with Pydantic's type system to enable dynamic object creation based on type definitions.

Installation

pip install pydantic-fabricated

Features

  • Dynamic object creation from type definitions
  • Seamless integration with Pydantic models
  • Type-safe parameter validation
  • Support for JSON serialization/deserialization
  • Discriminated unions for type-safe polymorphism

Quick Start

Here's a simple example of how to use Pydantic Fabricated:

import os

from pydantic_settings import BaseSettings, SettingsConfigDict

from pydantic_fabricated import PydanticFabricated


# Define a base class using the metaclass
class Shape(metaclass=PydanticFabricated):
    pass


# Define concrete implementations
class Circle(Shape):
    def __init__(self, radius: float):
        self.radius = radius


class Rectangle(Shape):
    def __init__(self, width: float, height: float):
        self.width = width
        self.height = height


# Create instances using the fabricate_from_type method
circle = Shape.fabricate_from_type('Circle', {'radius': 5.0})
rectangle = Shape.fabricate_from_type('Rectangle', {'width': 10.0, 'height': 20.0})


# Or use with Pydantic Settings
class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_prefix='my_prefix_')

    shape: Shape


os.environ['MY_PREFIX_SHAPE'] = r'{"type": "Circle", "radius": 5.0}'
settings = Settings()

Requirements

  • Python ≥ 3.13
  • Pydantic ≥ 2.11.9

License

Apache License 2.0

Links

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Additional Documentation

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_fabricated-1.0.2.tar.gz (68.7 kB view details)

Uploaded Source

Built Distribution

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

pydantic_fabricated-1.0.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_fabricated-1.0.2.tar.gz.

File metadata

  • Download URL: pydantic_fabricated-1.0.2.tar.gz
  • Upload date:
  • Size: 68.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pydantic_fabricated-1.0.2.tar.gz
Algorithm Hash digest
SHA256 886c217d7e87b980756a40b5a7d4fd04d505f27dda39ad4c90e894d17dbcfddd
MD5 bf5359bb17662647e9b9cc408c99cb58
BLAKE2b-256 b948b817172ea4eaa842b5cef8a688bfc4ef8c818f87664c52887d5c49df0cc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_fabricated-1.0.2.tar.gz:

Publisher: release.yml on KRunchPL/pydantic-fabricated

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_fabricated-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_fabricated-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 974a54d717118af44b9c46018026f558ccf907d24c8351c52f548e5a1ca1775c
MD5 aa5fd4c9fdec1591c2bff967723a203d
BLAKE2b-256 118dd394d281b89ac5d447727bbe525e44ad86110d1de058a85b653ccf3a0a83

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_fabricated-1.0.2-py3-none-any.whl:

Publisher: release.yml on KRunchPL/pydantic-fabricated

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

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page