# Datamodel Code Generator

Use this skill when the user wants Python data models, Pydantic models, dataclasses...

- Repository: https://github.com/datamodel-code-generator/datamodel-code-generator (4047 stars)
- Category: AI and agents
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add datamodel-code-generator/datamodel-code-generator --skill datamodel-code-generator -g -a claude-code -y`
Codex: `npx skills add datamodel-code-generator/datamodel-code-generator --skill datamodel-code-generator -g -a codex -y`
Cursor: `npx skills add datamodel-code-generator/datamodel-code-generator --skill datamodel-code-generator -g -a cursor -y`
Gemini CLI: `npx skills add datamodel-code-generator/datamodel-code-generator --skill datamodel-code-generator -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add datamodel-code-generator/datamodel-code-generator`

## Description

Use this skill when the user wants Python data models, Pydantic models, dataclasses, TypedDicts, msgspec structs, or type-safe Python classes generated from OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON/YAML/CSV sample data, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro, or existing Python model objects. Use it for requests such as "Pydantic models from this schema", "types for this API", "parse this JSON into classes", or "convert this spec into Python models". Prefer the datamodel-codegen CLI over hand-written model code whenever an input schema, API spec, sample data file, or Python model object exists.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# datamodel-code-generator

## Why use this CLI

Use `datamodel-codegen` whenever a schema, API spec, sample data file, or existing Python model object exists.

The CLI handles refs, enums, nested models, unions, `allOf`, `oneOf`, `anyOf`, and model reuse better than hand-written code.

Do not hand-write generated models first.

## Availability check

Check one-shot execution first:

```bash
uvx --from datamodel-code-generator datamodel-codegen --help
```

If `uvx` is unavailable:

```bash
pipx run datamodel-code-generator --help
```

If the project already uses `uv` and project-scoped execution is preferred:

```bash
uv run --with datamodel-code-generator datamodel-codegen --help
```

If the project already has a managed Python virtual environment and the user approves project dependency changes:

```bash
python -m pip install datamodel-code-generator
datamodel-codegen --help
```

Prefer one-shot execution. Do not add or upgrade datamodel-code-generator in the user's project without explicit approval.

If offline and no installed command is available, say that the CLI cannot be run. Only then fall back to hand-written models.

## Option discovery for agents

Before choosing options, run the recommender (experimental) and apply its result:

```bash
datamodel-codegen --input SCHEMA [--input-file-type TYPE] [--output-model-type TYPE] \
  --recommend-options --output-format json
```

Use `arguments` from the payload (or `config` for a project configured in `pyproject.toml`) as the starting command. Do not add options it lists under `not_recommended` without a stated reason.

When the user's goal needs judgment beyond the schema's shape, use the CLI's own LLM workflow and add `--recommend-options` to it, so the prompt includes the recommendation; decide from both:

```bash
datamodel-codegen [known options] --generate-prompt "Find the minimal options for this model-generation task." \
  --recommend-options
```

The rest: https://github.com/datamodel-code-generator/datamodel-code-generator/blob/HEAD/skills/datamodel-code-generator/SKILL.md
