🌐
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
pip install 'datamodel-code-generator[graphql]' Docker: docker pull koxudaxi/datamodel-code-generator · datamodel-codegen --input schema.json --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output model.py ·
Starred by 3.8K users
Forked by 429 users
Languages   Python
🌐
PyPI
pypi.org › project › improved-datamodel-codegen
improved-datamodel-codegen · PyPI
Download URL: improved_datamodel_codegen-1.2.1-py3-none-any.whl
      » pip install improved-datamodel-codegen
    
Published   Mar 07, 2023
Version   1.2.1
Discussions

Create Pydantic datamodel from huge JSON file with local datamodel-code-generator
Did the pip installation succeed? If so, you could try python -m datamodel_code_generator More on reddit.com
🌐 r/learnpython
2
0
December 22, 2022
jsonschema - datamodel-code-generator can't handle JSON Compound Schema Document - Stack Overflow
I ran on the CLI datamodel-codegen --input schema.json --input-file-type jsonschema --output model.py. More on stackoverflow.com
🌐 stackoverflow.com
python - Is it possible to extend pydantic models generated using datamodel-code-generator? - Stack Overflow
I am using the datamodel-code-generator to generate pydantic models from a JSON schema. Here is the JSON schema used. And the generated models after running the datamodel-code-generator. # File: More on stackoverflow.com
🌐 stackoverflow.com
Support for Pydantic v2
Just FYI https://pydantic-docs.helpmanual.io/blog/pydantic-v2/ Likely requires dropping More on github.com
🌐 github.com
23
July 10, 2022
🌐
Pydantic
docs.pydantic.dev › latest › integrations › datamodel_code_generator
datamodel-code-generator - Pydantic Validation
pip install datamodel-code-generator · In this case, datamodel-code-generator creates pydantic models from a JSON Schema file. datamodel-codegen --input person.json --input-file-type jsonschema --output model.py ·
🌐
PyPI
pypi.org › project › datamodel-code-generator
datamodel-code-generator · PyPI
pip install 'datamodel-code-generator[graphql]' Docker: docker pull koxudaxi/datamodel-code-generator · datamodel-codegen --input schema.json --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output model.py ·
      » pip install datamodel-code-generator
    
Published   Mar 10, 2026
Version   0.55.0
🌐
Debian Manpages
manpages.debian.org › unstable › datamodel-codegen › datamodel-codegen.1.en.html
datamodel-codegen(1) — datamodel-codegen — Debian unstable — Debian Manpages
2 weeks ago - Documentation: https://datamodel-code-generator.koxudaxi.dev GitHub: https://github.com/koxudaxi/datamodel-code-generator
🌐
Debian Manpages
manpages.debian.org › testing › datamodel-codegen › datamodel-codegen.1.en.html
datamodel-codegen(1) — datamodel-codegen — Debian testing — Debian Manpages
Documentation: https://koxudaxi.github.io/datamodel-code-generator GitHub: https://github.com/koxudaxi/datamodel-code-generator
🌐
Koxudaxi
koxudaxi.github.io › datamodel-code-generator › custom_template
Custom template - datamodel-code-generator
$ datamodel-codegen --input person.json --output person.py --custom-template-dir custom_templates
🌐
Ubuntu
manpages.ubuntu.com › manpages › resolute › man1 › datamodel-codegen.1.html
Ubuntu Manpage: datamodel-codegen - pydantic code generator from OpenAPI and more
`$ pip install 'datamodel-code-generator[debug]'`) --disable-warnings disable warnings --generate-cli-command Generate CLI command from pyproject.toml configuration and exit --generate-pyproject-config Generate pyproject.toml configuration from the provided CLI arguments and exit --ignore-pyproject ...
🌐
Pythonfix
pythonfix.com › pkg › d › datamodel-code-generator
datamodel-code-generator 0.54.0 - Datamodel Code Generator - PythonFix.com
August 9, 2021 - The koxudaxi/datamodel-code-generator repo was created 6 years ago and the last code push was 3 days ago. The project is very popular with an impressive 3759 github stars! You can install datamodel-code-generator using pip
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › create pydantic datamodel from huge json file with local datamodel-code-generator
r/learnpython on Reddit: Create Pydantic datamodel from huge JSON file with local datamodel-code-generator
December 22, 2022 -

Hi,

I got some JSON files and would like to use them to create a basemodel.

And I also found this create website JSON to Pydantic.

My main JSON test file is above 700kb, which seems to much for the website.

The site also provide a link to the github repo of the underlying program.

I uses

pip install datamodel-code-generator

to install it on my Windows 10 machine, but am not able to use it.

Is it possible to run it from powershell command line?

I tried

datamodel-codegen -h

python datamodel-codegen -h

without success.

🌐
Koxudaxi
datamodel-code-generator.koxudaxi.dev
datamodel-code-generator - datamodel-code-generator
# ⚡ msgspec (high-performance ... full list. ... See LLM Integration for more examples. pip install 'datamodel-code-generator[http]' datamodel-codegen --url https://example.com/api/openapi.yaml --output model.py...
🌐
Pydigger
pydigger.com › pypi › datamodel-code-generator
datamodel-code-generator
March 16, 2024 - o/pypi/pyversions/datamodel-co... install `datamodel-code-generator`:\n```bash\n$ pip install datamodel-code-generator\n```\n\n## Simple Usage\nYou can generate models from a local file.\n```bash\n$ datamodel-codegen --input api.yaml --output model.py\n```\n\n<details>\n...
🌐
Docker Hub
hub.docker.com › r › koxudaxi › datamodel-code-generator
koxudaxi/datamodel-code-generator - Docker Image
$ pip install 'datamodel-code-generator[graphql]' Copy ... You can generate models from a URL. $ datamodel-codegen --url https://<INPUT FILE URL> --output model.py Copy
🌐
GitHub
github.com › guardicore › datamodel-code-generator
GitHub - guardicore/datamodel-code-generator · GitHub
$ pip install datamodel-code-generator · You can generate models from a local file. $ datamodel-codegen --input api.yaml --output model.py ·
Author   guardicore
🌐
GitHub
github.com › koxudaxi › datamodel-code-generator › releases
Releases · koxudaxi/datamodel-code-generator
Use datamodel_code_generator.model.pydantic_v2 instead. (#3031) Pydantic v2 now required at runtime - The minimum pydantic dependency changed from pydantic>=1.5 to pydantic>=2,<3. Users with pydantic v1 installed must upgrade to pydantic v2 before using datamodel-code-generator (#3027)
Author   koxudaxi
🌐
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
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 › koxudaxi › datamodel-code-generator › issues › 803
Support for Pydantic v2 · Issue #803 · koxudaxi/datamodel-code-generator
July 10, 2022 - Just FYI https://pydantic-docs.helpmanual.io/blog/pydantic-v2/ Likely requires dropping
Author   ofek