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
🎯 Generates Pydantic v2, Pydantic v2 dataclass, dataclasses, TypedDict, or msgspec output · 🔗 Handles complex schemas: $ref, allOf, oneOf, anyOf, enums, and nested types · ✅ Produces type-safe, validated code ready for your IDE and type checker ... 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
Pydantic
docs.pydantic.dev › latest › integrations › datamodel_code_generator
datamodel-code-generator - Pydantic Validation
# generated by datamodel-codegen: # filename: person.json # timestamp: 2020-05-19T15:07:31+00:00 from __future__ import annotations from typing import Any from pydantic import BaseModel, Field, conint class Pet(BaseModel): name: str | None = None age: int | None = None class Person(BaseModel): first_name: str = Field(description="The person's first name.") last_name: str = Field(description="The person's last name.") age: conint(ge=0) | None = Field(None, description='Age in years.') pets: list[Pet] | None = None comment: Any | None = None
PyPI
pypi.org › project › datamodel-code-generator › 0.33.0
datamodel-code-generator · PyPI
This code generator creates pydantic v1 and v2 model, dataclasses.dataclass, typing.TypedDict and msgspec.Struct from an openapi file and others. See documentation for more details. To install datamodel-code-generator: $ pip install datamodel-code-generator ·
» pip install datamodel-code-generator
GitHub
github.com › koxudaxi › datamodel-code-generator › releases
Releases · koxudaxi/datamodel-code-generator
Default output model switched from Pydantic v1 to v2 - Running datamodel-codegen without specifying --output-model-type now generates Pydantic v2 models (pydantic_v2.BaseModel) instead of Pydantic v1 models (pydantic.BaseModel). Users who depend on the previous default behavior must now explicitly specify --output-model-type pydantic.BaseModel to continue generating Pydantic v1 compatible code.
Author koxudaxi
Koxudaxi
koxudaxi.github.io › datamodel-code-generator
Redirecting to datamodel-code-generator.koxudaxi.dev
Redirecting to datamodel-code-generator.koxudaxi.dev...
Koxudaxi
datamodel-code-generator.koxudaxi.dev
datamodel-code-generator - datamodel-code-generator
pip install 'datamodel-code-generator[http]' datamodel-codegen --url https://example.com/api/openapi.yaml --output model.py ... [tool.datamodel-codegen] input = "schema.yaml" output = "src/models.py" output-model-type = "pydantic_v2.BaseModel"
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 · Support for Pydantic v2#803 ·
Author ofek
Top answer 1 of 9
144
In Pydantic 2, you can use MyModel.model_validate(my_dict) to generate a model from a dictionary. According to the documentation –
this is very similar to the
__init__method of the model, except it takes a dict rather than keyword arguments.
If you're Pydantic 1, the method is parse_obj instead.
2 of 9
72
You can also use its __init__ method:
your_model = YourModel(**your_dict)
Ubuntu
manpages.ubuntu.com › manpages › resolute › man1 › datamodel-codegen.1.html
Ubuntu Manpage: datamodel-codegen - pydantic code generator from OpenAPI and more
(example: "ref=branch") --input INPUT Input file/directory (default: stdin) --input-file-type {auto,openapi,jsonschema,json,yaml,dict,csv,graphql} Input file type (default: auto) --output OUTPUT Output file (default: stdout) --output-model-type {pydantic.BaseModel,pydantic_v2.BaseModel,dataclasses.dataclass,typing.TypedDict,msgspec.Struct} Output model type (default: pydantic.BaseModel) --url URL Input file URL.
Docker Hub
hub.docker.com › r › koxudaxi › datamodel-code-generator
koxudaxi/datamodel-code-generator - Docker Image
This code generator creates pydantic v1 and v2 model, dataclasses.dataclass, typing.TypedDict and msgspec.Struct from an openapi file and others. See documentation for more details. To install datamodel-code-generator: $ pip install datamodel-code-generator Copy ·
PyPI
pypi.org › project › improved-datamodel-codegen
improved-datamodel-codegen · PyPI
# generated by datamodel-codegen: # filename: api.yaml # timestamp: 2020-06-02T05:28:24+00:00 from __future__ import annotations from typing import List, Optional from pydantic import AnyUrl, BaseModel, Field class Pet(BaseModel): id: int name: str tag: Optional[str] = None class Pets(BaseModel): __root__: List[Pet] class Error(BaseModel): code: int message: str class Api(BaseModel): apiKey: Optional[str] = Field( None, description='To be used as a dataset parameter value' ) apiVersionNumber: Optional[str] = Field( None, description='To be used as a version parameter value' ) apiUrl: Optional[AnyUrl] = Field( None, description="The URL describing the dataset's fields" ) apiDocumentationUrl: Optional[AnyUrl] = Field( None, description='A URL to the API console for each API' ) class Apis(BaseModel): __root__: List[Api] This code generator creates FastAPI app from an openapi file.
» pip install improved-datamodel-codegen
Pydantic
docs.pydantic.dev › latest › datamodel_code_generator
Code Generation
You're being redirected to a new destination
Koxudaxi
koxudaxi.github.io › datamodel-code-generator › what_is_the_difference_between_v1_and_v2
Output Model Types - datamodel-code-generator
datamodel-codegen --input schema.json --output-model-type pydantic.BaseModel --output model.py · from pydantic import BaseModel, Field class Pet(BaseModel): id: int = Field(..., ge=0) name: str = Field(..., max_length=256) tag: Optional[str] = None class Pets(BaseModel): __root__: List[Pet] ... See Pydantic v2 Migration Guide for details.
Pydantic
docs.pydantic.dev › 1.10 › datamodel_code_generator
Code Generation - Pydantic
# generated by datamodel-codegen: # filename: person.json # timestamp: 2020-05-19T15:07:31+00:00 from __future__ import annotations from typing import Any, List, Optional from pydantic import BaseModel, Field, conint class Pet(BaseModel): name: Optional[str] = None age: Optional[int] = None class Person(BaseModel): first_name: str = Field(..., description="The person's first name.") last_name: str = Field(..., description="The person's last name.") age: Optional[conint(ge=0)] = Field(None, description='Age in years.') pets: Optional[List[Pet]] = None comment: Optional[Any] = None
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
Debian Manpages
manpages.debian.org › unstable › datamodel-codegen › datamodel-codegen.1.en.html
datamodel-codegen(1) — datamodel-codegen — Debian unstable — Debian Manpages
3 weeks ago - Use type alias format for RootModel (e.g., Foo = RootModel[Bar]) instead of class inheritance (Pydantic v2 only) ... Use specialized Enum class (StrEnum, IntEnum). Requires --target-python-version 3.11+ --use-standard-collections, --no-use-standard-collections · Use standard collections for type hinting (list, dict). Default: enabled ... Generate tuple types for arrays with items array syntax when minItems equals maxItems equals items length
GitHub
github.com › pydantic › pydantic › blob › main › docs › integrations › datamodel_code_generator.md
pydantic/docs/integrations/datamodel_code_generator.md at main · pydantic/pydantic
November 20, 2024 - # generated by datamodel-codegen: # filename: person.json # timestamp: 2020-05-19T15:07:31+00:00 from __future__ import annotations from typing import Any from pydantic import BaseModel, Field, conint class Pet(BaseModel): name: str | None = None age: int | None = None class Person(BaseModel): first_name: str = Field(description="The person's first name.") last_name: str = Field(description="The person's last name.") age: conint(ge=0) | None = Field(None, description='Age in years.') pets: list[Pet] | None = None comment: Any | None = None
Author pydantic
GitHub
github.com › koxudaxi › datamodel-code-generator › blob › main › CHANGELOG.md
datamodel-code-generator/CHANGELOG.md at main · koxudaxi/datamodel-code-generator
Default output model switched from Pydantic v1 to v2 - Running datamodel-codegen without specifying --output-model-type now generates Pydantic v2 models (pydantic_v2.BaseModel) instead of Pydantic v1 models (pydantic.BaseModel). Users who depend on the previous default behavior must now explicitly specify --output-model-type pydantic.BaseModel to continue generating Pydantic v1 compatible code.
Author koxudaxi