{"id":23388451,"url":"https://github.com/planet-a-ventures/pydantic-flatten-rootmodel","last_synced_at":"2025-04-08T13:23:50.311Z","repository":{"id":269064772,"uuid":"906314678","full_name":"planet-a-ventures/pydantic-flatten-rootmodel","owner":"planet-a-ventures","description":"Library to flatten a Pydantic (www.github.com/pydantic/pydantic) RootModel into a flattened BaseModel","archived":false,"fork":false,"pushed_at":"2025-01-31T10:47:12.000Z","size":56,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-14T09:41:19.487Z","etag":null,"topics":["flatten","pydantic","python","rootmodel"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/planet-a-ventures.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-20T16:12:32.000Z","updated_at":"2025-01-31T10:47:15.000Z","dependencies_parsed_at":"2024-12-20T17:26:43.899Z","dependency_job_id":"e90d8186-9a58-434f-ac3c-5fa2196a8e8d","html_url":"https://github.com/planet-a-ventures/pydantic-flatten-rootmodel","commit_stats":null,"previous_names":["planet-a-ventures/pydantic-flatten-rootmodel"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planet-a-ventures%2Fpydantic-flatten-rootmodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planet-a-ventures%2Fpydantic-flatten-rootmodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planet-a-ventures%2Fpydantic-flatten-rootmodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planet-a-ventures%2Fpydantic-flatten-rootmodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/planet-a-ventures","download_url":"https://codeload.github.com/planet-a-ventures/pydantic-flatten-rootmodel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247848633,"owners_count":21006286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flatten","pydantic","python","rootmodel"],"created_at":"2024-12-22T02:20:17.757Z","updated_at":"2025-04-08T13:23:50.284Z","avatar_url":"https://github.com/planet-a-ventures.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pydantic-flatten-rootmodel\n\n[![PyPI version](https://img.shields.io/pypi/v/pydantic-flatten-rootmodel.svg)](https://pypi.org/project/pydantic-flatten-rootmodel/)\n\nLibrary to transform a [Pydantic](https://pydantic.dev/)\n[RootModel](https://docs.pydantic.dev/latest/api/root_model/)\nwith discriminated unions into a flattened BaseModel.\n\n```py\nfrom pydantic_flatten_rootmodel import flatten_root_model\n\nclass Cat(BaseModel):\n    pet_type: Annotated[Literal[\"cat\"], Field()]\n    meow: str\n\n\nclass Dog(BaseModel):\n    pet_type: Annotated[Literal[\"dog\"], Field()]\n    bark: str\n\nclass Pet(RootModel[Cat | Dog]):\n    root: Annotated[Cat | Dog, Field(discriminator=\"pet_type\")]\n\n\nFlattenedPet = flatten_root_model(Pet)\n```\n\n would result in `FlattenedPet` to have this shape:\n\n ```py\n class FlattenedPet(BaseModel):\n    pet_type: Annotated[Union[Literal[\"cat\"], Literal[\"dog\"]]]\n    bark: Union[str, None]\n    meow: Union[str, None]\n ```\n\n This can for example be leveraged by [dlt](https://dlthub.com) for it's\n [schema definition](https://dlthub.com/docs/general-usage/resource#define-a-schema-with-pydantic).\n Without flattening it, the discriminated union is not recognized correctly\n when setting up the table schema.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanet-a-ventures%2Fpydantic-flatten-rootmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplanet-a-ventures%2Fpydantic-flatten-rootmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanet-a-ventures%2Fpydantic-flatten-rootmodel/lists"}