Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python data model generator (Pydantic, dataclasses, TypedDict, msgspec) from OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV).

License

NotificationsYou must be signed in to change notification settings

koxudaxi/datamodel-code-generator

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

🚀 Generate Python data models from schema definitions in seconds.

PyPI versionConda-forgeDownloadsPyPI - Python VersioncodecovlicensePydantic v1Pydantic v2

✨ What it does

  • 📄 ConvertsOpenAPI 3,JSON Schema,GraphQL, and raw data (JSON/YAML/CSV) into Python models
  • 🐍 Generates fromexisting Python types (Pydantic, dataclass, TypedDict) via--input-model
  • 🎯 GeneratesPydantic v1/v2,dataclasses,TypedDict, ormsgspec output
  • 🔗 Handles complex schemas:$ref,allOf,oneOf,anyOf, enums, and nested types
  • ✅ Produces type-safe, validated code ready for your IDE and type checker

📖 Documentation

👉datamodel-code-generator.koxudaxi.dev


📦 Installation

uv tool install datamodel-code-generator
Other installation methods

pip:

pip install datamodel-code-generator

uv (add to project):

uv add datamodel-code-generator

conda:

conda install -c conda-forge datamodel-code-generator

With HTTP support (for resolving remote$ref):

pip install'datamodel-code-generator[http]'

With GraphQL support:

pip install'datamodel-code-generator[graphql]'

Docker:

docker pull koxudaxi/datamodel-code-generator

🏃 Quick Start

datamodel-codegen --input schema.json --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output model.py
📄 schema.json (input)
{"$schema":"http://json-schema.org/draft-07/schema#","title":"Pet","type":"object","required": ["name","species"],"properties": {"name": {"type":"string","description":"The pet's name"    },"species": {"type":"string","enum": ["dog","cat","bird","fish"]    },"age": {"type":"integer","minimum":0,"description":"Age in years"    },"vaccinated": {"type":"boolean","default":false    }  }}
🐍 model.py (output)
# generated by datamodel-codegen:#   filename:  schema.jsonfrom __future__importannotationsfromenumimportEnumfromtypingimportOptionalfrompydanticimportBaseModel,FieldclassSpecies(Enum):dog='dog'cat='cat'bird='bird'fish='fish'classPet(BaseModel):name:str=Field(...,description="The pet's name")species:Speciesage:Optional[int]=Field(None,description='Age in years',ge=0)vaccinated:Optional[bool]=False

📥 Supported Input

  • OpenAPI 3 (YAML/JSON)
  • JSON Schema
  • JSON / YAML / CSV data
  • GraphQL schema
  • Python types (Pydantic, dataclass, TypedDict) via--input-model
  • Python dictionary

📤 Supported Output


🍳 Common Recipes

🤖 Get CLI Help from LLMs

Generate a prompt to ask LLMs about CLI options:

datamodel-codegen --generate-prompt"Best options for Pydantic v2?"| claude -p

SeeLLM Integration for more examples.

🌐 Generate from URL

pip install'datamodel-code-generator[http]'datamodel-codegen --url https://example.com/api/openapi.yaml --output model.py

⚙️ Use with pyproject.toml

[tool.datamodel-codegen]input ="schema.yaml"output ="src/models.py"output-model-type ="pydantic_v2.BaseModel"

Then simply run:

datamodel-codegen

Seepyproject.toml Configuration for more options.

🔄 CI/CD Integration

Validate generated models in your CI pipeline:

-uses:koxudaxi/datamodel-code-generator@0.44.0with:input:schemas/api.yamloutput:src/models/api.py

SeeCI/CD Integration for more options.


💖 Sponsors

Astral Logo

Astral


🏢 Projects that use datamodel-code-generator

These projects use datamodel-code-generator. See the linked examples for real-world usage.

See all dependents →


🔗 Related Projects


🤝 Contributing

SeeDevelopment & Contributing for how to get started!

📄 License

MIT License - seeLICENSE for details.

About

Python data model generator (Pydantic, dataclasses, TypedDict, msgspec) from OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV).

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors203

Languages


[8]ページ先頭

©2009-2026 Movatter.jp