🌐
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 429 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:
🌐
PyPI
pypi.org › project › datamodel-code-generator
datamodel-code-generator · PyPI
- uses: koxudaxi/datamodel-code-generator@0.44.0 with: input: schemas/api.yaml output: src/models/api.py
      » pip install datamodel-code-generator
    
Published   Mar 10, 2026
Version   0.55.0
🌐
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). - 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.
🌐
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
🌐
Debian Manpages
manpages.debian.org › unstable › datamodel-codegen › datamodel-codegen.1.en.html
datamodel-codegen(1) — datamodel-codegen — Debian unstable — Debian Manpages
Model generation for readOnly/writeOnly fields: 'request-response' = Request/Response models only (no base model), 'all' = Base + Request + Response models. ... Include HTTP status code in response model names (e.g., ResourceGetResponse200, ResourceGetResponseDefault)
Find elsewhere
🌐
Docker Hub
hub.docker.com › r › koxudaxi › datamodel-code-generator
koxudaxi/datamodel-code-generator - Docker Image
If you want to generate data model from a GraphQL schema then you should specify graphql extra option. $ pip install 'datamodel-code-generator[graphql]' Copy
🌐
Anaconda.org
anaconda.org › conda-forge › datamodel-code-generator
datamodel-code-generator - conda-forge
January 7, 2026 - Organization created on Apr 11, 2015 · A community-led collection of recipes, build infrastructure, and distributions for the conda package manager
🌐
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
🌐
Pydantify
pydantify.github.io › pydantify › technologies › dmcg
datamodel-code-generator - pydantify
Datamodel-code-generator (or DMCG for short) is a project which aims to translate data models written in either the ApenAPI 3 or JSONSchema format into Python class structures based on pydantic.
Top answer
1 of 1
1

I haven't found a way to make the Globals class use the extended definition of the table

You can change the type of a field in a subclass if you declare the field again using the desired type.

Also, simply adding new fields to the subclass does not seem to work

It looks like you are setting instance attributes in the __init__() method, but fields are declared as class attributes.

This example shows a way to add a calculated field records_by_id to ExtendedTable and use ExtendedTable in ExtendedGlobals:

# File: extensions.py
import json
from typing import Any, Dict, List, Optional

from pydantic import Field, validator

from datamodel import Globals, Record, Table


class ExtendedTable(Table):
    # New fields are declared as class attributes not as instance attributes inside the __init__()
    # Calculated fields usually have a default value or default factory so that you don't have to provide a value
    # I prefer a default_factory for mutable values
    records_by_id: Dict[int, Record] = Field(default_factory=dict)

    # A validator can populate a calculated field
    # Use always=True to run the validator even if a value is not supplied and the default value is used
    @validator("records_by_id", always=True)
    def _calculate_records_by_id(
        cls, value: Dict[int, Record], values: Dict[str, Any]
    ) -> Dict[int, Record]:
        records: Optional[List[Record]] = values.get("records")
        if records is None:
            # The records field was not valid
            # Return value or raise a ValueError instead if you want
            return value
        return {record.id: record for record in records}


class ExtendedGlobals(Globals):
    # You can change the type of a field in a subclass if you declare the field again
    table: ExtendedTable


if __name__ == "__main__":
    records = """
    {
        "table": {
            "records": [{"id": 0, "name": "A"}, {"id": 1, "name": "B"}]
        }
    }
    """

    content = json.loads(records)
    extended_globals = ExtendedGlobals.parse_obj(content)
    print(repr(extended_globals))

Output:

ExtendedGlobals(table=ExtendedTable(records=[Record(id=0, name='A'), Record(id=1, name='B')], records_by_id={0: Record(id=0, name='A'), 1: Record(id=1, name='B')}))
🌐
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
🌐
GitHub
github.com › koxudaxi › datamodel-code-generator › issues › 803
Support for Pydantic v2 · Issue #803 · koxudaxi/datamodel-code-generator
July 10, 2022 - koxudaxi / datamodel-code-generator Public · There was an error while loading. Please reload this page. Notifications · You must be signed in to change notification settings · Fork 426 · Star 3.8k · New issueCopy link · New issueCopy link · Closed · Closed ·
Author   ofek
🌐
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 - pydantic code generator from OpenAPI and more · 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 ·
🌐
Pythonfix
pythonfix.com › pkg › d › datamodel-code-generator
datamodel-code-generator 0.54.0 - Datamodel Code Generator - PythonFix.com
August 9, 2021 - Generate CSV files with fake data. Connexion - API first applications with OpenAPI/Swagger ... Typeddict Swagger-Codegen Json-Schema Graphql Datamodel Yaml Dataclass Fastapi Openapi-Codegen Msgspec Swagger Code Generator Openapi Generator Csv Pydantic