Generate Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON/YAML/CSV, plus FastAPI servers and Python clients from OpenAPI.
# Add to your Claude Code skills
git clone https://github.com/datamodel-code-generator/datamodel-code-generatorGuides for using ai agents skills like datamodel-code-generator.
datamodel-code-generator is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by datamodel-code-generator. Generate Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON/YAML/CSV, plus FastAPI servers and Python clients from OpenAPI. It has 4,067 GitHub stars.
datamodel-code-generator's catalog security scan is still queued. You can run an instant dependency and prompt-injection check now with the "Scan for vulnerabilities" button above.
Clone the repository with "git clone https://github.com/datamodel-code-generator/datamodel-code-generator" and add it to your Claude Code skills directory (see the Installation section above).
datamodel-code-generator is primarily written in Python. It is open-source under datamodel-code-generator on GitHub, so you can review or fork the full source.
Yes. AgentsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh datamodel-code-generator against similar tools.
No comments yet. Be the first to share your thoughts!
Unlocks once the catalog security scan passes (runs nightly).
The deep catalog scan for this skill is still queued. Run an instant dependency check now instead.
🚀 Generate Python models, typed clients and FastAPI servers (experimental) from schemas, deterministically, with --check for drift.
📚 Documentation · 🧪 Playground · 💼 Lead maintainer available for work
[!NOTE] Playground privacy: Generation runs locally in your browser with Pyodide. Your schema and options are not sent to a backend. Shared repro URLs encode them in the URL fragment (
#state=...), which browsers do not send to the server; the full URL can still be stored in your browser history or wherever you share it.
Pick any one of the supported inputs and pick the Python model style you want as output. From OpenAPI (and, for
clients, AsyncAPI), the same run can also write a typed client or a FastAPI server package (experimental).
Generation is deterministic with a preset, which turns the header timestamp off, and
datamodel-codegen --check exits with 1 when the files on disk differ from what the schema generates, so CI catches drift.
--input-model path/to/file.py:ClassName can even retarget an existing Pydantic, dataclass, or TypedDict class defined
in another Python file to a different output type.
--input-model--generate-client httpx2, from OpenAPI and AsyncAPI) or a FastAPI server (--generate-server fastapi, from OpenAPI) together with the models (experimental)--client-tools functions or mcp, experimental)pyproject.toml (--recommend-options --write-pyproject-config, experimental)$ref, allOf, oneOf, anyOf, enums, and nested typesRecommended for standalone CLI use:
uv tool install datamodel-code-generator
Conda users can install from conda-forge:
conda install -c conda-forge datamodel-code-generator
For projects that should pin the generator version, add it as a development dependency instead:
uv add --dev datamodel-code-generator
[!NOTE] Community-maintained distribution packages are also available from Debian, Ubuntu, nixpkgs, and openSUSE Tumbleweed. Availability and versions vary by distribution.
pip:
pip install datamodel-code-generator
uv (run without adding to project):
uv run --with datamodel-code-generator datamodel-codegen --help
With stable HTTP support (for resolving remote $ref):
pip install 'datamodel-code-generator[http]'
The http extra is supported and is not deprecated. To require the experimental
HTTPX2 backend instead, install datamodel-code-generator[httpx2] and pass
--http-backend httpx2. The experimental extra is not included in
datamodel-code-generator[all]. See
HTTP backend selection
for automatic and explicit selection behavior.
With GraphQL support:
pip install 'datamodel-code-generator[graphql]'
With Protocol Buffers support:
pip install 'datamodel-code-generator[protobuf]'
Docker:
docker pull koxudaxi/datamodel-code-generator
Published Docker images run as a non-root appuser. When writing generated files
to a bind-mounted directory, make sure the directory is writable by the container
user or pass an explicit Docker user, for example --user "$(id -u):$(id -g)".
Command
datamodel-codegen \
--input schema.json \
--input-file-type jsonschema \
--output-model-type pydantic_v2.BaseModel \
--preset standard-py312-20261128 \
--output model.py
This quick start uses standard-py312-20261128 as the modern Python 3.12 baseline.
Preset names include the target Python version: py312 means Python 3.12.
See CLI Reference for all options. See Presets,
--preset, --input-file-type, and
--output-model-type for this command.
For more schema-aware output that preserves schema-authored names, reuses models, and embeds generated
documentation, use practical-py312-20261128.
Not sure which options fit your schema? Add --recommend-options to the command above (experimental). It
analyses the schema and prints the options to add on top of the latest preset with the reason for each, and a ready
command and pyproject.toml block. See
Option recommendations.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Pet",
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"description": "The pet's name"
},
"species": {
"type": "string",
"enum": ["dog", "cat", "bird", "fish"],
"default": "dog"
},
"age": {
"type": "integer",
"minimum": 0,
"description": "Age in years"
},
"vaccinated": {
"type": "boolean",
"default": false
}
}
}
Output (model.py)
# generated by datamodel-codegen:
# filename: schema.json
from __future__ import annotations
from enum import StrEnum
from typing import Annotated
from pydantic import BaseModel, ConfigDict, Field
class Species(StrEnum):
dog = 'dog'
cat = 'cat'
bird = 'bird'
fish = 'fish'
class Pet(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
name: Annotated[str, Field(description="The pet's name")]
species: Species = Species.dog
age: Annotated[int | None, Field(description='Age in years', ge=0)] = None
vaccinated: bool = False
Choose a formatter to match your project and generation priorities:
--formatters ruff-check ruff-format to keep generated code consistent with the
project's formatting and lint policy. Install it with pip install 'datamodel-code-generator[ruff]'.--formatters builtin to avoid running
external formatters on standard generated model modules.--formatters black isort to preserve the project's formatting and existing
generated output.The current default remains Black/isort, which are still required dependencies. Omitting formatter options continues normal generation. The future builtin default is intended to reduce required installation dependencies and version constraints; Ruff will still be recommended for projects that use Ruff. Format