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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
886c217d7e87b980756a40b5a7d4fd04d505f27dda39ad4c90e894d17dbcfddd
|
|
| MD5 |
bf5359bb17662647e9b9cc408c99cb58
|
|
| BLAKE2b-256 |
b948b817172ea4eaa842b5cef8a688bfc4ef8c818f87664c52887d5c49df0cc6
|
Provenance
The following attestation bundles were made for pydantic_fabricated-1.0.2.tar.gz:
Publisher:
release.yml on KRunchPL/pydantic-fabricated
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_fabricated-1.0.2.tar.gz -
Subject digest:
886c217d7e87b980756a40b5a7d4fd04d505f27dda39ad4c90e894d17dbcfddd - Sigstore transparency entry: 2244789850
- Sigstore integration time:
-
Permalink:
KRunchPL/pydantic-fabricated@ca5979be9db502325e49e400504f38de546c937d -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/KRunchPL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ca5979be9db502325e49e400504f38de546c937d -
Trigger Event:
release
-
Statement type:
File details
Details for the file pydantic_fabricated-1.0.2-py3-none-any.whl.
File metadata
- Download URL: pydantic_fabricated-1.0.2-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
974a54d717118af44b9c46018026f558ccf907d24c8351c52f548e5a1ca1775c
|
|
| MD5 |
aa5fd4c9fdec1591c2bff967723a203d
|
|
| BLAKE2b-256 |
118dd394d281b89ac5d447727bbe525e44ad86110d1de058a85b653ccf3a0a83
|
Provenance
The following attestation bundles were made for pydantic_fabricated-1.0.2-py3-none-any.whl:
Publisher:
release.yml on KRunchPL/pydantic-fabricated
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_fabricated-1.0.2-py3-none-any.whl -
Subject digest:
974a54d717118af44b9c46018026f558ccf907d24c8351c52f548e5a1ca1775c - Sigstore transparency entry: 2244790667
- Sigstore integration time:
-
Permalink:
KRunchPL/pydantic-fabricated@ca5979be9db502325e49e400504f38de546c937d -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/KRunchPL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ca5979be9db502325e49e400504f38de546c937d -
Trigger Event:
release
-
Statement type: