Skip to main content

pydantic-flatten-rootmodel

Library to transform a Pydantic RootModel with discriminated unions into a flattened BaseModel.

from pydantic_flatten_rootmodel import flatten_root_model

class Cat(BaseModel):
    pet_type: Annotated[Literal["cat"], Field()]
    meow: str


class Dog(BaseModel):
    pet_type: Annotated[Literal["dog"], Field()]
    bark: str

class Pet(RootModel[Cat | Dog]):
    root: Annotated[Cat | Dog, Field(discriminator="pet_type")]


FlattenedPet = flatten_root_model(Pet)

would result in FlattenedPet to have this shape:

class FlattenedPet(BaseModel):
   pet_type: Annotated[Union[Literal["cat"], Literal["dog"]]]
   bark: Union[str, None]
   meow: Union[str, None]

This can for example be leveraged by dlt for it's schema definition. Without flattening it, the discriminated union is not recognized correctly when setting up the table schema.

Metadata

Release files for pydantic-flatten-rootmodel 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-flatten-rootmodel 0.1.2
File Size Uploaded Provenance Actions
pydantic_flatten_rootmodel-0.1.2.tar.gz 7.2 kB With provenance Details for pydantic_flatten_rootmodel-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-flatten-rootmodel 0.1.2
File Interpreter ABI Platform Actions
pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl Python 3 none any Details for pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl

Total release size: 15.5 kB

Release files / pydantic_flatten_rootmodel-0.1.2.tar.gz

Download URL pydantic_flatten_rootmodel-0.1.2.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5264346b5e98ed0fae553531b2384cb71ee79109a0003c08fb487ddd31a49e0f
BLAKE2b-256 checksum
How to use checksums
44ae9d41766704e3c5e0ab537098b303e43ad0eac64735a49b01b866311a525b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2025.

Transparency log

Release files / pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl

Download URL pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a51d36c5eb94ea59045a7a43e6ff663f055dbf0969791b8ca76b1b01d3475ce
BLAKE2b-256 checksum
How to use checksums
2613968e21a63787d7729cedc2f0644a79b2326aade2a7f444735688470a274b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2025.

Transparency log

Security for pydantic-flatten-rootmodel 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_flatten_rootmodel-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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