Skip to content
Back to search

datamodel-code-generator

Generate Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON/YAML/CSV.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/datamodel-code-generator/datamodel-code-generator with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/datamodel-code-generator/datamodel-code-generator'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/koxudaxi--datamodel-code-generator/badge.svg)](/listings/koxudaxi--datamodel-code-generator)

HTML

<a href="/listings/koxudaxi--datamodel-code-generator"><img src="/api/listings/koxudaxi--datamodel-code-generator/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Recommended 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](https://packages.debian.org/search?keywords=datamodel-codegen&searchon=names&suite=all&section=all), > [Ubuntu](https://packages.ubuntu.com/search?keywords=datamodel-codegen&searchon=names&suite=all&section=all), > [nixpkgs](https://search.nixos.org/packages?query=datamodel-code-generator), and > [openSUSE Tumbleweed](https://software.opensuse.org/package/python-datamodel-code-generator). > Availability and versions vary by distribution.

<details> <summary>Other installation methods</summary>

**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](https://datamodel-code-generator.koxudaxi.dev/faq/#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)"`.

</details>

---

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/marketplace.json · Manifest · 14 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. {
  2. "name": "datamodel-code-generator",
  3. "owner": {
  4. "name": "Koudai Aono"
  5. },
  6. "description": "Agent Skill that teaches coding agents to run datamodel-codegen.",
  7. "plugins": [
  8. {
  9. "name": "datamodel-code-generator",
  10. "source": "./skills/datamodel-code-generator",
  11. "description": "Generate Python models from OpenAPI, JSON Schema, GraphQL and more with datamodel-codegen."
  12. }
  13. ]
  14. }
README.md · README · 740 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. # datamodel-code-generator
  2. 🚀 Generate Python data models from schema definitions in seconds.
  3. 📚 [Documentation](https://datamodel-code-generator.koxudaxi.dev/) ·
  4. 🧪 [Playground](https://datamodel-code-generator.koxudaxi.dev/playground/) ·
  5. 💼 [Lead maintainer available for work](https://koxudaxi.dev/?utm_source=github_readme&utm_medium=top&utm_campaign=open_to_work)
  6. > [!NOTE]
  7. > Playground privacy: Generation runs locally in your browser with Pyodide. Your schema and options are not sent to a
  8. > backend. Shared repro URLs encode them in the URL fragment (`#state=...`), which browsers do not send to the server;
  9. > the full URL can still be stored in your browser history or wherever you share it.
  10. [![PyPI version](https://img.shields.io/pypi/v/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
  11. [![Conda-forge](https://img.shields.io/conda/v/conda-forge/datamodel-code-generator)](https://anaconda.org/conda-forge/datamodel-code-generator)
  12. [![Downloads](https://api.pepy.tech/badge/datamodel-code-generator/month)](https://pepy.tech/projects/datamodel-code-generator)
  13. [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/datamodel-code-generator)](https://pypi.python.org/pypi/datamodel-code-generator)
  14. [![codecov](https://codecov.io/gh/datamodel-code-generator/datamodel-code-generator/graph/badge.svg?token=plzSSFb9Li)](https://codecov.io/gh/datamodel-code-generator/datamodel-code-generator)
  15. ![license](https://img.shields.io/github/license/datamodel-code-generator/datamodel-code-generator.svg)
  16. [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)
  17. ## ✨ What it does
  18. <!-- Source of truth: docs/assets/diagrams/hero.mmd — regenerate with `tox run -e diagrams` -->
  19. <p align="center">
  20. <picture>
  21. <source media="(prefers-color-scheme: dark)" srcset="docs/assets/diagrams/hero-dark.svg">
  22. <img alt="Schema files, raw data, and existing Python models flow through datamodel-code-generator into Python model output types and experimental HTTPX2 client and FastAPI server packages" src="docs/assets/diagrams/hero-light.svg" width="760">
  23. </picture>
  24. </p>
  25. Pick any one of the supported inputs and pick the Python model style you want as output.
  26. `--input-model path/to/file.py:ClassName` can even retarget an existing Pydantic, dataclass, or TypedDict class defined
  27. in another Python file to a different output type.
  28. - 📄 Converts **OpenAPI 3**, **AsyncAPI**, **JSON Schema**, **Apache Avro**, **XML Schema**, **Protocol Buffers/gRPC**, **GraphQL**, **MCP tool schemas**, and raw data (JSON/YAML/CSV) into Python models
  29. - 🐍 Generates from **existing Python types** (Pydantic, dataclass, TypedDict) via `--input-model`
  30. - 🎯 Generates **Pydantic v2**, **Pydantic v2 dataclass**, **dataclasses**, **TypedDict**, or **msgspec** output
  31. - 🌐 Generates a typed **HTTPX2 client** (`--generate-client httpx2`, from OpenAPI and AsyncAPI) or a **FastAPI server** (`--generate-server fastapi`, from OpenAPI) together with the models (experimental)
  32. - 🔗 Handles complex schemas: `$ref`, `allOf`, `oneOf`, `anyOf`, enums, and nested types
  33. - ✅ Produces type-safe, validated code ready for your IDE and type checker
  34. ---
  35. ## 📦 Installation
  36. Recommended for standalone CLI use:
  37. ```bash
  38. uv tool install datamodel-code-generator
  39. ```
  40. Conda users can install from conda-forge:
  41. ```bash
  42. conda install -c conda-forge datamodel-code-generator
  43. ```
  44. For projects that should pin the generator version, add it as a development dependency instead:
  45. ```bash
  46. uv add --dev datamodel-code-generator
  47. ```
  48. > [!NOTE]
  49. > Community-maintained distribution packages are also available from
  50. > [Debian](https://packages.debian.org/search?keywords=datamodel-codegen&searchon=names&suite=all&section=all),
  51. > [Ubuntu](https://packages.ubuntu.com/search?keywords=datamodel-codegen&searchon=names&suite=all&section=all),
  52. > [nixpkgs](https://search.nixos.org/packages?query=datamodel-code-generator), and
  53. > [openSUSE Tumbleweed](https://software.opensuse.org/package/python-datamodel-code-generator).
  54. > Availability and versions vary by distribution.
  55. <details>
  56. <summary>Other installation methods</summary>
  57. **pip:**
  58. ```bash
  59. pip install datamodel-code-generator
  60. ```
  61. **uv (run without adding to project):**
  62. ```bash
  63. uv run --with datamodel-code-generator datamodel-codegen --help
  64. ```
  65. **With stable HTTP support** (for resolving remote `$ref`):
  66. ```bash
  67. pip install 'datamodel-code-generator[http]'
  68. ```
  69. The `http` extra is supported and is not deprecated. To require the experimental
  70. HTTPX2 backend instead, install `datamodel-code-generator[httpx2]` and pass
  71. `--http-backend httpx2`. The experimental extra is not included in
  72. `datamodel-code-generator[all]`. See
  73. [HTTP backend selection](https://datamodel-code-generator.koxudaxi.dev/faq/#http-backend-selection)
  74. for automatic and explicit selection behavior.
  75. **With GraphQL support:**
  76. ```bash
  77. pip install 'datamodel-code-generator[graphql]'
  78. ```
  79. **With Protocol Buffers support:**
  80. ```bash
  81. pip install 'datamodel-code-generator[protobuf]'
  82. ```
  83. **Docker:**
  84. ```bash
  85. docker pull koxudaxi/datamodel-code-generator
  86. ```
  87. Published Docker images run as a non-root `appuser`. When writing generated files
  88. to a bind-mounted directory, make sure the directory is writable by the container
  89. user or pass an explicit Docker user, for example `--user "$(id -u):$(id -g)"`.
  90. </details>
  91. ---
  92. ## 🏃 Quick Start
  93. <!-- BEGIN AUTO-GENERATED PRESET QUICK START -->
  94. **Command**
  95. ```bash
  96. datamodel-codegen \
  97. --input schema.json \
  98. --input-file-type jsonschema \
  99. --output-model-type pydantic_v2.BaseModel \
  100. --preset standard-py312-20261118 \
  101. --output model.py
  102. ```
  103. This quick start uses `standard-py312-20261118` as the modern Python 3.12 baseline.
  104. Preset names include the target Python version: `py312` means Python 3.12.
  105. See [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/) for all options. See [Presets](https://datamodel-code-generator.koxudaxi.dev/presets/),
  106. [`--preset`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/#preset), [`--input-file-type`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/#input-file-type), and
  107. [`--output-model-type`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/model-customization/#output-model-type) for this command.
  108. For more schema-aware output that preserves schema-authored names, reuses models, and embeds generated
  109. documentation, use [`practical-py312-20261118`](https://datamodel-code-generator.koxudaxi.dev/presets/#practical-py312-20261118).
  110. **Not sure which options fit your schema?** Add `--recommend-options` to the command above (experimental). It
  111. analyses the schema and prints the options to add on top of the latest preset with the reason for each, and a ready
  112. command and `pyproject.toml` block. See
  113. [Option recommendations](https://datamodel-code-generator.koxudaxi.dev/recommend-options/).
  114. <details>
  115. <summary>Input (<code>schema.json</code>)</summary>
  116. ```json
  117. {
  118. "$schema": "http://json-schema.org/draft-07/schema#",
  119. "title": "Pet",
  120. "type": "object",
  121. "required": ["name"],
  122. "properties": {
  123. "name": {
  124. "type": "string",
  125. "description": "The pet's name"
  126. },
  127. "species": {
  128. "type": "string",
  129. "enum": ["dog", "cat", "bird", "fish"],
  130. "default": "dog"
  131. },
  132. "age": {
  133. "type": "integer",
  134. "minimum": 0,
  135. "description": "Age in years"
  136. },
  137. "vaccinated": {
  138. "type": "boolean",
  139. "default": false
  140. }
  141. }
  142. }
  143. ```
  144. </details>
  145. **Output (`model.py`)**
  146. <!-- fmt: off -->
  147. ```python
  148. # generated by datamodel-codegen:
  149. # filename: schema.json
  150. from __future__ import annotations
  151. from enum import StrEnum
  152. from typing import Annotated
  153. from pydantic import BaseModel, ConfigDict, Field
  154. class Species(StrEnum):
  155. dog = 'dog'
  156. cat = 'cat'
  157. bird = 'bird'
  158. fish = 'fish'
  159. class Pet(BaseModel):
  160. model_config = ConfigDict(
  161. populate_by_name=True,
  162. )
  163. name: Annotated[str, Field(description="The pet's name")]
  164. species: Species = Species.dog
  165. age: Annotated[int | None, Field(description='Age in years', ge=0)] = None
  166. vaccinated: bool = False
  167. ```
  168. <!-- fmt: on -->
  169. ### Choose a formatter
  170. Choose a formatter to match your project and generation priorities:
  171. - **Projects using Ruff:** use `--formatters ruff-check ruff-format` to keep generated code consistent with the
  172. project's formatting and lint policy. Install it with `pip install 'datamodel-code-generator[ruff]'`.
  173. - **No Ruff, Black, or isort, or generation speed is the priority:** use `--formatters builtin` to avoid running
  174. external formatters on standard generated model modules.
  175. - **Projects using Black/isort:** keep `--formatters black isort` to preserve the project's formatting and existing
  176. generated output.
  177. The current default remains Black/isort, which are still required dependencies. Omitting formatter options continues
  178. normal generation. The future builtin default is intended to reduce required installation dependencies and version
  179. constraints; Ruff will still be recommended for projects that use Ruff. Formatters are never selected automatically
  180. based on installed packages or Ruff configuration. The new `[black]` and `[isort]` extras prepare for later
  181. optional installation; their ranges and environment markers match the current required dependencies. The
  182. `[jinja2]` (custom templates), `[genson]` (JSON, YAML, CSV and dict data input) and `[argcomplete]` (shell
  183. completion) extras do the same for those dependencies.
  184. Selecting only a formatter preserves your other generation settings; a preset also supplies model-generation options.
  185. Explicit formatter selection does not pin formatter versions or guarantee byte-for-byte output stability.
  186. Custom templates can emit Python outside the standard generated model patterns covered by `builtin`, so
  187. custom-template output is not exhaustively validated. If `--formatters builtin` produces invalid or poorly formatted
  188. output with a custom template, please open an issue with a small reproducer. See
  189. [Formatter Behavior](https://datamodel-code-generator.koxudaxi.dev/formatter-behavior/) for details.
  190. See [Performance Benchmarks](https://datamodel-code-generator.koxudaxi.dev/performance-benchmarks/) for release benchmark data and interactive charts.
  191. <!-- END AUTO-GENERATED PRESET QUICK START -->
  192. ---
  193. ## 🌐 Generate a FastAPI server or an HTTP client (experimental)
  194. > [!WARNING]
  195. > Server and client generation are experimental since 0.84.0: their options and generated packages may change.
  196. > See [Experimental Features](https://datamodel-code-generator.koxudaxi.dev/experimental/).
  197. From one OpenAPI document, `--generate-server fastapi` writes a FastAPI server package and `--generate-client httpx2`
  198. an HTTPX2 client package, in the same run as the models. The models stay the runtime contract: routes and client
  199. methods take and return the generated models, so the server and the client parse and produce the same classes you already
  200. use. Every generated file is regenerated on each run; keep your own code outside the generated packages.
  201. The commands put everything in one application package, `app`: the generated `app/models.py`, `app/server/`, and
  202. `app/client/`, and your `app/services/`, so no generic top-level name such as `models` or `server` is taken.
  203. This example is the [FastAPI server tutorial](https://datamodel-code-generator.koxudaxi.dev/fastapi-server/#quick-start), and the tests of this project run it as shown.
  204. <!-- BEGIN AUTO-GENERATED DOC EXAMPLE: readme.server-client.openapi -->
  205. <details>
  206. <summary>Input (<code>openapi.yaml</code>)</summary>
  207. <!-- fmt: off -->
  208. ```yaml
  209. openapi: 3.1.0
  210. info:
  211. title: Pets
  212. version: "1.0"
  213. servers:
  214. - url: http://localhost:8000
  215. paths:
  216. /pets:
  217. get:
  218. operationId: listPets
  219. tags: [pets]
  220. parameters:
  221. - name: limit
  222. in: query
  223. schema: {type: integer, minimum: 1, maximum: 100, default: 20}
  224. responses:
  225. "200":
  226. description: The pets.
  227. content:
  228. application/json:
  229. schema: {$ref: "#/components/schemas/Pets"}
  230. post:
  231. operationId: createPet
  232. tags: [pets]
  233. requestBody:
  234. required: true
  235. content:
  236. application/json:
  237. schema: {$ref: "#/components/schemas/NewPet"}
  238. responses:
  239. "201":
  240. description: Created.
  241. content:
  242. application/json:
  243. schema: {$ref: "#/components/schemas/Pet"}
  244. /pets/{petId}:
  245. get:
  246. operationId: getPet
  247. tags: [pets]
  248. parameters:
  249. - name: petId
  250. in: path
  251. required: true
  252. schema: {type: integer}
  253. responses:
  254. "200":
  255. description: The pet.
  256. content:
  257. application/json:
  258. schema: {$ref: "#/components/schemas/Pet"}
  259. "404":
  260. description: No pet has this ID.
  261. content:
  262. application/json:
  263. schema: {$ref: "#/components/schemas/Error"}
  264. components:
  265. schemas:
  266. NewPet:
  267. type: object
  268. required: [name]
  269. properties:
  270. name: {type: string}
  271. tag: {type: string}
  272. Pet:
  273. type: object
  274. required: [id, name]
  275. properties:
  276. id: {type: integer}
  277. name: {type: string}
  278. tag: {type: string}
  279. Pets:
  280. type: array
  281. items: {$ref: "#/components/schemas/Pet"}
  282. Error:
  283. type: object
  284. required: [message]
  285. properties:
  286. message: {type: string}
  287. ```
  288. <!-- fmt: on -->
  289. </details>
  290. <!-- END AUTO-GENERATED DOC EXAMPLE: readme.server-client.openapi -->
  291. **Commands**
  292. <!-- BEGIN AUTO-GENERATED DOC EXAMPLE: readme.server-client.commands -->
  293. <!-- fmt: off -->
  294. ```bash
  295. # The application package app, which the generated packages go into
  296. mkdir -p app && touch app/__init__.py
  297. # FastAPI server package in app/server/
  298. datamodel-codegen \
  299. --input openapi.yaml \
  300. --input-file-type openapi \
  301. --openapi-scopes schemas api \
  302. --output-model-type pydantic_v2.BaseModel \
  303. --preset standard-py312-20261118 \
  304. --output app/models.py \
  305. --generate-server fastapi \
  306. --server-output app/server \
  307. --server-package app.server \
  308. --server-model-package app.models
  309. # HTTPX2 client package in app/client/
  310. datamodel-codegen \
  311. --input openapi.yaml \
  312. --input-file-type openapi \
  313. --openapi-scopes schemas api \
  314. --output-model-type pydantic_v2.BaseModel \
  315. --preset standard-py312-20261118 \
  316. --output app/models.py \
  317. --generate-client httpx2 \
  318. --client-output app/client \
  319. --client-package app.client \
  320. --client-model-package app.models
  321. ```
  322. <!-- fmt: on -->
  323. <!-- END AUTO-GENERATED DOC EXAMPLE: readme.server-client.commands -->
  324. `--openapi-scopes` must include `api`, and both need Python 3.11 or later, to run and as the target version (the preset
  325. sets 3.12); left unset, the run sets them and says how. Each run ends by printing the runtime dependencies of its
  326. package to stderr:
  327. <!-- BEGIN AUTO-GENERATED DOC EXAMPLE: readme.server-client.notice -->
  328. <!-- fmt: off -->
  329. ```text
  330. Add the runtime dependencies of app.server to your project:
  331. uv add "fastapi>=0.141.1" "pydantic>=2.14.0" "typing-extensions>=4.16"
  332. Next steps: implement the stubs in app/services/pets.py, then run the server:
  333. uv add uvicorn && uv run uvicorn app.server.main:app --reload
  334. or: uv add "fastapi[standard]" && uv run fastapi dev --entrypoint app.server.main:app
  335. See app/server/README.md.
  336. Add the runtime dependencies of app.client to your project:
  337. uv add "httpx2>=2.13.0" "typing-extensions>=4.16" "pydantic>=2.14.0"
  338. Next steps: call the API with the client:
  339. from app.client import Client
  340. with Client(base_url=...) as client:
  341. client.pets.list_pets(...)
  342. See app/client/README.md.
  343. ```
  344. <!-- fmt: on -->
  345. <!-- END AUTO-GENERATED DOC EXAMPLE: readme.server-client.notice -->
  346. **Generated files (trimmed)**
  347. <!-- BEGIN AUTO-GENERATED DOC EXAMPLE: readme.server-client.tree -->
  348. <!-- fmt: off -->
  349. ```text
  350. app/
  351. ├── __init__.py
  352. ├── models.py
  353. ├── server/
  354. ├── services/
  355. └── client/
  356. ```
  357. <!-- fmt: on -->
  358. <!-- END AUTO-GENERATED DOC EXAMPLE: readme.server-client.tree -->
  359. **Implement the server** in `app/services/pets.py`, which generation wrote once with stubs, by replacing the stubs of the
  360. `Pets` class that subclasses the generated service Protocol; type checkers report a missing method or a mismatched
  361. signature:
  362. <!-- BEGIN AUTO-GENERATED DOC EXAMPLE: readme.server-client.app -->
  363. <!-- fmt: off -->
  364. ```python
  365. from app import models
  366. from app.server import HTTPResult
  367. from app.server.services import PetsService
  368. class Pets(PetsService):
  369. def __init__(self) -> None:
  370. self.pets: dict[int, models.Pet] = {}
  371. def list_pets(self, *, limit: int) -> models.Pets:
  372. return models.Pets(list(self.pets.values())[:limit])
  373. def create_pet(self, *, body: models.NewPet) -> models.Pet:
  374. pet = models.Pet(id=len(self.pets) + 1, name=body.name, tag=body.tag)
  375. self.pets[pet.id] = pet
  376. return pet
  377. def get_pet(self, *, pet_id: int) -> models.Pet | HTTPResult[models.Error]:
  378. if (pet := self.pets.get(pet_id)) is None:
  379. return HTTPResult(404, models.Error(message=f"Pet {pet_id} not found"))
  380. return pet
  381. ```
  382. <!-- fmt: on -->
  383. <!-- END AUTO-GENERATED DOC EXAMPLE: readme.server-client.app -->
  384. ```bash
  385. uv add uvicorn
  386. uv run uvicorn app.server.main:app
  387. ```
  388. **Call it with the client** in `call.py`, which sends to the document's server URL by default:
  389. <!-- BEGIN AUTO-GENERATED DOC EXAMPLE: readme.server-client.call -->
  390. <!-- fmt: off -->
  391. ```python
  392. from app.client import Client
  393. from app.client.errors import NotFoundError
  394. from app.models import NewPet
  395. with Client() as client:
  396. pet = client.pets.create_pet(body=NewPet(name="Mimi", tag="cat"))
  397. print(pet)
  398. for listed in client.pets.list_pets(limit=10).root:
  399. print(listed.name)
  400. try:
  401. client.pets.get_pet(pet_id=99)
  402. except NotFoundError as error:
  403. print(error.status_code, error.body)
  404. ```
  405. <!-- fmt: on -->
  406. <!-- END AUTO-GENERATED DOC EXAMPLE: readme.server-client.call -->
  407. It prints:
  408. <!-- BEGIN AUTO-GENERATED DOC EXAMPLE: readme.server-client.output -->
  409. <!-- fmt: off -->
  410. ```text
  411. id=1 name='Mimi' tag='cat'
  412. Mimi
  413. 404 message='Pet 99 not found'
  414. ```
  415. <!-- fmt: on -->
  416. <!-- END AUTO-GENERATED DOC EXAMPLE: readme.server-client.output -->
  417. `AsyncClient` offers the same methods as coroutines. See [FastAPI Server Generation](https://datamodel-code-generator.koxudaxi.dev/fastapi-server/) and [Python Client Generation](https://datamodel-code-generator.koxudaxi.dev/python-client/) for every option, the
  418. `pyproject.toml` settings, authentication, and the Python API.
  419. ---
  420. ## 📖 Documentation
  421. **👉 [Read the full documentation →](https://datamodel-code-generator.koxudaxi.dev/)**
  422. - 🧰 [Presets](https://datamodel-code-generator.koxudaxi.dev/presets/) - Recommended option bundles for modern output
  423. - 🚀 [Getting Started](https://datamodel-code-generator.koxudaxi.dev/getting-started/) - Installation and first model
  424. - 🖥️ [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/) - All command-line options
  425. - 🌐 [FastAPI Server Generation](https://datamodel-code-generator.koxudaxi.dev/fastapi-server/) - Experimental FastAPI server package from OpenAPI
  426. - 📡 [Python Client Generation](https://datamodel-code-generator.koxudaxi.dev/python-client/) - Experimental HTTPX2 client package from OpenAPI
  427. - 🧪 [Playground](https://datamodel-code-generator.koxudaxi.dev/playground/) - Try generation in your browser
  428. - ⚙️ [pyproject.toml](https://datamodel-code-generator.koxudaxi.dev/pyproject_toml/) - Configuration file
  429. - 🔄 [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/) - GitHub Actions, pre-commit hooks
  430. - ✅ [Conformance Dashboard](https://datamodel-code-generator.koxudaxi.dev/conformance/) - External corpus coverage signals
  431. - 📈 [Performance Benchmarks](https://datamodel-code-generator.koxudaxi.dev/performance-benchmarks/) - Release benchmark tables and interactive charts
  432. - 🧭 [Architecture](https://datamodel-code-generator.koxudaxi.dev/architecture/) - Generation pipeline and synchronized component inventory
  433. - 🚀 [One-liner Usage](https://datamodel-code-generator.koxudaxi.dev/oneliner/) - uvx, pipx, clipboard integration
  434. - ❓ [FAQ](https://datamodel-code-generator.koxudaxi.dev/faq/) - Common questions
  435. ---
  436. ## 📥 Supported Input
  437. <!-- BEGIN AUTO-GENERATED README SUPPORTED INPUT -->
  438. - OpenAPI 3 (YAML/JSON)
  439. - AsyncAPI (YAML/JSON)
  440. - JSON Schema
  441. - MCP tool schemas
  442. - XML Schema (XSD)
  443. - Protocol Buffers / gRPC (`.proto`)
  444. - Apache Avro schema (AVSC)
  445. - JSON data
  446. - YAML data
  447. - Python dictionary
  448. - CSV data
  449. - GraphQL schema
  450. - Python types (Pydantic, dataclass, TypedDict) via `--input-model`
  451. <!-- END AUTO-GENERATED README SUPPORTED INPUT -->
  452. ## 📤 Supported Output
  453. <!-- BEGIN AUTO-GENERATED README SUPPORTED OUTPUT -->
  454. - [pydantic v2](https://docs.pydantic.dev/) BaseModel
  455. - [pydantic v2](https://docs.pydantic.dev/) dataclass
  456. - [dataclasses](https://docs.python.org/3/library/dataclasses.html)
  457. - [TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict)
  458. - [msgspec](https://github.com/jcrist/msgspec) Struct
  459. <!-- END AUTO-GENERATED README SUPPORTED OUTPUT -->
  460. ## ✅ Conformance Signals
  461. CI exercises datamodel-code-generator against pinned external corpora for XML Schema, JSON Schema, AsyncAPI, Apache
  462. Avro, and Protocol Buffers. See the [Conformance Dashboard](https://datamodel-code-generator.koxudaxi.dev/conformance/)
  463. for the generated summary of runner scripts, tox environments, CI jobs, expected corpus counts, and upstream sources.
  464. ---
  465. ## 🍳 Common Recipes
  466. <!-- BEGIN AUTO-GENERATED CLI RECIPE QUICK STARTS -->
  467. ### CLI option quick starts
  468. Use these starting points when combining options; each option links to the generated CLI reference for details and examples.
  469. - **Generate a local schema file:** Pin the input type and destination when the source extension is ambiguous or generated output needs a stable path. Options: [`--input`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/#input), [`--input-file-type`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/#input-file-type), [`--output`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/#output).
  470. - **Target Pydantic v2 on modern Python:** Set the output model family and Python/Pydantic compatibility targets together. Options: [`--output-model-type`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/model-customization/#output-model-type), [`--target-python-version`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/model-customization/#target-python-version), [`--target-pydantic-version`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/model-customization/#target-pydantic-version).
  471. - **Use modern Python annotations:** Target a recent Python version and prefer built-in collection and union syntax in generated types. Options: [`--target-python-version`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/model-customization/#target-python-version), [`--use-union-operator`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/typing-customization/#use-union-operator), [`--use-standard-collections`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/typing-customization/#use-standard-collections).
  472. - **Normalize incoming field names:** Convert source names to Python identifiers while preserving explicit alias data for runtime IO. Options: [`--snake-case-field`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/field-customization/#snake-case-field), [`--original-field-name-delimiter`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/field-customization/#original-field-name-delimiter), [`--aliases`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/field-customization/#aliases).
  473. - **Generate operation-focused models:** Limit OpenAPI output to operation shapes and name models from operation IDs and status codes. Options: [`--openapi-scopes`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/openapi-only-options/#openapi-scopes), [`--use-operation-id-as-name`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/openapi-only-options/#use-operation-id-as-name), [`--use-status-code-in-response-name`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/openapi-only-options/#use-status-code-in-response-name).
  474. - **Resolve remote references deliberately:** Enable remote `$ref` loading and configure request metadata, timeouts, or local ref roots. Options: [`--allow-remote-refs`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/general-options/#allow-remote-refs), [`--http-headers`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/general-options/#http-headers), [`--http-timeout`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/general-options/#http-timeout), [`--http-local-ref-path`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/general-options/#http-local-ref-path).
  475. See the [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/) for the full option list and category-specific recipes.
  476. <!-- END AUTO-GENERATED CLI RECIPE QUICK STARTS -->
  477. ### 🤖 Get CLI Help from LLMs
  478. Generate a prompt to ask LLMs about CLI options:
  479. ```bash
  480. datamodel-codegen --generate-prompt "Best options for Pydantic v2?" | claude -p
  481. ```
  482. See [LLM Integration](https://datamodel-code-generator.koxudaxi.dev/llm-integration/) for more examples.
  483. ### 🌐 Generate from URL
  484. ```bash
  485. pip install 'datamodel-code-generator[http]'
  486. datamodel-codegen --url https://example.com/api/openapi.yaml --output model.py
  487. ```
  488. The `http` extra is the stable, non-deprecated backend. For the experimental
  489. HTTPX2 alternative, pass `--http-backend httpx2`; see
  490. [HTTP backend selection](https://datamodel-code-generator.koxudaxi.dev/faq/#http-backend-selection).
  491. ### ⚙️ Use with pyproject.toml
  492. ```toml
  493. [tool.datamodel-codegen]
  494. input = "schema.yaml"
  495. output = "src/models.py"
  496. output-model-type = "pydantic_v2.BaseModel"
  497. ```
  498. Then simply run:
  499. ```bash
  500. datamodel-codegen
  501. ```
  502. See [pyproject.toml Configuration](https://datamodel-code-generator.koxudaxi.dev/pyproject_toml/) for more options.
  503. ### 🔄 CI/CD Integration
  504. Validate generated models in your CI pipeline:
  505. ```yaml
  506. # Replace vX.Y.Z with a released action version.
  507. - uses: datamodel-code-generator/datamodel-code-generator@vX.Y.Z
  508. with:
  509. input: schemas/api.yaml
  510. output: src/models/api.py
  511. ```
  512. See [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/) for more options.
  513. ---
  514. ## Coding agent skill
  515. This repository includes an experimental Agent Skill that teaches compatible coding agents to run `datamodel-codegen` when generating Python models 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.
  516. See [Coding Agent Skill](docs/coding-agent-skill.md) for detailed guidance and troubleshooting.
  517. Install the bundled skill directly from the CLI:
  518. ```bash
  519. # Codex, project-local
  520. datamodel-codegen --install-skill codex
  521. # Claude Code, project-local
  522. datamodel-codegen --install-skill claude-code
  523. ```
  524. For a personal install, add `--skill-scope user`. Existing skills are preserved
  525. unless you explicitly add `--overwrite-skill`.
  526. To install without the Python package, for example in Claude Code, run `claude plugin marketplace add datamodel-code-generator/datamodel-code-generator` and then `claude plugin install datamodel-code-generator@datamodel-code-generator`. See [Install from the repository](docs/coding-agent-skill.md#install-from-the-repository) for other agents.
  527. Check your agent's current documentation for exact search paths.
  528. ---
  529. ## 💖 Sponsors
  530. <table>
  531. <tr>
  532. <td valign="top" align="center">
  533. <a href="https://github.com/openai">
  534. <img src="https://avatars.githubusercontent.com/u/14957082?s=200&v=4" alt="OpenAI Logo" style="width: 100px;">
  535. <p>OpenAI</p>
  536. </a>
  537. </td>
  538. </tr>
  539. </table>
  540. ---
  541. ## 🏢 Projects that use datamodel-code-generator
  542. These public examples are grouped by how each project uses datamodel-code-generator.
  543. ### Code generation and runtime integration
  544. - [openai/codex](https://github.com/openai/codex) - *[Generate public Python SDK types from protocol schemas](https://github.com/openai/codex/blob/205d37a20f742b0bf8e191622bd07c43f567ea49/sdk/python/scripts/update_sdk_artifacts.py#L558-L590)*
  545. - [modelcontextprotocol/python-sdk](https://github.com/modelcontextprotocol/python-sdk) - *[Generate MCP protocol models from vendored JSON Schemas](https://github.com/modelcontextprotocol/python-sdk/blob/main/scripts/gen_surface_types.py)*
  546. - [typesafe-ai/typesafe-sdk-python](https://github.com/typesafe-ai/typesafe-sdk-python) - *[Generate official Jev Python SDK models from the TypeSafe OpenAPI schema](https://github.com/typesafe-ai/typesafe-sdk-python/blob/0ffd094c72ed9445223060b24ffd7a56aa781fb4/src/typesafe_sdk/_schemas/models.py#L1-L2)*
  547. - [modular/modular](https://github.com/modular/modular) - *[Generate MAX Serve KServe schemas from OpenAPI with datamodel-codegen](https://github.com/modular/modular/blob/0735fa29762a5c53d65a0456d0b53eac1472180f/max/python/max/serve/schemas/README.md#L20-L33)*
  548. - [apache/airflow](https://github.com/apache/airflow) - *[Generate OpenAPI datamodels for airflow-ctl and task-sdk via pyproject codegen config](https://github.com/apache/airflow/blob/f1ac27af8b53e7d3ca7ff710c4f4413599bd1535/airflow-ctl/pyproject.toml#L148-L172)*
  549. - [PostHog/posthog](https://github.com/PostHog/posthog) - *[Generate Pydantic models from JSON Schema](https://github.com/PostHog/posthog/blob/master/bin/build-schema-python.sh#L5-L14)*
  550. - [airbytehq/airbyte](https://github.com/airbytehq/airbyte) - *[Generate Python, Java/Kotlin, and Typescript protocol models](https://github.com/airbytehq/airbyte-protocol/tree/main/protocol-models/bin)*
  551. - [open-metadata/OpenMetadata](https://github.com/open-metadata/OpenMetadata) - *[datamodel_generation.py](https://github.com/open-metadata/OpenMetadata/blob/main/scripts/datamodel_generation.py)*
  552. - [topoteretes/cognee](https://github.com/topoteretes/cognee) - *[Runtime generation of graph data models from JSON Schema](https://github.com/topoteretes/cognee/blob/main/cognee/shared/graph_model_utils.py)*
  553. - [e2b-dev/E2B](https://github.com/e2b-dev/E2B) - *[Generate MCP server TypedDict models via Makefile](https://github.com/e2b-dev/E2B/blob/main/packages/python-sdk/Makefile)*
  554. - [DataDog/integrations-core](https://github.com/DataDog/integrations-core) - *[Config models](https://github.com/DataDog/integrations-core/blob/master/docs/developer/meta/config-models.md)*
  555. - [open-telemetry/opentelemetry-python](https://github.com/open-telemetry/opentelemetry-python) - *[Generate SDK configuration dataclasses from JSON Schema](https://github.com/open-telemetry/opentelemetry-python/blob/main/tox.ini)*
  556. ### Development, testing, and evaluation
  557. - [browser-use/browser-use](https://github.com/browser-use/browser-use) - *[Evaluation dependency](https://github.com/browser-use/browser-use/blob/de14b9aa31d167696a7ea7185d71876dbd7e6c94/pyproject.toml#L74-L79)*
  558. - [vllm-project/vllm](https://github.com/vllm-project/vllm) - *[Test dependency for MiniCPM3 tests](https://github.com/vllm-project/vllm/blob/46f01a50acd6862806ed67b88176c96c2b161142/requirements/test/cuda.in#L40)*
  559. - [stanfordnlp/dspy](https://github.com/stanfordnlp/dspy) - *[Generate Pydantic models from JSON Schema for reliability tests](https://github.com/stanfordnlp/dspy/blob/main/tests/reliability/generate/utils.py)*
  560. [See all dependents →](https://github.com/datamodel-code-generator/datamodel-code-generator/network/dependents)
  561. ---
  562. ## 🔗 Related Projects
  563. - **[fastapi-code-generator](https://github.com/koxudaxi/fastapi-code-generator)** - Generate FastAPI app from OpenAPI. To generate a FastAPI server with this project, see `--generate-server fastapi` and the [migration guide](https://datamodel-code-generator.koxudaxi.dev/fastapi-code-generator-migration/)
  564. - **[pydantic-pycharm-plugin](https://github.com/koxudaxi/pydantic-pycharm-plugin)** - PyCharm plugin for Pydantic
  565. ---
  566. ## 🤝 Contributing
  567. See [Development & Contributing](https://datamodel-code-generator.koxudaxi.dev/development-contributing/) for how to get started!
  568. ---
  569. ## 👥 Maintainers
  570. - [Koudai Aono](https://koxudaxi.dev/?utm_source=github_readme&utm_medium=maintainer_section&utm_campaign=open_to_work) ([@koxudaxi](https://github.com/koxudaxi)) - Lead maintainer
  571. - [Bernát Gábor](https://github.com/gaborbernat) ([@gaborbernat](https://github.com/gaborbernat)) - Maintainer
  572. - [Antonio Spadaro](https://github.com/ilovelinux) ([@ilovelinux](https://github.com/ilovelinux)) - Maintainer
  573. ---
  574. ## 📄 License
  575. MIT License - see [LICENSE](LICENSE) for details.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.