datamodel-code-generator skill

A skill that teaches your agent to run datamodel-codegen and get Pydantic models from OpenAPI, JSON Schema and GraphQL

  • 4,057 ★ on the repository
  • Last commit
  • MIT
Skill

Extended access

Why this level

  • The agent runs a command that writes generated files into the project
  • A one-off run through uvx or pipx downloads the package from PyPI
All reasons and checks

datamodel-code-generator/datamodel-code-generator

Install

Manual install

claude plugin marketplace add datamodel-code-generator/datamodel-code-generator
claude plugin install datamodel-code-generator@datamodel-code-generator

The plugin points at the same skills/datamodel-code-generator directory.

Access and checks

How we review

Extended accessThe tool runs code or makes network calls and only reads external data.

  • The agent runs a command that writes generated files into the project
  • A one-off run through uvx or pipx downloads the package from PyPI

This is third-party code. Review the repository files before installing.

What it does

The skill sits in the datamodel-code-generator repository and points the agent to the `datamodel-codegen` command whenever the user has a schema or sample data. Inputs are OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON, YAML and CSV samples, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro or existing Python models. Outputs are Pydantic v2 models, dataclasses, TypedDict or msgspec.Struct. The skill requires running the generator first and hand-writing models only when running it is impossible offline. For a one-shot run it suggests `uvx --from datamodel-code-generator datamodel-codegen --help`, then `pipx run`, then `uv run --with`, and adds the package to a project only with your approval. To choose options the agent calls the recommender with the `--recommend-options` flag and takes the arguments from its answer. Reference files on options, workflows and common failures live in the references folder.

Who it is for. For Python developers who ask Claude Code, Codex or Cursor to build typed models from an API schema or sample data.

Good fit when

  • You have an OpenAPI spec and need Pydantic v2 models for a client or a FastAPI server
  • A JSON or CSV sample must become typed classes
  • A GraphQL, Avro or Protobuf schema must become Python models
  • You need msgspec.Struct or TypedDict instead of Pydantic
  • The schema is complex, with refs, allOf and oneOf, and hand-written code comes out wrong

Not a fit when

  • You need models in another language: the generator outputs only Python
  • There is no schema and no sample to replace it: the skill works from an input file or sample
  • You want to call an API from the command line, and the catalog has OpenAPI to CLI for that

Example request

Generate Pydantic v2 models from openapi.yaml into app/models and check that they import

Limitations

The author calls the skill experimental: the workflow, trigger wording and client install guidance may change. The author also calls the option recommender experimental, so check its advice against the generator's documentation and the generated files. Offline and without an installed command the agent can only hand-write models. There is no separate Codex plugin: Codex works with `datamodel-codegen --install-skill codex` or `npx skills add`.

How to disable. For the Claude Code plugin run `claude plugin uninstall datamodel-code-generator`. If you installed by copying, delete the skill folder from `.claude/skills/` or `.agents/skills/`.

FAQ

How do I install the datamodel-code-generator skill in Claude Code?

Run `claude plugin marketplace add datamodel-code-generator/datamodel-code-generator`, then `claude plugin install datamodel-code-generator@datamodel-code-generator`. If the Python package is already installed, `datamodel-codegen --install-skill claude-code` also works.

Do I need the Python package installed for the skill to work?

No. The skill installs from the repository without the package, and the agent first tries to run the generator one-shot through `uvx` or `pipx run`. The package enters project dependencies only with your approval.

What does the --recommend-options flag do?

It proposes a set of options for your schema. The agent takes the arguments field of the answer as the starting command and adds nothing from the not_recommended list without a reason.

Which input formats does the skill cover?

OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON, YAML and CSV samples, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro and existing Python model objects.

Which models come out?

Pydantic v2, dataclasses, TypedDict and msgspec.Struct. The agent picks the output model type to fit the task.

Discussion

No questions or reviews yet.

Skills

The opinionated-django skill set teaches an agent to build Django projects with API, service, DTO and repository layers.

SkillMinimal access111Repository stars

A SQL code generator with an agent plugin: annotated queries become type-safe database code in ten languages.

CLIExtended access75Repository stars
Editors’ pick

The official FastAPI skill, bundled with the package, teaching agents to write code for the installed version

SkillMinimal access104.7KRepository stars
Official

The PowerSync skill: the agent sets up offline app sync through the CLI, writes Sync Streams and debugs a stuck Syncing status

SkillExtended access22Repository stars

A CLI checking Python service architecture against documented rules, with skills teaching the agent to code within them.

CLIMinimal access199Repository stars

README in short

The README describes the generator itself: installation through uv, conda or pip with extras, supported formats and options. A separate documentation page covers the agent skill: why to run the CLI, how to install the skill for Claude Code, Codex, Gemini CLI and others, and how to use the generator's prompts.

README badge

Original SKILL.md

---
name: 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.
license: MIT
metadata:
  status: experimental
---

# 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

Report a problem