{"library":"datamodel-code-generator","title":"Datamodel Code Generator","description":"Datamodel Code Generator is a Python library and command-line utility for generating data models from various structured input formats like OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV). It supports outputting models for Pydantic v2, dataclasses, TypedDict, and msgspec. Currently at version 0.56.0, it maintains an active development pace with frequent releases addressing new features and breaking changes, particularly around Pydantic compatibility.","status":"active","version":"0.56.0","language":"en","source_language":"en","source_url":"https://github.com/koxudaxi/datamodel-code-generator","tags":["code-generation","pydantic","json-schema","openapi","graphql","dataclasses","typeddict"],"install":[{"cmd":"pip install datamodel-code-generator","lang":"bash","label":"Default Install"},{"cmd":"pip install 'datamodel-code-generator[http]'","lang":"bash","label":"With HTTP support (for remote $ref)"},{"cmd":"pip install 'datamodel-code-generator[graphql]'","lang":"bash","label":"With GraphQL support"}],"dependencies":[{"reason":"Required runtime dependency for generated models, Pydantic v2+ is mandatory since 0.55.0.","package":"pydantic","optional":false}],"imports":[{"symbol":"generate","correct":"from datamodel_code_generator import generate"},{"symbol":"GenerateConfig","correct":"from datamodel_code_generator import GenerateConfig"},{"symbol":"InputFileType","correct":"from datamodel_code_generator import InputFileType"},{"symbol":"DataModelType","correct":"from datamodel_code_generator import DataModelType"}],"quickstart":{"code":"from datamodel_code_generator import InputFileType, generate, GenerateConfig, DataModelType\n\njson_schema: str = \"\"\"{ \n  \"type\": \"object\",\n  \"properties\": {\n    \"number\": {\"type\": \"number\"},\n    \"street_name\": {\"type\": \"string\"},\n    \"street_type\": {\"type\": \"string\", \"enum\": [\"Street\", \"Avenue\", \"Boulevard\"]}\n  }\n}\"\"\"\n\nconfig = GenerateConfig(\n    input_file_type=InputFileType.JsonSchema,\n    input_filename=\"example.json\",\n    output_model_type=DataModelType.PydanticV2BaseModel,\n)\nresult = generate(json_schema, config=config)\nprint(result)","lang":"python","description":"This example demonstrates how to programmatically generate Pydantic v2 models from a JSON Schema string. The `generate` function takes the schema content and a `GenerateConfig` object to specify input/output types."},"warnings":[{"fix":"Ensure Pydantic v2 is installed (`pip install pydantic>=2`) in your environment. Update any existing generated models to Pydantic v2 standards if they were generated with `--output-model-type pydantic.BaseModel` (which is now deprecated in favor of `pydantic_v2.BaseModel`).","message":"Pydantic v1 runtime support has been completely removed in version 0.55.0. All generated models and internal operations now require Pydantic v2 or newer. Attempting to use the generator or its output with Pydantic v1 will result in errors.","severity":"breaking","affected_versions":">=0.55.0"},{"fix":"Review your generated models and code that interacts with default values. While often a cosmetic change, if you had custom logic around `default_factory`, you might need to adapt it.","message":"As of version 0.56.0, the generated syntax for fields with structured defaults (dicts, lists, model references) has changed. They now use `Field(default_value, validate_default=True)` instead of `default_factory=lambda: ...`. This change simplifies the output but may require adjustments if you were relying on the previous factory-based default initialization behavior.","severity":"breaking","affected_versions":">=0.56.0"},{"fix":"Always explicitly specify the output model type. For new projects, `--output-model-type pydantic_v2.BaseModel` (or `DataModelType.PydanticV2BaseModel`) is recommended.","message":"Omitting the `--output-model-type` option when using the CLI (or `output_model_type` in `GenerateConfig`) has been deprecated since version 0.53.0. The default output model type switched from Pydantic v1 to Pydantic v2 in 0.55.0.","severity":"deprecated","affected_versions":">=0.53.0"},{"fix":"If you rely on specific enum member names for `oneOf`/`anyOf` constructs, check your schema definitions. Ensure `title` fields are accurate or adjust your code to the new naming convention.","message":"In version 0.54.0, enum member names derived from `oneOf`/`anyOf` const constructs now correctly utilize the `title` field from the schema. Previously, `title` was ignored, and names were generated as `{type}_{value}`. This can change generated enum member names.","severity":"breaking","affected_versions":">=0.54.0"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}