datamodel-code-generator  by koxudaxi

Python data model generation from schemas

Created 6 years ago
3,694 stars

Top 13.0% on SourcePulse

GitHubView on GitHub
Project Summary

Generates Python data models from schema definitions and raw data, targeting developers who need to integrate external data sources or define complex data structures. It significantly reduces boilerplate code by automatically creating type-safe, validated Python classes from formats like OpenAPI, JSON Schema, GraphQL, and JSON/YAML/CSV, enhancing developer productivity and code reliability.

How It Works

The core approach involves parsing schema definitions (OpenAPI, JSON Schema, GraphQL) or raw data (JSON, YAML, CSV) and transforming them into Python type-hinted classes. It leverages robust parsing to handle complex schema constructs like $ref, allOf, oneOf, anyOf, and nested types, ensuring accurate and type-safe code generation. This approach streamlines data handling and validation in Python applications.

Quick Start & Requirements

Primary installation via uv tool install datamodel-code-generator or pip install datamodel-code-generator. Optional extras include [http] for remote $ref resolution and [graphql] for GraphQL schema support. Docker image koxudaxi/datamodel-code-generator is also available. Official documentation is hosted at datamodel-code-generator.koxudaxi.dev.

Highlighted Details

  • Broad input support: OpenAPI 3, JSON Schema, GraphQL, raw JSON/YAML/CSV, and existing Python types.
  • Flexible output options: Pydantic v1/v2, dataclasses, TypedDict, and msgspec.
  • Advanced schema feature handling: $ref, allOf, oneOf, anyOf, enums, and nested types.
  • Integrated LLM CLI help and direct URL generation capabilities.
  • CI/CD integration examples provided for automated workflows.

Maintenance & Community

The project is sponsored by Astral and has significant adoption, with notable dependents including PostHog, Airbyte, and Apache Iceberg. Related projects like fastapi-code-generator indicate ecosystem integration. Community contribution details are available in the "Development & Contributing" section.

Licensing & Compatibility

MIT License. This permissive license allows for commercial use and integration into closed-source projects without significant restrictions.

Limitations & Caveats

No specific limitations, alpha status, or known bugs are detailed in the provided README. The project appears stable and mature with extensive feature support.

Health Check
Last Commit

1 day ago

Responsiveness

Inactive

Pull Requests (30d)
273
Issues (30d)
44
Star History
74 stars in the last 30 days

Explore Similar Projects

Starred by Elie Bursztein Elie Bursztein(Cybersecurity Lead at Google DeepMind), Michael Chiang Michael Chiang(Cofounder of Ollama), and
2 more.

enrichmcp by featureform

0.2%
640
ORM for AI agents
Created 9 months ago
Updated 1 week ago
Feedback? Help us improve.