# datamodel-code-generator

> This code generator creates pydantic model from an openapi file and others.

- [datamodel-code-generator](https://datamodel-code-generator.koxudaxi.dev/): Generate Python data models from schema definitions in seconds.
- [Getting Started](https://datamodel-code-generator.koxudaxi.dev/getting-started/): Install `datamodel-code-generator` and generate your first Pydantic v2 model.
- [Presets](https://datamodel-code-generator.koxudaxi.dev/presets/): Presets are immutable named groups of CLI options. A preset name never changes behavior; new recommendations are published as new dated preset names.
- [Playground](https://datamodel-code-generator.koxudaxi.dev/playground/): Run datamodel-code-generator in your browser. The deployed site serves this route as a standalone app so Pyodide only starts after you open it.
- [Supported Input Formats](https://datamodel-code-generator.koxudaxi.dev/supported-data-types/): This code generator supports the following input formats:
- [Schema Version Support](https://datamodel-code-generator.koxudaxi.dev/supported_formats/): This document describes the JSON Schema, OpenAPI, AsyncAPI, Apache Avro, XML Schema, and Protocol Buffers versions supported by datamodel-code-gene...
## Usage

### Input Formats

- [Generate from OpenAPI](https://datamodel-code-generator.koxudaxi.dev/openapi/): Generate Pydantic models from OpenAPI 3 schema definitions.
- [OpenAPI Options](https://datamodel-code-generator.koxudaxi.dev/openapi-options/): When working with OpenAPI specifications, datamodel-code-generator provides several options to control how schemas, operations, and special propert...
- [Generate from AsyncAPI](https://datamodel-code-generator.koxudaxi.dev/asyncapi/): Generate Python models from AsyncAPI 2.x and 3.x documents.
- [Generate from JSON Schema](https://datamodel-code-generator.koxudaxi.dev/jsonschema/): Generate Pydantic models from JSON Schema definitions. See Supported Data Types for supported JSON Schema features.
- [Generate from Apache Avro Schema](https://datamodel-code-generator.koxudaxi.dev/avro/): Generate Python models from JSON-encoded Apache Avro schemas (`.avsc`).
- [Generate from XML Schema](https://datamodel-code-generator.koxudaxi.dev/xmlschema/): Generate Python models from W3C XML Schema documents (`.xsd`).
- [Generate from Protocol Buffers / gRPC](https://datamodel-code-generator.koxudaxi.dev/protobuf/): Generate Python models from Protocol Buffers schema files (`.proto`), including message types referenced by gRPC service definitions.
- [Generate from MCP Tool Schemas](https://datamodel-code-generator.koxudaxi.dev/mcp-tools/): Generate Python models from Model Context Protocol (MCP) tool schema profiles.
- [Generate from JSON / YAML / CSV Data](https://datamodel-code-generator.koxudaxi.dev/jsondata/): Generate Pydantic models directly from raw JSON, YAML, or CSV data. Under the hood, the generator uses GenSON to infer a JSON Schema from JSON/YAML...
- [Generate from GraphQL](https://datamodel-code-generator.koxudaxi.dev/graphql/): Generate Pydantic models from GraphQL schema definitions.
- [Generate from Python Models](https://datamodel-code-generator.koxudaxi.dev/python-model/): Generate code from existing Python types: Pydantic models, dataclasses, TypedDict, or dict schemas. This is useful for converting between model typ...

### Output Customization

- [Output Model Types](https://datamodel-code-generator.koxudaxi.dev/output-model-types/): datamodel-code-generator supports multiple output model types. This page compares them to help you choose the right one for your project.
- [Model Reuse and Deduplication](https://datamodel-code-generator.koxudaxi.dev/model-reuse/): When generating models from schemas, you may encounter duplicate model definitions. datamodel-code-generator provides options to deduplicate models...
- [Module Structure and Exports](https://datamodel-code-generator.koxudaxi.dev/module-exports/): When generating models to a directory structure, datamodel-code-generator can automatically create `__init__.py` files with `__all__` exports. This...
- [Type Mappings and Custom Types](https://datamodel-code-generator.koxudaxi.dev/type-mappings/): datamodel-code-generator allows you to customize how schema types are mapped to Python types. This is essential for projects with specific type req...
- [Python Version Compatibility](https://datamodel-code-generator.koxudaxi.dev/python-version-compatibility/): datamodel-code-generator can generate code compatible with different Python versions. This page explains how to control type annotation syntax and ...
- [Root Models and Type Aliases](https://datamodel-code-generator.koxudaxi.dev/root-model-and-type-alias/): When a schema defines a simple type (not an object with properties), `datamodel-code-generator` creates a root model. If you don't want to introduc...
- [Field Constraints](https://datamodel-code-generator.koxudaxi.dev/field-constraints/): The `--field-constraints` option converts all `con*` annotations (like `conint`, `constr`) to `Field` constraint options.
- [Field Aliases](https://datamodel-code-generator.koxudaxi.dev/aliases/): The `--aliases` option allows you to rename fields in the generated models. This is useful when you want to use different Python field names than t...
- [Field Validators](https://datamodel-code-generator.koxudaxi.dev/validators/): The `--validators` option allows you to add custom field validators to generated Pydantic v2 models. This enables you to inject validation logic in...
- [Custom Class Decorators](https://datamodel-code-generator.koxudaxi.dev/class-decorators/): The `--class-decorators` option adds custom decorators to all generated model classes. This is useful for integrating with serialization libraries ...

### Templates and Formatting

- [Custom Templates](https://datamodel-code-generator.koxudaxi.dev/custom_template/): One of the powerful features of datamodel-code-generator is the ability to use custom templates with the `--custom-template-dir` option. This allow...
- [Custom Code Formatters](https://datamodel-code-generator.koxudaxi.dev/custom-formatters/): Create your own custom code formatters for specialized formatting needs.
- [Code Formatting](https://datamodel-code-generator.koxudaxi.dev/formatting/): Generated code is automatically formatted using code formatters. By default, `black` and `isort` are used to produce consistent, well-formatted out...
- [Formatter behavior](https://datamodel-code-generator.koxudaxi.dev/formatter-behavior/): `datamodel-codegen` formats generated Python code after model generation. The default formatter list is currently `black` and `isort`.

### Integration

- [One-liner Usage](https://datamodel-code-generator.koxudaxi.dev/oneliner/): This guide covers how to use datamodel-code-generator with pipes and clipboard tools for quick, one-time code generation without permanent installa...
- [Using datamodel-code-generator as a Module](https://datamodel-code-generator.koxudaxi.dev/using_as_module/): datamodel-code-generator is a CLI tool, but it can also be used as a Python module.
- [Dynamic Model Generation](https://datamodel-code-generator.koxudaxi.dev/dynamic-model-generation/): Generate real Python model classes from JSON Schema or OpenAPI at runtime without writing files.
- [pyproject.toml Configuration](https://datamodel-code-generator.koxudaxi.dev/pyproject_toml/): datamodel-code-generator can be configured using `pyproject.toml`. The tool automatically searches for `pyproject.toml` in the current directory an...
- [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/): This guide covers how to use datamodel-code-generator in CI/CD pipelines and development workflows to ensure generated code stays in sync with sche...
- [LLM Integration](https://datamodel-code-generator.koxudaxi.dev/llm-integration/): The `--generate-prompt` option generates a formatted prompt that you can use to consult Large Language Models (LLMs) about datamodel-code-generator...
- [Using datamodel-code-generator with coding agents](https://datamodel-code-generator.koxudaxi.dev/coding-agent-skill/): This repository includes an experimental Agent Skill for skills-compatible coding agents. The skill teaches an agent to run `datamodel-codegen` whe...


## CLI Reference

- [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/): This documentation is auto-generated from test cases.
- [Base Options](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/)
- [Model Customization](https://datamodel-code-generator.koxudaxi.dev/cli-reference/model-customization/)
- [Field Customization](https://datamodel-code-generator.koxudaxi.dev/cli-reference/field-customization/)
- [Typing Customization](https://datamodel-code-generator.koxudaxi.dev/cli-reference/typing-customization/)
- [Template Customization](https://datamodel-code-generator.koxudaxi.dev/cli-reference/template-customization/)
- [OpenAPI-only Options](https://datamodel-code-generator.koxudaxi.dev/cli-reference/openapi-only-options/): This generated reference lists every OpenAPI-only CLI flag and its tested examples. For a workflow-oriented guide, see OpenAPI Options. For input f...
- [GraphQL-only Options](https://datamodel-code-generator.koxudaxi.dev/cli-reference/graphql-only-options/)
- [General Options](https://datamodel-code-generator.koxudaxi.dev/cli-reference/general-options/)
- [Utility Options](https://datamodel-code-generator.koxudaxi.dev/cli-reference/utility-options/)
### Focused Topics

- [Model Customization](https://datamodel-code-generator.koxudaxi.dev/cli-reference/topics/model-customization/): Choose model class shape, naming, reuse, and root-model behavior.
- [Template Customization](https://datamodel-code-generator.koxudaxi.dev/cli-reference/topics/template-customization/): Tune generated file headers, imports, decorators, templates, and formatting.
- [Typing Customization](https://datamodel-code-generator.koxudaxi.dev/cli-reference/topics/typing-customization/): Control Python annotation syntax, collection types, imports, and type mappings.
- [OpenAPI](https://datamodel-code-generator.koxudaxi.dev/cli-reference/topics/openapi/): Handle OpenAPI operation naming, path selection, scopes, and readOnly/writeOnly behavior.

- [Quick Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/quick-reference/): All CLI options in one page for easy **Ctrl+F** searching.
### Manual

- [Help](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/help/)
- [Version](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/version/)
- [Debug](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/debug/)
- [Profile](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/profile/)
- [No Color](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/no-color/)
- [Generate Prompt](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/generate-prompt/)
- [List Deprecations](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/list-deprecations/)
- [List Experimental](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/list-experimental/)
- [Output Format](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/output-format/)
- [Output Format Json Schema](https://datamodel-code-generator.koxudaxi.dev/cli-reference/manual/output-format-json-schema/)


- [Conformance Dashboard](https://datamodel-code-generator.koxudaxi.dev/conformance/): This page summarizes the external conformance and end-to-end corpus checks that CI runs for datamodel-code-generator. The table is generated from `...
- [Performance Benchmarks](https://datamodel-code-generator.koxudaxi.dev/performance-benchmarks/): This page tracks datamodel-code-generator release and main-branch benchmark results collected on GitHub Actions. The data covers only datamodel-cod...
- [Deprecations](https://datamodel-code-generator.koxudaxi.dev/deprecations/): This page lists deprecations and scheduled breaking changes.
- [Experimental Features](https://datamodel-code-generator.koxudaxi.dev/experimental/): This page lists features that are available but still experimental.
- [Architecture](https://datamodel-code-generator.koxudaxi.dev/architecture/): `datamodel-code-generator` is organized around one central idea: many input formats are normalized into a shared generation graph, then rendered th...
## Optional

- [Frequently Asked Questions](https://datamodel-code-generator.koxudaxi.dev/faq/)
- [Development](https://datamodel-code-generator.koxudaxi.dev/development-contributing/): Install the package in editable mode:
