🌐
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
Python dictionary · pydantic v2 BaseModel · pydantic v2 dataclass · dataclasses · TypedDict · msgspec Struct · Generate a prompt to ask LLMs about CLI options: datamodel-codegen --generate-prompt "Best options for Pydantic v2?" | claude -p · See LLM Integration for more examples.
      » pip install datamodel-code-generator
    
Published   Mar 10, 2026
Version   0.55.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.
🌐
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.
🌐
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
🌐
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
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
🌐
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
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'>
>>> 
🌐
Tessl
tessl.io › registry › tessl › pypi-datamodel-code-generator
0.33.0 • pypi-datamodel-code-generator • tessl • Registry • Tessl
January 29, 2026 - The primary programmatic interface for generating Python data models with extensive configuration options for input sources, output formats, and code generation behavior. def generate( input_: Path | str | ParseResult | Mapping[str, Any], *, ...
🌐
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 › 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
🌐
Koxudaxi
datamodel-code-generator.koxudaxi.dev › cli-reference › base-options
📁 Base Options - datamodel-code-generator
Specify the input file type for code generation. The --input-file-type flag explicitly sets the input format. ... For example, if you have a JSON Schema written in YAML format, use --input-file-type jsonschema, not --input-file-type yaml. The yaml type treats the file as raw data and infers a schema from it. ... # generated by datamodel-codegen: # filename: pet.json # timestamp: 2019-07-26T00:00:00+00:00 from __future__ import annotations from pydantic import BaseModel class Pet(BaseModel): name: str age: int class Model(BaseModel): Pet: Pet