datamodel-code-generator 0.11.12__py3-none-any.whl → 0.45.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. datamodel_code_generator/__init__.py +654 -185
  2. datamodel_code_generator/__main__.py +872 -388
  3. datamodel_code_generator/arguments.py +798 -0
  4. datamodel_code_generator/cli_options.py +295 -0
  5. datamodel_code_generator/format.py +292 -54
  6. datamodel_code_generator/http.py +85 -10
  7. datamodel_code_generator/imports.py +152 -43
  8. datamodel_code_generator/model/__init__.py +138 -1
  9. datamodel_code_generator/model/base.py +531 -120
  10. datamodel_code_generator/model/dataclass.py +211 -0
  11. datamodel_code_generator/model/enum.py +133 -12
  12. datamodel_code_generator/model/imports.py +22 -0
  13. datamodel_code_generator/model/msgspec.py +462 -0
  14. datamodel_code_generator/model/pydantic/__init__.py +30 -25
  15. datamodel_code_generator/model/pydantic/base_model.py +304 -100
  16. datamodel_code_generator/model/pydantic/custom_root_type.py +11 -2
  17. datamodel_code_generator/model/pydantic/dataclass.py +15 -4
  18. datamodel_code_generator/model/pydantic/imports.py +40 -27
  19. datamodel_code_generator/model/pydantic/types.py +188 -96
  20. datamodel_code_generator/model/pydantic_v2/__init__.py +51 -0
  21. datamodel_code_generator/model/pydantic_v2/base_model.py +268 -0
  22. datamodel_code_generator/model/pydantic_v2/imports.py +15 -0
  23. datamodel_code_generator/model/pydantic_v2/root_model.py +35 -0
  24. datamodel_code_generator/model/pydantic_v2/types.py +143 -0
  25. datamodel_code_generator/model/scalar.py +124 -0
  26. datamodel_code_generator/model/template/Enum.jinja2 +15 -2
  27. datamodel_code_generator/model/template/ScalarTypeAliasAnnotation.jinja2 +6 -0
  28. datamodel_code_generator/model/template/ScalarTypeAliasType.jinja2 +6 -0
  29. datamodel_code_generator/model/template/ScalarTypeStatement.jinja2 +6 -0
  30. datamodel_code_generator/model/template/TypeAliasAnnotation.jinja2 +20 -0
  31. datamodel_code_generator/model/template/TypeAliasType.jinja2 +20 -0
  32. datamodel_code_generator/model/template/TypeStatement.jinja2 +20 -0
  33. datamodel_code_generator/model/template/TypedDict.jinja2 +5 -0
  34. datamodel_code_generator/model/template/TypedDictClass.jinja2 +25 -0
  35. datamodel_code_generator/model/template/TypedDictFunction.jinja2 +24 -0
  36. datamodel_code_generator/model/template/UnionTypeAliasAnnotation.jinja2 +10 -0
  37. datamodel_code_generator/model/template/UnionTypeAliasType.jinja2 +10 -0
  38. datamodel_code_generator/model/template/UnionTypeStatement.jinja2 +10 -0
  39. datamodel_code_generator/model/template/dataclass.jinja2 +50 -0
  40. datamodel_code_generator/model/template/msgspec.jinja2 +55 -0
  41. datamodel_code_generator/model/template/pydantic/BaseModel.jinja2 +17 -4
  42. datamodel_code_generator/model/template/pydantic/BaseModel_root.jinja2 +12 -4
  43. datamodel_code_generator/model/template/pydantic/Config.jinja2 +1 -1
  44. datamodel_code_generator/model/template/pydantic/dataclass.jinja2 +15 -2
  45. datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2 +57 -0
  46. datamodel_code_generator/model/template/pydantic_v2/ConfigDict.jinja2 +5 -0
  47. datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2 +48 -0
  48. datamodel_code_generator/model/type_alias.py +70 -0
  49. datamodel_code_generator/model/typed_dict.py +161 -0
  50. datamodel_code_generator/model/types.py +106 -0
  51. datamodel_code_generator/model/union.py +105 -0
  52. datamodel_code_generator/parser/__init__.py +30 -12
  53. datamodel_code_generator/parser/_graph.py +67 -0
  54. datamodel_code_generator/parser/_scc.py +171 -0
  55. datamodel_code_generator/parser/base.py +2426 -380
  56. datamodel_code_generator/parser/graphql.py +652 -0
  57. datamodel_code_generator/parser/jsonschema.py +2518 -647
  58. datamodel_code_generator/parser/openapi.py +631 -222
  59. datamodel_code_generator/py.typed +0 -0
  60. datamodel_code_generator/pydantic_patch.py +28 -0
  61. datamodel_code_generator/reference.py +672 -290
  62. datamodel_code_generator/types.py +521 -145
  63. datamodel_code_generator/util.py +155 -0
  64. datamodel_code_generator/watch.py +65 -0
  65. datamodel_code_generator-0.45.0.dist-info/METADATA +301 -0
  66. datamodel_code_generator-0.45.0.dist-info/RECORD +69 -0
  67. {datamodel_code_generator-0.11.12.dist-info → datamodel_code_generator-0.45.0.dist-info}/WHEEL +1 -1
  68. datamodel_code_generator-0.45.0.dist-info/entry_points.txt +2 -0
  69. datamodel_code_generator/version.py +0 -1
  70. datamodel_code_generator-0.11.12.dist-info/METADATA +0 -440
  71. datamodel_code_generator-0.11.12.dist-info/RECORD +0 -31
  72. datamodel_code_generator-0.11.12.dist-info/entry_points.txt +0 -3
  73. {datamodel_code_generator-0.11.12.dist-info → datamodel_code_generator-0.45.0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,155 @@
1
+ """Utility functions and Pydantic version compatibility helpers.
2
+
3
+ Provides Pydantic version detection (PYDANTIC_V2), YAML/TOML loading,
4
+ and version-compatible decorators (model_validator, field_validator).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import copy
10
+ import re
11
+ from functools import lru_cache
12
+ from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, overload
13
+
14
+ import pydantic
15
+ from packaging import version
16
+ from pydantic import BaseModel as _BaseModel
17
+
18
+ if TYPE_CHECKING:
19
+ from pathlib import Path
20
+
21
+ PYDANTIC_VERSION = version.parse(pydantic.VERSION if isinstance(pydantic.VERSION, str) else str(pydantic.VERSION))
22
+
23
+ PYDANTIC_V2: bool = version.parse("2.0b3") <= PYDANTIC_VERSION
24
+
25
+ try:
26
+ from yaml import CSafeLoader as SafeLoader
27
+ except ImportError: # pragma: no cover
28
+ from yaml import SafeLoader
29
+
30
+ try:
31
+ from tomllib import load as load_tomllib # type: ignore[ignoreMissingImports]
32
+ except ImportError:
33
+ from tomli import load as load_tomllib # type: ignore[ignoreMissingImports]
34
+
35
+
36
+ def load_toml(path: Path) -> dict[str, Any]:
37
+ """Load and parse a TOML file."""
38
+ with path.open("rb") as f:
39
+ return load_tomllib(f)
40
+
41
+
42
+ SafeLoaderTemp = copy.deepcopy(SafeLoader)
43
+ SafeLoaderTemp.yaml_constructors = copy.deepcopy(SafeLoader.yaml_constructors)
44
+ SafeLoaderTemp.add_constructor(
45
+ "tag:yaml.org,2002:timestamp",
46
+ SafeLoaderTemp.yaml_constructors["tag:yaml.org,2002:str"],
47
+ )
48
+ SafeLoader = SafeLoaderTemp
49
+
50
+ Model = TypeVar("Model", bound=_BaseModel)
51
+ T = TypeVar("T")
52
+
53
+
54
+ @overload
55
+ def model_validator(
56
+ mode: Literal["before"],
57
+ ) -> (
58
+ Callable[[Callable[[type[Model], T], T]], Callable[[type[Model], T], T]]
59
+ | Callable[[Callable[[Model, T], T]], Callable[[Model, T], T]]
60
+ ): ...
61
+
62
+
63
+ @overload
64
+ def model_validator(
65
+ mode: Literal["after"],
66
+ ) -> (
67
+ Callable[[Callable[[type[Model], T], T]], Callable[[type[Model], T], T]]
68
+ | Callable[[Callable[[Model, T], T]], Callable[[Model, T], T]]
69
+ | Callable[[Callable[[Model], Model]], Callable[[Model], Model]]
70
+ ): ...
71
+
72
+
73
+ @overload
74
+ def model_validator() -> (
75
+ Callable[[Callable[[type[Model], T], T]], Callable[[type[Model], T], T]]
76
+ | Callable[[Callable[[Model, T], T]], Callable[[Model, T], T]]
77
+ | Callable[[Callable[[Model], Model]], Callable[[Model], Model]]
78
+ ): ...
79
+
80
+
81
+ def model_validator( # pyright: ignore[reportInconsistentOverload]
82
+ mode: Literal["before", "after"] = "after",
83
+ ) -> (
84
+ Callable[[Callable[[type[Model], T], T]], Callable[[type[Model], T], T]]
85
+ | Callable[[Callable[[Model, T], T]], Callable[[Model, T], T]]
86
+ | Callable[[Callable[[Model], Model]], Callable[[Model], Model]]
87
+ ):
88
+ """Decorate model validators for both Pydantic v1 and v2."""
89
+
90
+ @overload
91
+ def inner(method: Callable[[type[Model], T], T]) -> Callable[[type[Model], T], T]: ...
92
+
93
+ @overload
94
+ def inner(method: Callable[[Model, T], T]) -> Callable[[Model, T], T]: ...
95
+
96
+ @overload
97
+ def inner(method: Callable[[Model], Model]) -> Callable[[Model], Model]: ...
98
+
99
+ def inner(
100
+ method: Callable[[type[Model], T], T] | Callable[[Model, T], T] | Callable[[Model], Model],
101
+ ) -> Callable[[type[Model], T], T] | Callable[[Model, T], T] | Callable[[Model], Model]:
102
+ if PYDANTIC_V2:
103
+ from pydantic import model_validator as model_validator_v2 # noqa: PLC0415
104
+
105
+ if mode == "before":
106
+ return model_validator_v2(mode=mode)(classmethod(method)) # type: ignore[reportReturnType]
107
+ return model_validator_v2(mode=mode)(method) # type: ignore[reportReturnType]
108
+ from pydantic import root_validator # noqa: PLC0415
109
+
110
+ return root_validator(method, pre=mode == "before") # pyright: ignore[reportCallIssue]
111
+
112
+ return inner
113
+
114
+
115
+ def field_validator(
116
+ field_name: str,
117
+ *fields: str,
118
+ mode: Literal["before", "after"] = "after",
119
+ ) -> Callable[[Any], Callable[[BaseModel, Any], Any]]:
120
+ """Decorate field validators for both Pydantic v1 and v2."""
121
+
122
+ def inner(method: Callable[[Model, Any], Any]) -> Callable[[Model, Any], Any]:
123
+ if PYDANTIC_V2:
124
+ from pydantic import field_validator as field_validator_v2 # noqa: PLC0415
125
+
126
+ return field_validator_v2(field_name, *fields, mode=mode)(method)
127
+ from pydantic import validator # noqa: PLC0415
128
+
129
+ return validator(field_name, *fields, pre=mode == "before")(method) # pyright: ignore[reportReturnType]
130
+
131
+ return inner
132
+
133
+
134
+ if PYDANTIC_V2:
135
+ from pydantic import ConfigDict
136
+ else:
137
+ ConfigDict = dict
138
+
139
+
140
+ class BaseModel(_BaseModel):
141
+ """Base Pydantic model with version-compatible configuration."""
142
+
143
+ if PYDANTIC_V2:
144
+ model_config = ConfigDict(strict=False) # pyright: ignore[reportAssignmentType]
145
+
146
+
147
+ _UNDER_SCORE_1: re.Pattern[str] = re.compile(r"([^_])([A-Z][a-z]+)")
148
+ _UNDER_SCORE_2: re.Pattern[str] = re.compile(r"([a-z0-9])([A-Z])")
149
+
150
+
151
+ @lru_cache
152
+ def camel_to_snake(string: str) -> str:
153
+ """Convert camelCase or PascalCase to snake_case."""
154
+ subbed = _UNDER_SCORE_1.sub(r"\1_\2", string)
155
+ return _UNDER_SCORE_2.sub(r"\1_\2", subbed).lower()
@@ -0,0 +1,65 @@
1
+ """Watch mode for automatic code regeneration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from pathlib import Path
7
+ from typing import TYPE_CHECKING, Any
8
+
9
+ if TYPE_CHECKING:
10
+ from datamodel_code_generator.__main__ import Config, Exit
11
+
12
+
13
+ def _get_watchfiles() -> Any:
14
+ """Lazily import watchfiles."""
15
+ try:
16
+ import watchfiles # noqa: PLC0415 # pyright: ignore[reportMissingImports]
17
+ except ImportError as exc:
18
+ msg = "Please run `pip install 'datamodel-code-generator[watch]'` to use watch mode"
19
+ raise Exception(msg) from exc # noqa: TRY002
20
+ return watchfiles
21
+
22
+
23
+ def watch_and_regenerate(
24
+ config: Config,
25
+ extra_template_data: dict[str, Any] | None,
26
+ aliases: dict[str, str] | None,
27
+ custom_formatters_kwargs: dict[str, str] | None,
28
+ ) -> Exit:
29
+ """Watch input files and regenerate on changes."""
30
+ from datamodel_code_generator.__main__ import Exit, run_generate_from_config # noqa: PLC0415
31
+
32
+ watchfiles = _get_watchfiles()
33
+
34
+ watch_path = Path(config.input) if isinstance(config.input, (str, Path)) else None
35
+ if watch_path is None:
36
+ print("Watch mode requires --input file path", file=sys.stderr) # noqa: T201
37
+ return Exit.ERROR
38
+
39
+ print(f"Watching {watch_path} for changes... (Ctrl+C to stop)") # noqa: T201
40
+
41
+ try:
42
+ for changes in watchfiles.watch(
43
+ watch_path,
44
+ debounce=int(config.watch_delay * 1000),
45
+ recursive=watch_path.is_dir(),
46
+ ):
47
+ print(f"\nDetected changes: {changes}") # noqa: T201
48
+ print("Regenerating...") # noqa: T201
49
+ try:
50
+ run_generate_from_config(
51
+ config=config,
52
+ input_=config.input, # pyright: ignore[reportArgumentType]
53
+ output=config.output,
54
+ extra_template_data=extra_template_data,
55
+ aliases=aliases,
56
+ command_line=None,
57
+ custom_formatters_kwargs=custom_formatters_kwargs,
58
+ )
59
+ print("Done.") # noqa: T201
60
+ except Exception as e: # noqa: BLE001
61
+ print(f"Error: {e}", file=sys.stderr) # noqa: T201
62
+ except KeyboardInterrupt:
63
+ print("\nWatch mode stopped.") # noqa: T201
64
+
65
+ return Exit.OK
@@ -0,0 +1,301 @@
1
+ Metadata-Version: 2.4
2
+ Name: datamodel-code-generator
3
+ Version: 0.45.0
4
+ Summary: Datamodel Code Generator
5
+ Project-URL: Homepage, https://github.com/koxudaxi/datamodel-code-generator
6
+ Project-URL: Source, https://github.com/koxudaxi/datamodel-code-generator
7
+ Author-email: Koudai Aono <koxudaxi@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: Implementation :: CPython
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: argcomplete<4,>=2.10.1
23
+ Requires-Dist: black>=19.10b0
24
+ Requires-Dist: genson<2,>=1.2.1
25
+ Requires-Dist: inflect<8,>=4.1
26
+ Requires-Dist: isort<8,>=4.3.21
27
+ Requires-Dist: jinja2<4,>=2.10.1
28
+ Requires-Dist: packaging
29
+ Requires-Dist: pydantic>=1.5
30
+ Requires-Dist: pyyaml>=6.0.1
31
+ Requires-Dist: tomli<3,>=2.2.1; python_version <= '3.11'
32
+ Provides-Extra: all
33
+ Requires-Dist: graphql-core>=3.2.3; extra == 'all'
34
+ Requires-Dist: httpx>=0.24.1; extra == 'all'
35
+ Requires-Dist: openapi-spec-validator<0.8,>=0.2.8; extra == 'all'
36
+ Requires-Dist: prance>=0.18.2; extra == 'all'
37
+ Requires-Dist: pysnooper<2,>=0.4.1; extra == 'all'
38
+ Requires-Dist: ruff>=0.9.10; extra == 'all'
39
+ Requires-Dist: watchfiles>=1.1; extra == 'all'
40
+ Provides-Extra: debug
41
+ Requires-Dist: pysnooper<2,>=0.4.1; extra == 'debug'
42
+ Provides-Extra: graphql
43
+ Requires-Dist: graphql-core>=3.2.3; extra == 'graphql'
44
+ Provides-Extra: http
45
+ Requires-Dist: httpx>=0.24.1; extra == 'http'
46
+ Provides-Extra: ruff
47
+ Requires-Dist: ruff>=0.9.10; extra == 'ruff'
48
+ Provides-Extra: validation
49
+ Requires-Dist: openapi-spec-validator<0.8,>=0.2.8; extra == 'validation'
50
+ Requires-Dist: prance>=0.18.2; extra == 'validation'
51
+ Provides-Extra: watch
52
+ Requires-Dist: watchfiles>=1.1; extra == 'watch'
53
+ Description-Content-Type: text/markdown
54
+
55
+ # datamodel-code-generator
56
+
57
+ 🚀 Generate Python data models from schema definitions in seconds.
58
+
59
+ [![PyPI version](https://badge.fury.io/py/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
60
+ [![Conda-forge](https://img.shields.io/conda/v/conda-forge/datamodel-code-generator)](https://anaconda.org/conda-forge/datamodel-code-generator)
61
+ [![Downloads](https://pepy.tech/badge/datamodel-code-generator/month)](https://pepy.tech/project/datamodel-code-generator)
62
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/datamodel-code-generator)](https://pypi.python.org/pypi/datamodel-code-generator)
63
+ [![codecov](https://codecov.io/gh/koxudaxi/datamodel-code-generator/graph/badge.svg?token=plzSSFb9Li)](https://codecov.io/gh/koxudaxi/datamodel-code-generator)
64
+ ![license](https://img.shields.io/github/license/koxudaxi/datamodel-code-generator.svg)
65
+ [![Pydantic v1](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v1.json)](https://pydantic.dev)
66
+ [![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)
67
+
68
+ ## ✨ What it does
69
+
70
+ - 📄 Converts **OpenAPI 3**, **JSON Schema**, **GraphQL**, and raw data (JSON/YAML/CSV) into Python models
71
+ - 🎯 Generates **Pydantic v1/v2**, **dataclasses**, **TypedDict**, or **msgspec** output
72
+ - 🔗 Handles complex schemas: `$ref`, `allOf`, `oneOf`, `anyOf`, enums, and nested types
73
+ - ✅ Produces type-safe, validated code ready for your IDE and type checker
74
+
75
+ ---
76
+
77
+ ## 📖 Documentation
78
+
79
+ **👉 [koxudaxi.github.io/datamodel-code-generator](https://koxudaxi.github.io/datamodel-code-generator)**
80
+
81
+ - 🖥️ [CLI Reference](https://koxudaxi.github.io/datamodel-code-generator/cli-reference/) - All command-line options
82
+ - ⚙️ [pyproject.toml](https://koxudaxi.github.io/datamodel-code-generator/pyproject_toml/) - Configuration file
83
+ - 🔄 [CI/CD Integration](https://koxudaxi.github.io/datamodel-code-generator/ci-cd/) - GitHub Actions, pre-commit hooks
84
+ - 🚀 [One-liner Usage](https://koxudaxi.github.io/datamodel-code-generator/oneliner/) - uvx, pipx, clipboard integration
85
+ - ❓ [FAQ](https://koxudaxi.github.io/datamodel-code-generator/faq/) - Common questions
86
+
87
+ ---
88
+
89
+ ## 📦 Installation
90
+
91
+ ```bash
92
+ pip install datamodel-code-generator
93
+ ```
94
+
95
+ <details>
96
+ <summary>Other installation methods</summary>
97
+
98
+ **uv:**
99
+ ```bash
100
+ uv add datamodel-code-generator
101
+ ```
102
+
103
+ **conda:**
104
+ ```bash
105
+ conda install -c conda-forge datamodel-code-generator
106
+ ```
107
+
108
+ **With HTTP support** (for resolving remote `$ref`):
109
+ ```bash
110
+ pip install 'datamodel-code-generator[http]'
111
+ ```
112
+
113
+ **With GraphQL support:**
114
+ ```bash
115
+ pip install 'datamodel-code-generator[graphql]'
116
+ ```
117
+
118
+ **Docker:**
119
+ ```bash
120
+ docker pull koxudaxi/datamodel-code-generator
121
+ ```
122
+
123
+ </details>
124
+
125
+ ---
126
+
127
+ ## 🏃 Quick Start
128
+
129
+ ```bash
130
+ datamodel-codegen --input schema.json --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output model.py
131
+ ```
132
+
133
+ <details>
134
+ <summary>📄 schema.json (input)</summary>
135
+
136
+ ```json
137
+ {
138
+ "$schema": "http://json-schema.org/draft-07/schema#",
139
+ "title": "Pet",
140
+ "type": "object",
141
+ "required": ["name", "species"],
142
+ "properties": {
143
+ "name": {
144
+ "type": "string",
145
+ "description": "The pet's name"
146
+ },
147
+ "species": {
148
+ "type": "string",
149
+ "enum": ["dog", "cat", "bird", "fish"]
150
+ },
151
+ "age": {
152
+ "type": "integer",
153
+ "minimum": 0,
154
+ "description": "Age in years"
155
+ },
156
+ "vaccinated": {
157
+ "type": "boolean",
158
+ "default": false
159
+ }
160
+ }
161
+ }
162
+ ```
163
+
164
+ </details>
165
+
166
+ <details>
167
+ <summary>🐍 model.py (output)</summary>
168
+
169
+ ```python
170
+ # generated by datamodel-codegen:
171
+ # filename: schema.json
172
+
173
+ from __future__ import annotations
174
+
175
+ from enum import Enum
176
+ from typing import Optional
177
+
178
+ from pydantic import BaseModel, Field
179
+
180
+
181
+ class Species(Enum):
182
+ dog = 'dog'
183
+ cat = 'cat'
184
+ bird = 'bird'
185
+ fish = 'fish'
186
+
187
+
188
+ class Pet(BaseModel):
189
+ name: str = Field(..., description="The pet's name")
190
+ species: Species
191
+ age: Optional[int] = Field(None, description='Age in years', ge=0)
192
+ vaccinated: Optional[bool] = False
193
+ ```
194
+
195
+ </details>
196
+
197
+ ---
198
+
199
+ ## 📥 Supported Input
200
+
201
+ - OpenAPI 3 (YAML/JSON)
202
+ - JSON Schema
203
+ - JSON / YAML / CSV data
204
+ - GraphQL schema
205
+ - Python dictionary
206
+
207
+ ## 📤 Supported Output
208
+
209
+ - [pydantic v1](https://docs.pydantic.dev/1.10/) BaseModel
210
+ - [pydantic v2](https://docs.pydantic.dev/) BaseModel
211
+ - [dataclasses](https://docs.python.org/3/library/dataclasses.html)
212
+ - [TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict)
213
+ - [msgspec](https://github.com/jcrist/msgspec) Struct
214
+
215
+ ---
216
+
217
+ ## 🍳 Common Recipes
218
+
219
+ ### 🆕 Generate Pydantic v2 models
220
+ ```bash
221
+ datamodel-codegen --input schema.json --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output model.py
222
+ ```
223
+
224
+ ### 🌐 Generate from URL
225
+ ```bash
226
+ pip install 'datamodel-code-generator[http]'
227
+ datamodel-codegen --url https://example.com/api/openapi.yaml --input-file-type openapi --output-model-type pydantic_v2.BaseModel --output model.py
228
+ ```
229
+
230
+ ### ⚙️ Use with pyproject.toml
231
+ ```toml
232
+ [tool.datamodel-codegen]
233
+ input = "schema.yaml"
234
+ input-file-type = "openapi"
235
+ output = "src/models.py"
236
+ output-model-type = "pydantic_v2.BaseModel"
237
+ ```
238
+
239
+ See [pyproject.toml Configuration](https://koxudaxi.github.io/datamodel-code-generator/pyproject_toml/) for more options.
240
+
241
+ ### 🔄 CI/CD Integration
242
+ ```bash
243
+ datamodel-codegen --check
244
+ ```
245
+
246
+ Verify generated code stays in sync with schemas. See [CI/CD Integration](https://koxudaxi.github.io/datamodel-code-generator/ci-cd/) for GitHub Actions and pre-commit hooks.
247
+
248
+ ---
249
+
250
+ ## 💖 Sponsors
251
+
252
+ <table>
253
+ <tr>
254
+ <td valign="top" align="center">
255
+ <a href="https://github.com/astral-sh">
256
+ <img src="https://avatars.githubusercontent.com/u/115962839?s=200&v=4" alt="Astral Logo" style="width: 100px;">
257
+ <p>Astral</p>
258
+ </a>
259
+ </td>
260
+ </tr>
261
+ </table>
262
+
263
+ ---
264
+
265
+ ## 🏢 Projects that use datamodel-code-generator
266
+
267
+ These projects use datamodel-code-generator. See the linked examples for real-world usage.
268
+
269
+ - [PostHog/posthog](https://github.com/PostHog/posthog) - *[Generate models via npm run](https://github.com/PostHog/posthog/blob/e1a55b9cb38d01225224bebf8f0c1e28faa22399/package.json#L41)*
270
+ - [airbytehq/airbyte](https://github.com/airbytehq/airbyte) - *[Generate Python, Java/Kotlin, and Typescript protocol models](https://github.com/airbytehq/airbyte-protocol/tree/main/protocol-models/bin)*
271
+ - [apache/iceberg](https://github.com/apache/iceberg) - *[Generate Python code](https://github.com/apache/iceberg/blob/d2e1094ee0cc6239d43f63ba5114272f59d605d2/open-api/README.md?plain=1#L39)*
272
+ - [open-metadata/OpenMetadata](https://github.com/open-metadata/OpenMetadata) - *[datamodel_generation.py](https://github.com/open-metadata/OpenMetadata/blob/main/scripts/datamodel_generation.py)*
273
+ - [awslabs/aws-lambda-powertools-python](https://github.com/awslabs/aws-lambda-powertools-python) - *[Recommended for advanced-use-cases](https://awslabs.github.io/aws-lambda-powertools-python/2.6.0/utilities/parser/#advanced-use-cases)*
274
+ - [Netflix/consoleme](https://github.com/Netflix/consoleme) - *[Generate models from Swagger](https://github.com/Netflix/consoleme/blob/master/docs/gitbook/faq.md#how-do-i-generate-models-from-the-swagger-specification)*
275
+ - [DataDog/integrations-core](https://github.com/DataDog/integrations-core) - *[Config models](https://github.com/DataDog/integrations-core/blob/master/docs/developer/meta/config-models.md)*
276
+ - [argoproj-labs/hera](https://github.com/argoproj-labs/hera) - *[Makefile](https://github.com/argoproj-labs/hera/blob/c8cbf0c7a676de57469ca3d6aeacde7a5e84f8b7/Makefile#L53-L62)*
277
+ - [SeldonIO/MLServer](https://github.com/SeldonIO/MLServer) - *[generate-types.sh](https://github.com/SeldonIO/MLServer/blob/master/hack/generate-types.sh)*
278
+ - [geojupyter/jupytergis](https://github.com/geojupyter/jupytergis) - *[Python type generation from JSONSchema](https://jupytergis.readthedocs.io/en/latest/contributor_guide/explanation/code-generation.html)*
279
+ - [Nike-Inc/brickflow](https://github.com/Nike-Inc/brickflow) - *[Code generate tools](https://github.com/Nike-Inc/brickflow/blob/e3245bf638588867b831820a6675ada76b2010bf/tools/README.md?plain=1#L8)*
280
+ - [cloudcoil/cloudcoil](https://github.com/cloudcoil/cloudcoil) - *[Model generation](https://github.com/cloudcoil/cloudcoil#%EF%B8%8F-model-generation)*
281
+ - [IBM/compliance-trestle](https://github.com/IBM/compliance-trestle) - *[Building models from OSCAL schemas](https://github.com/IBM/compliance-trestle/blob/develop/docs/contributing/website.md#building-the-models-from-the-oscal-schemas)*
282
+ - [hashintel/hash](https://github.com/hashintel/hash) - *[codegen.sh](https://github.com/hashintel/hash/blob/9762b1a1937e14f6b387677e4c7fe4a5f3d4a1e1/libs/%40local/hash-graph-client/python/scripts/codegen.sh#L21-L39)*
283
+
284
+ [See all dependents →](https://github.com/koxudaxi/datamodel-code-generator/network/dependents)
285
+
286
+ ---
287
+
288
+ ## 🔗 Related Projects
289
+
290
+ - **[fastapi-code-generator](https://github.com/koxudaxi/fastapi-code-generator)** - Generate FastAPI app from OpenAPI
291
+ - **[pydantic-pycharm-plugin](https://github.com/koxudaxi/pydantic-pycharm-plugin)** - PyCharm plugin for Pydantic
292
+
293
+ ---
294
+
295
+ ## 🤝 Contributing
296
+
297
+ See [Development & Contributing](https://koxudaxi.github.io/datamodel-code-generator/development-contributing/) for how to get started!
298
+
299
+ ## 📄 License
300
+
301
+ MIT License - see [LICENSE](LICENSE) for details.
@@ -0,0 +1,69 @@
1
+ datamodel_code_generator/__init__.py,sha256=8ydWj15j_381BUt4-W1g7cAtSR699xzJVlqt5_gOVRg,31921
2
+ datamodel_code_generator/__main__.py,sha256=eI7KXuZQC5Nncb5gvyzRwcEZ7fJTOovlhWae-zsRsvs,42449
3
+ datamodel_code_generator/arguments.py,sha256=YA7davTZvPooCytZ7iKBBlY7ynlUEar6aUI8rv46vgc,26439
4
+ datamodel_code_generator/cli_options.py,sha256=Mb-3JqKNJobgZ2k2XapSgR7FB7p6nBn65KD9cC5W3Jk,16909
5
+ datamodel_code_generator/format.py,sha256=SA3oV8aIilXHXamMs_GiWkM51LC52vg9yPMVppz9OTM,12094
6
+ datamodel_code_generator/http.py,sha256=o9xiCbReDE0Kbped63CYRzvQqQcpbv7GIbqQH-YAZKI,2945
7
+ datamodel_code_generator/imports.py,sha256=9YocOKpGP7FfT9HlNOFOT52910xHiLuLhDVl9IdcLno,8408
8
+ datamodel_code_generator/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ datamodel_code_generator/pydantic_patch.py,sha256=xyP5VWsiLubxifzRH58mXzFMHpLfdm1nJvko6vJQDgY,967
10
+ datamodel_code_generator/reference.py,sha256=QHAB59T090EgBmfZPp1qjQjar74XhuTTJ7OrxFya_88,37658
11
+ datamodel_code_generator/types.py,sha256=qwQTaxjWvab2ls2-q0mGVXu7EU3h3Cf8fHlF7fC2428,26316
12
+ datamodel_code_generator/util.py,sha256=LxPgMVxoVLLAvFXvyof6LeyhuNVDujetoZryHQAlcvI,5042
13
+ datamodel_code_generator/watch.py,sha256=BNEmtw-jZlHVCnLrXX3tZvNROVxRitOW0RzTLs_fS_A,2307
14
+ datamodel_code_generator/model/__init__.py,sha256=guVCeAEFY9rO3nX8Hq7EchhhaiQKvkOgJ74OfQm_U5Y,5544
15
+ datamodel_code_generator/model/base.py,sha256=_wfKGvMENd70QB7obuGPGgSWU6hD-ScBggWeaKztqug,26464
16
+ datamodel_code_generator/model/dataclass.py,sha256=xVuMiYldewkP9xw56RD3xbyiMgVLl19CkB6Jdf794Bk,7808
17
+ datamodel_code_generator/model/enum.py,sha256=MBFytx131XC4sG12yUiUFYy7sxMFXPJid6hRrnFJkPk,5228
18
+ datamodel_code_generator/model/imports.py,sha256=KI8dD2bRlMaNoYUBatAkakoUSkn5p4KWHy8pFCCXPRc,1077
19
+ datamodel_code_generator/model/msgspec.py,sha256=gP40xMnJ_O9bkMIQ2o_7HrEyFwNhwmI5jyxAdrNj4BU,17884
20
+ datamodel_code_generator/model/scalar.py,sha256=uDGM6CY_cRjKZ-bf9mfkPTGsAt6gL7JX98-z86-dxNg,4117
21
+ datamodel_code_generator/model/type_alias.py,sha256=cucdSjJeJkGhohEytSmfmkBoz4K7JATfvbUMHZZOqX0,2258
22
+ datamodel_code_generator/model/typed_dict.py,sha256=KXunIeRLVbw6J0jGfeGdO5iEXmR6HE-Xs8n9xN_NzvE,5234
23
+ datamodel_code_generator/model/types.py,sha256=MIozRw_OB5Im77yUWOZAMKmqDc4cO_I0bpRJZKs4VgU,4045
24
+ datamodel_code_generator/model/union.py,sha256=6XeWOgyHYioyWv4mYyvHsz_t_JogMQxaM8EIqEsClEM,3480
25
+ datamodel_code_generator/model/pydantic/__init__.py,sha256=HzU7rnt8vo_H1Vr9bOn3F5MEUMhE4zc3qC9GubEG1Gc,1468
26
+ datamodel_code_generator/model/pydantic/base_model.py,sha256=67mXSDtArU98k4uG9Cs26VOOlQ8vuGtpasLWi19QX1U,15071
27
+ datamodel_code_generator/model/pydantic/custom_root_type.py,sha256=mHPN8Xz7ST45QpL6-vo9XdfzvNmPJ2geAn5FVa-rwvw,481
28
+ datamodel_code_generator/model/pydantic/dataclass.py,sha256=i2CaMIFFBfg-ai6Y-NWZAEZYE0IVP-YtiKHVleihbRE,603
29
+ datamodel_code_generator/model/pydantic/imports.py,sha256=Gy9_wrE2wVnbfVo2KFS9DbzKJz4giSiPpZi3LuOVjJw,2358
30
+ datamodel_code_generator/model/pydantic/types.py,sha256=zVr8sbxbpTw-QMOKJDxRGimtPic5bmVbn9eFHpeKKCA,14838
31
+ datamodel_code_generator/model/pydantic_v2/__init__.py,sha256=f427nMH590gi6Z7T7oCD8uz9mxOwJ8a9RhE7L0W83d8,1684
32
+ datamodel_code_generator/model/pydantic_v2/base_model.py,sha256=jfmDIu226Sj94ceWgaQZxq__FMK43K3j_uhSzFu0zas,9488
33
+ datamodel_code_generator/model/pydantic_v2/imports.py,sha256=xXY11oGoSicwubKDjXGMJAf9a7PlwEoxUNY2JYcts-Q,674
34
+ datamodel_code_generator/model/pydantic_v2/root_model.py,sha256=IjMY1jgoyH2FB7olGhsZGvOFERPSII2VxtLGwsq3YkA,1144
35
+ datamodel_code_generator/model/pydantic_v2/types.py,sha256=3M5ppMsEmbZXKy--OoBz3Ft1fPLTZ2wwxsTI_B4u6GY,5820
36
+ datamodel_code_generator/model/template/Enum.jinja2,sha256=ozInIGLh2mN7QxsehAIfD0Txt-UncxYVY-_xTHjNgCU,575
37
+ datamodel_code_generator/model/template/ScalarTypeAliasAnnotation.jinja2,sha256=k-kpTD10HHzdqRfUDTf8BnBrbO6pqIVWCF4sbN-rLqA,105
38
+ datamodel_code_generator/model/template/ScalarTypeAliasType.jinja2,sha256=tYeLmWniac__yAKifv2OinkOTyMvepqMY4CzfsqwALk,129
39
+ datamodel_code_generator/model/template/ScalarTypeStatement.jinja2,sha256=6Cy5PgYFFGki-evwukIL14qxN1aiw_E4TzHD9A2Zb1g,98
40
+ datamodel_code_generator/model/template/TypeAliasAnnotation.jinja2,sha256=DLV0KXOcykUD9htvlbisc95USesabowkYeka7h_h_ZU,525
41
+ datamodel_code_generator/model/template/TypeAliasType.jinja2,sha256=SFPPnZJdvHxDlKGuCp_6ejF6_-y6qCYtr4mY3YsXQr8,549
42
+ datamodel_code_generator/model/template/TypeStatement.jinja2,sha256=95iURuCy0xgJ6TJOuCOabUG29qrecaxnhvMDvhZUWFA,518
43
+ datamodel_code_generator/model/template/TypedDict.jinja2,sha256=J_Pe_CiuvTOb-EUCExXPaeTEFzn2keyrKB0wglZ8HgA,135
44
+ datamodel_code_generator/model/template/TypedDictClass.jinja2,sha256=mtkEKvB9Y4Ly-fEr2QxY9YS73QTiWe9ud81zVeLbYf0,574
45
+ datamodel_code_generator/model/template/TypedDictFunction.jinja2,sha256=f3mzkrleeizPVeNatwzJ_tzjQV7t37NIpgBSlJM5MCE,518
46
+ datamodel_code_generator/model/template/UnionTypeAliasAnnotation.jinja2,sha256=kXpUZ3-qnvcYugqJPluiZysX-0xyspbHjbTSc5NaMtM,291
47
+ datamodel_code_generator/model/template/UnionTypeAliasType.jinja2,sha256=AEGisoKISFzRt4GfAd01IkHvcpzDInHCMvTqO1PzBaU,331
48
+ datamodel_code_generator/model/template/UnionTypeStatement.jinja2,sha256=VLuo9SrHzbL0ransNjktS5ORb4aLlFegiNsOdk0XOQo,270
49
+ datamodel_code_generator/model/template/dataclass.jinja2,sha256=ePUxwEXM89oopciASPnVjHLG-xBn4tx9Kp4f7t9wtXo,1300
50
+ datamodel_code_generator/model/template/msgspec.jinja2,sha256=8E-RFfise2VyV6trEwxmDszF8hJNcIYPHa-oyjnr5FU,1742
51
+ datamodel_code_generator/model/template/pydantic/BaseModel.jinja2,sha256=vbBUDZruXPtcu8QG-i7jzAkki33sitdj6twkpQqcJEM,1324
52
+ datamodel_code_generator/model/template/pydantic/BaseModel_root.jinja2,sha256=y7VuOGELGk_vMQ_-vQEoPPBK5AuhGoB-r0i9O8hFJ94,1128
53
+ datamodel_code_generator/model/template/pydantic/Config.jinja2,sha256=Ik028qdqQhDfEP207TCbwVv2b5Do1-nRNDPKzBHKzwM,135
54
+ datamodel_code_generator/model/template/pydantic/dataclass.jinja2,sha256=Tby_Zz1Tqy43uJIkhP355S44NMKs19-K5Lb2Pybu5nA,826
55
+ datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2,sha256=nm7u6GORm42pN0V0bRUyz2mwa7mKnO_dsVrx7jVwTis,1703
56
+ datamodel_code_generator/model/template/pydantic_v2/ConfigDict.jinja2,sha256=xHvBYrh__32O1xRCSl6_u5zbyYIjB8a5k8fZiTo0spY,149
57
+ datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2,sha256=lZu0ShsPoiSw2ciwJ0pMFv78yFAXnbycn2VH7JL6K08,1351
58
+ datamodel_code_generator/parser/__init__.py,sha256=Tr-2b8A59J-e-Yap0XttWIbA80dsiA6sRoj7LovaKSI,1232
59
+ datamodel_code_generator/parser/_graph.py,sha256=WDVJJdAo6xa-o7voWLN-dzXbczQoBkn6Ug7XD9ApPfw,2193
60
+ datamodel_code_generator/parser/_scc.py,sha256=ELXFsJW86P11qNBil4v-irdWIUJ9rHhjVtkNMR1bIrc,5840
61
+ datamodel_code_generator/parser/base.py,sha256=s3qIsxOZY33u8Ze80wxKBdsgh_GMJ3dyqSTngDfLXh0,121520
62
+ datamodel_code_generator/parser/graphql.py,sha256=hriEbSYbHLzWKBhv_JtLA1MyviriPrYoDdW6phVsYk0,29663
63
+ datamodel_code_generator/parser/jsonschema.py,sha256=lXqMPEHbNhfgTzY6k_Nc5jir3GBaKtzpn1yMKTDDWIE,138641
64
+ datamodel_code_generator/parser/openapi.py,sha256=9v3l099xvclVs6MJIAc5tHvYfl1LXMxvWKpsF5Ny-QM,37124
65
+ datamodel_code_generator-0.45.0.dist-info/METADATA,sha256=6r4SiIQmqU7sn5yStEtJAs8l38vQmgrS-9fQnJ1P7F4,11658
66
+ datamodel_code_generator-0.45.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
67
+ datamodel_code_generator-0.45.0.dist-info/entry_points.txt,sha256=cJVcHiEViQMANaoM5C1xR5hzmyCqH6hHHMpV8W00in8,77
68
+ datamodel_code_generator-0.45.0.dist-info/licenses/LICENSE,sha256=K54Lwc6_jduycsy8oFFjQEeSSuEiqvVIjCGIXOMnuTQ,1068
69
+ datamodel_code_generator-0.45.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry 1.0.4
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ datamodel-codegen = datamodel_code_generator.__main__:main
@@ -1 +0,0 @@
1
- version: str = '0.11.12'