Library to transform a Pydantic RootModel into a flattened BaseModel
Project description
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.
Project details
Release history Release notifications | RSS feed
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_flatten_rootmodel-0.1.2.tar.gz.
File metadata
- Download URL: pydantic_flatten_rootmodel-0.1.2.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5264346b5e98ed0fae553531b2384cb71ee79109a0003c08fb487ddd31a49e0f
|
|
| MD5 |
29dcaca4bc131170928f0dc775181fcc
|
|
| BLAKE2b-256 |
44ae9d41766704e3c5e0ab537098b303e43ad0eac64735a49b01b866311a525b
|
Provenance
The following attestation bundles were made for pydantic_flatten_rootmodel-0.1.2.tar.gz:
Publisher:
test.yml on planet-a-ventures/pydantic-flatten-rootmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_flatten_rootmodel-0.1.2.tar.gz -
Subject digest:
5264346b5e98ed0fae553531b2384cb71ee79109a0003c08fb487ddd31a49e0f - Sigstore transparency entry: 160681192
- Sigstore integration time:
-
Permalink:
planet-a-ventures/pydantic-flatten-rootmodel@907278b0930189a16f03ff8682467f95b5ab8a86 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/planet-a-ventures
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@907278b0930189a16f03ff8682467f95b5ab8a86 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a51d36c5eb94ea59045a7a43e6ff663f055dbf0969791b8ca76b1b01d3475ce
|
|
| MD5 |
2dd525b8422e90220007f9b975cc8cc5
|
|
| BLAKE2b-256 |
2613968e21a63787d7729cedc2f0644a79b2326aade2a7f444735688470a274b
|
Provenance
The following attestation bundles were made for pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl:
Publisher:
test.yml on planet-a-ventures/pydantic-flatten-rootmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_flatten_rootmodel-0.1.2-py3-none-any.whl -
Subject digest:
9a51d36c5eb94ea59045a7a43e6ff663f055dbf0969791b8ca76b1b01d3475ce - Sigstore transparency entry: 160681197
- Sigstore integration time:
-
Permalink:
planet-a-ventures/pydantic-flatten-rootmodel@907278b0930189a16f03ff8682467f95b5ab8a86 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/planet-a-ventures
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@907278b0930189a16f03ff8682467f95b5ab8a86 -
Trigger Event:
push
-
Statement type: