🌐
GitHub
github.com › koxudaxi › datamodel-code-generator
GitHub - koxudaxi/datamodel-code-generator: Python data model generator (Pydantic, dataclasses, TypedDict, msgspec) from OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV). · GitHub
Python data model generator (Pydantic, dataclasses, TypedDict, msgspec) from OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV). - koxudaxi/datamodel-code-generator
Starred by 3.8K users
Forked by 430 users
Languages   Python
🌐
Pydantic
docs.pydantic.dev › latest › integrations › datamodel_code_generator
datamodel-code-generator - Pydantic Validation
The datamodel-code-generator project is a library and command-line utility to generate pydantic models from just about any data source, including: OpenAPI 3 (YAML/JSON) JSON Schema · JSON/YAML/CSV Data (which will be converted to JSON Schema) ...
🌐
PyPI
pypi.org › project › datamodel-code-generator
datamodel-code-generator · PyPI
apache/airflow - Generate OpenAPI datamodels for airflow-ctl and task-sdk via pyproject codegen config ... tensorzero/tensorzero - Generate Python dataclasses from JSON Schema in the schema generation pipeline
      » pip install datamodel-code-generator
    
Published   Apr 04, 2026
Version   0.56.0
🌐
Koxudaxi
koxudaxi.github.io › datamodel-code-generator › custom_template
Custom template - datamodel-code-generator
$ datamodel-codegen --input {your_input_file} --output {your_output_file} --custom-template-dir {your_custom_template_directory} Replace {your_input_file}, {your_output_file}, and {your_custom_template_directory} with the appropriate paths. Let's say you want to generate a custom Python data model from a JSON Schema file called person.json.
🌐
GitHub
github.com › koxudaxi › datamodel-code-generator › releases
Releases · koxudaxi/datamodel-code-generator
Python data model generator (Pydantic, dataclasses, TypedDict, msgspec) from OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV). - Releases · koxudaxi/datamodel-code-generator
Author   koxudaxi
🌐
Docker Hub
hub.docker.com › r › koxudaxi › datamodel-code-generator
koxudaxi/datamodel-code-generator - Docker Image
usage: datamodel-codegen [options] Generate Python data models from schema definitions or structured data Options: --http-headers HTTP_HEADER [HTTP_HEADER ...] Set headers in HTTP requests to the remote host.
🌐
Koxudaxi
datamodel-code-generator.koxudaxi.dev
datamodel-code-generator - datamodel-code-generator
This code generator creates pydantic model from an openapi file and others.
🌐
Debian Manpages
manpages.debian.org › testing › datamodel-codegen › datamodel-codegen.1.en.html
datamodel-codegen(1) — datamodel-codegen — Debian testing — Debian Manpages
December 19, 2025 - datamodel-codegen [options] Generate Python data models from schema definitions or structured data · For detailed usage, see: https://koxudaxi.github.io/datamodel-code-generator · --additional-imports ADDITIONAL_IMPORTS · Custom imports for output (delimited list input).
🌐
GitHub
github.com › tomercagan › datamodel-code-generator
GitHub - tomercagan/datamodel-code-generator: Pydantic model generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
This code generator creates pydantic model from an openapi file and others. See documentation for more details. ... If you want to resolve $ref for remote files then you should specify http extra option.
Author   tomercagan
Find elsewhere
🌐
Snyk
snyk.io › advisor › python packages › datamodel-code-generator
datamodel-code-generator - Python package | Snyk
usage: datamodel-codegen [options] Generate Python data models from schema definitions or structured data Options: --additional-imports ADDITIONAL_IMPORTS Custom imports for output (delimited list input).
🌐
DeepWiki
deepwiki.com › koxudaxi › datamodel-code-generator
koxudaxi/datamodel-code-generator | DeepWiki
April 21, 2025 - The datamodel-code-generator is a tool that generates Python data models from various schema formats and structured data inputs. It transforms schema definitions such as OpenAPI, JSON Schema, and Grap
🌐
GitHub
github.com › koxudaxi › datamodel-code-generator › blob › main › docs › using_as_module.md
datamodel-code-generator/docs/using_as_module.md at main · koxudaxi/datamodel-code-generator
Python data model generator (Pydantic, dataclasses, TypedDict, msgspec) from OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV). - koxudaxi/datamodel-code-generator
Author   koxudaxi
Top answer
1 of 1
2

From the datamodel-code-generator "official documentation" mentioned on the page you reference, datamodel-code-generator can be used as a module to get the dictionary to python-code-string (see https://koxudaxi.github.io/datamodel-code-generator/using_as_module/).

Here is there relevant example code (to avoid problems with their pages changing)

from datamodel_code_generator import DataModelType, PythonVersion
from datamodel_code_generator.model import get_data_model_types
from datamodel_code_generator.parser.jsonschema import JsonSchemaParser

json_schema: str = """{
    "type": "object",
    "properties": {
        "number": {"type": "number"},
        "street_name": {"type": "string"},
        "street_type": {"type": "string",
                        "enum": ["Street", "Avenue", "Boulevard"]
                        }
    }
}"""


data_model_types = get_data_model_types(
    DataModelType.PydanticV2BaseModel,
    target_python_version=PythonVersion.PY_311
)
parser = JsonSchemaParser(
   json_schema,
   data_model_type=data_model_types.data_model,
   data_model_root_type=data_model_types.root_model,
   data_model_field_type=data_model_types.field_model,
   data_type_manager_type=data_model_types.data_type_manager,
   dump_resolve_reference_action=data_model_types.dump_resolve_reference_action,
                       )
result = parser.parse()

Then, assuming that there isn't a way to send in a schema that would cause their parser to generate malicious code, you just need to run

exec(result)

EDIT: Here is a worked out example using the example code. I get an error with your schema, which I have not tried to debug.

>>> from datamodel_code_generator import DataModelType, PythonVersion
>>> from datamodel_code_generator.model import get_data_model_types
>>> from datamodel_code_generator.parser.jsonschema import JsonSchemaParser
>>> json_schema: str = """{
...     "type": "object",
...     "properties": {
...         "number": {"type": "number"},
...         "street_name": {"type": "string"},
...         "street_type": {"type": "string",
...                         "enum": ["Street", "Avenue", "Boulevard"]
...                         }
...     }
... }"""
>>> parser = JsonSchemaParser(
...    json_schema,
...    data_model_type=data_model_types.data_model,
...    data_model_root_type=data_model_types.root_model,
...    data_model_field_type=data_model_types.field_model,
...    data_type_manager_type=data_model_types.data_type_manager,
...    dump_resolve_reference_action=data_model_types.dump_resolve_reference_action,
... )
>>> result = parser.parse()
>>> print(result)
from __future__ import annotations

from enum import Enum
from typing import Optional

from pydantic import BaseModel


class StreetType(Enum):
    Street = 'Street'
    Avenue = 'Avenue'
    Boulevard = 'Boulevard'


class Model(BaseModel):
    number: Optional[float] = None
    street_name: Optional[str] = None
    street_type: Optional[StreetType] = None

>>> exec(result)
>>> m = Model(**{'number': 1, 'street_name': 'Main', 'street_type': 'Street'})
>>> print(m)
number=1.0 street_name='Main' street_type=<StreetType.Street: 'Street'>
>>> 
🌐
PyPI
pypi.org › project › improved-datamodel-codegen
improved-datamodel-codegen · PyPI
This code generator creates pydantic model from an openapi file and others. See documentation for more details. ... If you want to resolve $ref for remote files then you should specify http extra option.
      » pip install improved-datamodel-codegen
    
Published   Mar 07, 2023
Version   1.2.1
🌐
GitHub
github.com › guardicore › datamodel-code-generator
GitHub - guardicore/datamodel-code-generator · GitHub
usage: datamodel-codegen [options] Generate Python data models from schema definitions or structured data Options: --additional-imports ADDITIONAL_IMPORTS Custom imports for output (delimited list input).
Author   guardicore
🌐
GitHub
github.com › koxudaxi › datamodel-code-generator › blob › main › pyproject.toml
datamodel-code-generator/pyproject.toml at main · koxudaxi/datamodel-code-generator
Python data model generator (Pydantic, dataclasses, TypedDict, msgspec) from OpenAPI, JSON Schema, GraphQL, and raw data (JSON/YAML/CSV). - koxudaxi/datamodel-code-generator
Author   koxudaxi
🌐
GitHub
github.com › koxudaxi › datamodel-code-generator › issues › 331
Dynamic creation of BaseModel classes at runtime · Issue #331 · koxudaxi/datamodel-code-generator
February 11, 2021 - But it is tightly coupled with the rendering of Python files that contain the BaseModel child classes source code. I would like to be able to intercept this, and 'render' that structure differently. The most important case would be to generate a Python class dynamically (which should be relatively easy, using type(...). Another use-case (although less important) would be to 'translate' the schema into a different format (I would have a use for Avro, for example). Basically, datamodel-code-generator could become sort of an any-to-any schema translator.
Author   makkus