datamodel-code-generator-0.9.4
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.26
0.6.25
0.6.24
0.6.23
0.6.22
0.6.21
0.6.20
0.6.2
0.6.19
0.6.18
0.6.17
0.6.16
0.6.15
0.6.14
0.6.13
0.6.12
0.6.11
0.6.10
0.6.1
0.6.0
0.57.0
0.56.1
0.56.0
0.55.0
0.54.1
0.54.0
0.53.0
0.52.2
0.52.1
0.52.0
0.51.0
0.50.0
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.39
0.5.38
0.5.37
0.5.36
0.5.35
0.5.34
0.5.33
0.5.32
0.5.31
0.5.30
0.5.3
0.5.29
0.5.28
0.5.27
0.5.26
0.5.25
0.5.24
0.5.23
0.5.22
0.5.21
0.5.20
0.5.2
0.5.19
0.5.18
0.5.17
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.1
0.5.0
0.49.0
0.48.0
0.47.0
0.46.0
0.45.0
0.44.0
0.43.1
0.43.0
0.42.2
0.42.1
0.42.0
0.41.0
0.40.0
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.11
0.4.10
0.4.1
0.4.0
0.39.0
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.0
0.32.0
0.31.2
0.31.1
0.31.0
0.30.2
0.30.1
0.30.0
0.3.3
0.3.2
0.3.1
0.3.0
0.29.0
0.28.5
0.28.4
0.28.3
0.28.2
0.28.1
0.28.0
0.27.3
0.27.2
0.27.1
0.27.0
0.26.5
0.26.4
0.26.3
0.26.2
0.26.1
0.26.0
0.25.9
0.25.8
0.25.7
0.25.6
0.25.5
0.25.4
0.25.3
0.25.2
0.25.1
0.25.0
0.24.2
0.24.1
0.24.0
0.23.0
0.22.1
0.22.0
0.21.5
0.21.4
0.21.3
0.21.2
0.21.1
0.21.0
0.20.0
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.16
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.10
0.2.1
0.2.0
0.19.0
0.18.1
0.18.0
0.17.2
0.17.1
0.17.0
0.16.1
0.16.0
0.15.0
0.14.1
0.14.0
0.13.5
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.12.3
0.12.2
0.12.1
0.12.0
0.11.9
0.11.8
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.20
0.11.2
0.11.19
0.11.18
0.11.17
0.11.16
0.11.15
0.11.14
0.11.13
0.11.12
0.11.11
0.11.10
0.11.1
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.1.0
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.26
0.6.25
0.6.24
0.6.23
0.6.22
0.6.21
0.6.20
0.6.2
0.6.19
0.6.18
0.6.17
0.6.16
0.6.15
0.6.14
0.6.13
0.6.12
0.6.11
0.6.10
0.6.1
0.6.0
0.57.0
0.56.1
0.56.0
0.55.0
0.54.1
0.54.0
0.53.0
0.52.2
0.52.1
0.52.0
0.51.0
0.50.0
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.39
0.5.38
0.5.37
0.5.36
0.5.35
0.5.34
0.5.33
0.5.32
0.5.31
0.5.30
0.5.3
0.5.29
0.5.28
0.5.27
0.5.26
0.5.25
0.5.24
0.5.23
0.5.22
0.5.21
0.5.20
0.5.2
0.5.19
0.5.18
0.5.17
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.1
0.5.0
0.49.0
0.48.0
0.47.0
0.46.0
0.45.0
0.44.0
0.43.1
0.43.0
0.42.2
0.42.1
0.42.0
0.41.0
0.40.0
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.11
0.4.10
0.4.1
0.4.0
0.39.0
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.0
0.32.0
0.31.2
0.31.1
0.31.0
0.30.2
0.30.1
0.30.0
0.3.3
0.3.2
0.3.1
0.3.0
0.29.0
0.28.5
0.28.4
0.28.3
0.28.2
0.28.1
0.28.0
0.27.3
0.27.2
0.27.1
0.27.0
0.26.5
0.26.4
0.26.3
0.26.2
0.26.1
0.26.0
0.25.9
0.25.8
0.25.7
0.25.6
0.25.5
0.25.4
0.25.3
0.25.2
0.25.1
0.25.0
0.24.2
0.24.1
0.24.0
0.23.0
0.22.1
0.22.0
0.21.5
0.21.4
0.21.3
0.21.2
0.21.1
0.21.0
0.20.0
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.16
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.10
0.2.1
0.2.0
0.19.0
0.18.1
0.18.0
0.17.2
0.17.1
0.17.0
0.16.1
0.16.0
0.15.0
0.14.1
0.14.0
0.13.5
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.12.3
0.12.2
0.12.1
0.12.0
0.11.9
0.11.8
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.20
0.11.2
0.11.19
0.11.18
0.11.17
0.11.16
0.11.15
0.11.14
0.11.13
0.11.12
0.11.11
0.11.10
0.11.1
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.1.0
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
توضیحات
Datamodel Code Generator
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | datamodel-code-generator-0.9.4 |
| نام | datamodel-code-generator |
| نسخه کتابخانه | 0.9.4 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | - |
| ایمیل نویسنده | Koudai Aono <koxudaxi@gmail.com> |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/datamodel-code-generator/ |
| مجوز | - |
# datamodel-code-generator
🚀 Generate Python data models from schema definitions in seconds.
[](https://pypi.python.org/pypi/datamodel-code-generator)
[](https://anaconda.org/conda-forge/datamodel-code-generator)
[](https://pypistats.org/packages/datamodel-code-generator)
[](https://pypi.python.org/pypi/datamodel-code-generator)
[](https://codecov.io/gh/koxudaxi/datamodel-code-generator)

[](https://pydantic.dev)
> 📣 💼 Maintainer update: Open to opportunities. 🔗 [koxudaxi.dev](https://koxudaxi.dev/?utm_source=github_readme&utm_medium=top&utm_campaign=open_to_work)
## ✨ What it does
- 📄 Converts **OpenAPI 3**, **JSON Schema**, **GraphQL**, and raw data (JSON/YAML/CSV) into Python models
- 🐍 Generates from **existing Python types** (Pydantic, dataclass, TypedDict) via `--input-model`
- 🎯 Generates **Pydantic v2**, **Pydantic v2 dataclass**, **dataclasses**, **TypedDict**, or **msgspec** 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](https://datamodel-code-generator.koxudaxi.dev)**
- 🖥️ [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/) - All command-line options
- ⚙️ [pyproject.toml](https://datamodel-code-generator.koxudaxi.dev/pyproject_toml/) - Configuration file
- 🔄 [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/) - GitHub Actions, pre-commit hooks
- 🚀 [One-liner Usage](https://datamodel-code-generator.koxudaxi.dev/oneliner/) - uvx, pipx, clipboard integration
- ❓ [FAQ](https://datamodel-code-generator.koxudaxi.dev/faq/) - Common questions
---
## 📦 Installation
```bash
uv tool install datamodel-code-generator
```
<details>
<summary>Other installation methods</summary>
**pip:**
```bash
pip install datamodel-code-generator
```
**uv (add to project):**
```bash
uv add datamodel-code-generator
```
**conda:**
```bash
conda install -c conda-forge datamodel-code-generator
```
**With HTTP support** (for resolving remote `$ref`):
```bash
pip install 'datamodel-code-generator[http]'
```
**With GraphQL support:**
```bash
pip install 'datamodel-code-generator[graphql]'
```
**Docker:**
```bash
docker pull koxudaxi/datamodel-code-generator
```
</details>
---
## 🏃 Quick Start
```bash
datamodel-codegen --input schema.json --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output model.py
```
<details>
<summary>📄 schema.json (input)</summary>
```json
{
"$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
}
}
}
```
</details>
<details>
<summary>🐍 model.py (output)</summary>
```python
# generated by datamodel-codegen:
# filename: schema.json
from __future__ import annotations
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field
class Species(Enum):
dog = 'dog'
cat = 'cat'
bird = 'bird'
fish = 'fish'
class Pet(BaseModel):
name: str = Field(..., description="The pet's name")
species: Species
age: Optional[int] = Field(None, description='Age in years', ge=0)
vaccinated: Optional[bool] = False
```
</details>
---
## 📥 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
- [pydantic v2](https://docs.pydantic.dev/) BaseModel
- [pydantic v2](https://docs.pydantic.dev/) dataclass
- [dataclasses](https://docs.python.org/3/library/dataclasses.html)
- [TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict)
- [msgspec](https://github.com/jcrist/msgspec) Struct
---
## 🍳 Common Recipes
### 🤖 Get CLI Help from LLMs
Generate a prompt to ask LLMs about CLI options:
```bash
datamodel-codegen --generate-prompt "Best options for Pydantic v2?" | claude -p
```
See [LLM Integration](https://datamodel-code-generator.koxudaxi.dev/llm-integration/) for more examples.
### 🌐 Generate from URL
```bash
pip install 'datamodel-code-generator[http]'
datamodel-codegen --url https://example.com/api/openapi.yaml --output model.py
```
### ⚙️ Use with pyproject.toml
```toml
[tool.datamodel-codegen]
input = "schema.yaml"
output = "src/models.py"
output-model-type = "pydantic_v2.BaseModel"
```
Then simply run:
```bash
datamodel-codegen
```
See [pyproject.toml Configuration](https://datamodel-code-generator.koxudaxi.dev/pyproject_toml/) for more options.
### 🔄 CI/CD Integration
Validate generated models in your CI pipeline:
```yaml
- uses: koxudaxi/datamodel-code-generator@0.44.0
with:
input: schemas/api.yaml
output: src/models/api.py
```
See [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/) for more options.
---
## 💖 Sponsors
<table>
<tr>
<td valign="top" align="center">
<a href="https://github.com/astral-sh">
<img src="https://avatars.githubusercontent.com/u/115962839?s=200&v=4" alt="Astral Logo" style="width: 100px;">
<p>Astral</p>
</a>
</td>
</tr>
</table>
---
## 🏢 Projects that use datamodel-code-generator
These projects use datamodel-code-generator. See the linked examples for real-world usage.
- [PostHog/posthog](https://github.com/PostHog/posthog) - *[Generate models via npm run](https://github.com/PostHog/posthog/blob/e1a55b9cb38d01225224bebf8f0c1e28faa22399/package.json#L41)*
- [airbytehq/airbyte](https://github.com/airbytehq/airbyte) - *[Generate Python, Java/Kotlin, and Typescript protocol models](https://github.com/airbytehq/airbyte-protocol/tree/main/protocol-models/bin)*
- [apache/iceberg](https://github.com/apache/iceberg) - *[Generate Python code](https://github.com/apache/iceberg/blob/d2e1094ee0cc6239d43f63ba5114272f59d605d2/open-api/README.md?plain=1#L39)*
- [open-metadata/OpenMetadata](https://github.com/open-metadata/OpenMetadata) - *[datamodel_generation.py](https://github.com/open-metadata/OpenMetadata/blob/main/scripts/datamodel_generation.py)*
- [openai/codex](https://github.com/openai/codex) - *[Python SDK dev dependency](https://github.com/openai/codex/blob/cca36c5681d16c7dac6e3f385589b8cd4d3e78cd/sdk/python/pyproject.toml#L32-L33)*
- [vllm-project/vllm](https://github.com/vllm-project/vllm) - *[Test dependency for model tests](https://github.com/vllm-project/vllm/blob/main/requirements/test.in)*
- [stanfordnlp/dspy](https://github.com/stanfordnlp/dspy) - *[Generate Pydantic models from JSON Schema for reliability tests](https://github.com/stanfordnlp/dspy/blob/main/tests/reliability/generate/utils.py)*
- [topoteretes/cognee](https://github.com/topoteretes/cognee) - *[Runtime generation of graph data models from JSON Schema](https://github.com/topoteretes/cognee/blob/main/cognee/shared/graph_model_utils.py)*
- [e2b-dev/E2B](https://github.com/e2b-dev/E2B) - *[Generate MCP server TypedDict models via Makefile](https://github.com/e2b-dev/E2B/blob/main/packages/python-sdk/Makefile)*
- [apache/airflow](https://github.com/apache/airflow) - *[Generate OpenAPI datamodels for airflow-ctl and task-sdk via pyproject codegen config](https://github.com/apache/airflow/blob/f1ac27af8b53e7d3ca7ff710c4f4413599bd1535/airflow-ctl/pyproject.toml#L148-L172)*
- [browser-use/browser-use](https://github.com/browser-use/browser-use) - *[Eval dependency](https://github.com/browser-use/browser-use/blob/de14b9aa31d167696a7ea7185d71876dbd7e6c94/pyproject.toml#L74-L79)*
- [firebase/genkit](https://github.com/firebase/genkit) - *[Generate core typing models from JSON Schema](https://github.com/firebase/genkit/blob/main/py/bin/generate_schema_typing)*
- [open-telemetry/opentelemetry-python](https://github.com/open-telemetry/opentelemetry-python) - *[Generate SDK configuration dataclasses from JSON Schema](https://github.com/open-telemetry/opentelemetry-python/blob/main/tox.ini)*
- [DataDog/integrations-core](https://github.com/DataDog/integrations-core) - *[Config models](https://github.com/DataDog/integrations-core/blob/master/docs/developer/meta/config-models.md)*
- [argoproj-labs/hera](https://github.com/argoproj-labs/hera) - *[Makefile](https://github.com/argoproj-labs/hera/blob/c8cbf0c7a676de57469ca3d6aeacde7a5e84f8b7/Makefile#L53-L62)*
- [tensorzero/tensorzero](https://github.com/tensorzero/tensorzero) - *[Generate Python dataclasses from JSON Schema in the schema generation pipeline](https://github.com/tensorzero/tensorzero/blob/26a51c8808f64cc0beaf8db4dfeea646cffbdaaa/crates/tensorzero-python/generate_schema_types.py#L1-L26)*
- [IBM/compliance-trestle](https://github.com/IBM/compliance-trestle) - *[Building models from OSCAL schemas](https://github.com/IBM/compliance-trestle/blob/develop/docs/contributing/website.md#building-the-models-from-the-oscal-schemas)*
[See all dependents →](https://github.com/koxudaxi/datamodel-code-generator/network/dependents)
---
## 🔗 Related Projects
- **[fastapi-code-generator](https://github.com/koxudaxi/fastapi-code-generator)** - Generate FastAPI app from OpenAPI
- **[pydantic-pycharm-plugin](https://github.com/koxudaxi/pydantic-pycharm-plugin)** - PyCharm plugin for Pydantic
---
## 🤝 Contributing
See [Development & Contributing](https://datamodel-code-generator.koxudaxi.dev/development-contributing/) for how to get started!
## 📄 License
MIT License - see [LICENSE](LICENSE) for details.
نیازمندی
| مقدار | نام |
|---|---|
| - | argcomplete<4,>=2.10.1 |
| - | black>=19.10b0 |
| - | genson<2,>=1.2.1 |
| - | inflect<8,>=4.1 |
| - | isort<9,>=4.3.21 |
| - | jinja2<4,>=2.10.1 |
| ython_versio | pydantic<3,>=2.12; |
| ython_versio | pydantic<3,>=2; |
| - | pyyaml>=6.0.1 |
| ython_versio | tomli<3,>=2.2.1; |
| xtr | graphql-core>=3.2.3; |
| xtr | httpx>=0.24.1; |
| xtr | openapi-spec-validator<0.8,>=0.2.8; |
| xtr | prance>=0.18.2; |
| xtr | pysnooper<2,>=0.4.1; |
| xtr | ruff>=0.9.10; |
| xtr | watchfiles>=1.1; |
| xtr | pysnooper<2,>=0.4.1; |
| xtr | graphql-core>=3.2.3; |
| xtr | httpx>=0.24.1; |
| xtr | ruff>=0.9.10; |
| xtr | ryaml>=0.5.1; |
| xtr | openapi-spec-validator<0.8,>=0.2.8; |
| xtr | prance>=0.18.2; |
| xtr | watchfiles>=1.1; |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.10 | Python |
نحوه نصب
نصب پکیج whl datamodel-code-generator-0.9.4:
pip install datamodel-code-generator-0.9.4.whl
نصب پکیج tar.gz datamodel-code-generator-0.9.4:
pip install datamodel-code-generator-0.9.4.tar.gz