{"id":15012912,"url":"https://github.com/niklasvonm/pydantic-modelgen","last_synced_at":"2026-01-27T13:31:18.765Z","repository":{"id":243383761,"uuid":"812272735","full_name":"NiklasvonM/pydantic-modelgen","owner":"NiklasvonM","description":"Create Pydantic BaseModels from JSON Schema at runtime.","archived":false,"fork":false,"pushed_at":"2024-06-12T20:06:47.000Z","size":315,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T04:12:39.538Z","etag":null,"topics":["json-schema","pydantic","pydantic-v2"],"latest_commit_sha":null,"homepage":"https://niklasvonm.github.io/pydantic-modelgen/","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/NiklasvonM.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-06-08T12:26:59.000Z","updated_at":"2024-07-07T16:43:38.000Z","dependencies_parsed_at":"2024-09-20T08:00:31.305Z","dependency_job_id":null,"html_url":"https://github.com/NiklasvonM/pydantic-modelgen","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"7753ee62a9c3368ef4e096d82aa6d60da2d7ab6f"},"previous_names":["niklasvonm/pydantic-modelgen"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiklasvonM%2Fpydantic-modelgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiklasvonM%2Fpydantic-modelgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiklasvonM%2Fpydantic-modelgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NiklasvonM%2Fpydantic-modelgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NiklasvonM","download_url":"https://codeload.github.com/NiklasvonM/pydantic-modelgen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514205,"owners_count":21116903,"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":["json-schema","pydantic","pydantic-v2"],"created_at":"2024-09-24T19:43:24.431Z","updated_at":"2026-01-27T13:31:18.679Z","avatar_url":"https://github.com/NiklasvonM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pydantic-modelgen\n\nCreate Pydantic `BaseModel`s from JSON Schema at runtime.\n\n[![Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12-blue)](https://www.python.org/downloads/)\n[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Mypy](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/mypy.yml/badge.svg)](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/mypy.yml)\n[![Ruff](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/ruff.yml/badge.svg)](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/ruff.yml)\n[![Tests](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/tests.yml/badge.svg)](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/tests.yml)\n[![Security](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/bandit.yml/badge.svg)](https://github.com/NiklasvonM/pydantic-modelgen/actions/workflows/bandit.yml)\n\nSee [documentation](https://niklasvonm.github.io/pydantic-modelgen/).\n\n## Usage\n\n```python\nfrom pydanticmodelgen import generate_basemodel\n\njson_schema = {\n    \"title\": \"Person Information\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": {\"type\": \"string\"},\n        \"age\": {\"type\": \"integer\", \"minimum\": 0},\n        \"gender\": {\"enum\": [\"male\", \"female\", \"other\"]}\n    }\n}\nmodel = generate_basemodel(json_schema, validate_schema=True)\nprint(model)\n# \u003cclass 'pydanticmodelgen.generate_model.Person Information'\u003e\nprint(model.model_fields)\n# {'name': FieldInfo(annotation=str, required=False, default=None), 'age': FieldInfo(annotation=int, required=False, default=None, metadata=[Ge(ge=0)]), 'gender': FieldInfo(annotation=genderEnum, required=False, default=None)}\ninstance = model(**{\"name\": \"John Doe\", \"age\": 30, \"gender\": \"male\"})\nprint(instance)\n# name='John Doe' age=30 gender='male'\n```\n\n## Motivation\n\nThe motivation for this project is to create dynamic Swagger API documentations for FastAPI apps, which rely on Pydantic, from JSON Schema. This is useful when the application logic does not depend on the exact schema of the JSON, but the consumers of the REST API do. For example, this may be the case if the JSON is populated via an LLM.\n\nIf data validation is your only concern, [python-jsonschema](https://github.com/python-jsonschema/jsonschema) is recommended.\n\n\u003cdetails open\u003e\n    \u003csummary\u003eDemo FastAPI App\u003c/summary\u003e\n\n```python\nimport uvicorn\nfrom fastapi import FastAPI\nfrom pydanticmodelgen import generate_basemodel\n\napp = FastAPI(title=\"Pydantic Modelgen Demo\")\n\njson_schema = {\n    \"title\": \"Person Information\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": {\"type\": \"string\"},\n        \"age\": {\"type\": \"integer\", \"minimum\": 0},\n        \"gender\": {\"enum\": [\"male\", \"female\", \"other\"]},\n    },\n}\n\nModel = generate_basemodel(json_schema)\n\n@app.get(\"/\", response_model=Model)\nasync def root():\n    return Model(name=\"Alice\", age=30)\n\nif __name__ == \"__main__\":\n    uvicorn.run(app, host=\"0.0.0.0\", port=8000)\n```\n\n\u003c/details\u003e\n\nWhile running this FastAPI app, the following documentation can be accessed under localhost:8000/docs:\n\n![Swagger API Documentation](docs/Swagger%20Documentation%20Demo.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasvonm%2Fpydantic-modelgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniklasvonm%2Fpydantic-modelgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasvonm%2Fpydantic-modelgen/lists"}