Datamodel Code Generator
Use this skill when the user wants Python data models, Pydantic models, dataclasses...
Install
npx skills add datamodel-code-generator/datamodel-code-generator --skill datamodel-code-generator -g -a claude-code -y- Category
- AI and agents
- Updated
- 3d ago
- License
- MIT
- Context cost
- Mediumabout 2,074 tokens
- Runs scripts
- No, instructions only
What it does
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.
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:
uvx --from datamodel-code-generator datamodel-codegen --help
If uvx is unavailable:
pipx run datamodel-code-generator --help
If the project already uses uv and project-scoped execution is preferred:
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:
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:
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:
datamodel-codegen [known options] --generate-prompt "Find the minimal options for this model-generation task." \
--recommend-options

