Generate Python models from OpenAPI, AsyncAPI, JSON Schema, GraphQL and more, plus typed HTTP and WebSocket clients and FastAPI servers (experimental), with datamodel-codegen.
[!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.
✨ What it does
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.
📄 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
🐍 Generates from existing Python types (Pydantic, dataclass, TypedDict) via --input-model
🌐 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)
🤖 Turns the generated client into tools an agent searches, reads the schemas of, and calls, with an MCP server over them (--client-tools functions or mcp, experimental)
📝 Writes the recommended options into pyproject.toml (--recommend-options --write-pyproject-config, experimental)
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.