DATAMODEL-CODEGEN(1)

πŸ“¦
version 0.71.0 Β· 3 versions
, in ubuntu stonking

πŸ‘‘ DATAMODEL-CODEGEN(1) πŸ‘‘

okay bestie, sit down, drink your water πŸ“ β€” this is a User Commands manual page, and it's about to be the most thorough thing you've ever read. It's datamodel-codegen, and I'm gonna walk you through literally every flag like we're doing a group project and I refuse to let you fail. No skips. No vibes-based summarising. Periodt. πŸ’…


🌸 NAME 🌸

datamodel-codegen β€” pydantic code generator from OpenAPI and more ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

✨ usage ✨

datamodel-codegen [options]

Generate Python data models from schema definitions or structured data. fr fr that's the whole job description and it ate. πŸ”₯

For detailed usage, see: https://datamodel-code-generator.koxudaxi.dev


πŸŽ€ OPTIONS πŸŽ€

okay so this is the part everyone skips and it's honestly the best part. buckle up. there are so many of these and I love them all equally. πŸ’–

  • --additional-imports ADDITIONAL_IMPORTS β€” custom imports you want slapped into the output (it's a delimited list input, so you can hand over a bunch at once). for example "datetime.date,datetime.datetime".
  • --allow-private-network, --no-allow-private-network β€” lets your HTTP(S) schema requests hit private, loopback, link-local, or otherwise non-public network hosts. by default those targets are blocked, lowkey on purpose, to reduce serverside request forgery (SSRF) risk. so if a trusted internal schema endpoint is getting blocked: verify the URL, then pass this option. otherwise? just use a local schema file or a public endpoint, bestie. and if a config file already enables it and you want it gone, pass --no-allow-privatenetwork to override it.
  • --allow-remote-refs, --no-allow-remote-refs β€” allows fetching remote $ref references over HTTP/HTTPS. currently remote fetching is allowed by default BUT it emits a deprecation warning (🚨 yes, really). pass --allow-remote-refs to opt in without the warning, or --no-allow-remote-refs to block remote fetching entirely. heads up: in a future version, remote fetching will be disabled by default. future you has been warned πŸ’€
  • --class-decorators CLASS_DECORATORS β€” custom decorators for your generated model classes (delimited list input, again). for example "@dataclass_json(letter_case=LetterCase.CAMEL)". the "@" prefix is optional and will be added automatically if you forget it, because it loves you. 🫢
  • --custom-formatters CUSTOM_FORMATTERS β€” list of modules with a custom formatter (delimited list input).
  • --emit-model-metadata EMIT_MODEL_METADATA β€” write a separate JSON map that goes from source schema references β†’ the generated models and fields. receipts, but make them machine-readable. 🧾
  • --external-ref-mapping FILE_PATH=PYTHON_PACKAGE [FILE_PATH=PYTHON_PACKAGE ...] β€” map external $ref file paths to Python import packages instead of generating duplicate classes (iconic behaviour, honestly). accepts one or more mappings after a single flag. format: "path/to/schema.yaml=mypackage.models". when a $ref points to a mapped file, you get an import statement generated instead of a class definition.
  • --formatters {builtin,black,isort,ruff-check,ruff-format} [{builtin,black,isort,ruff-check,ruff-format} ...] β€” formatters for the output (default: [black, isort]; use builtin if you want dependency-free formatting). πŸ’…
  • --http-headers HTTP_HEADER [HTTP_HEADER ...] β€” set headers on HTTP requests to the remote host. (example: "Authorization: Basic dXNlcjpwYXNz")
  • --http-ignore-tls β€” disable verification of the remote host's TLS certificate.
  • --http-local-ref-path HTTP_LOCAL_REF_PATH β€” resolve HTTP(S) JSON Schema $ref URLs from a local directory instead of fetching them. URLs get mapped under the directory by host and path; extensionless refs also try '.json'. sneaky and helpful. πŸ”
  • --http-query-parameters HTTP_QUERY_PARAMETERS [HTTP_QUERY_PARAMETERS ...] β€” set query parameters on HTTP requests to the remote host. (example: "ref=branch")
  • --http-timeout HTTP_TIMEOUT β€” timeout in seconds for HTTP requests to remote hosts (default: 30).
  • --input INPUT β€” input file/directory (default: stdin).
  • --input-file-type {auto,openapi,asyncapi,jsonschema,mcp-tools,xmlschema,protobuf,avro,json,yaml,dict,csv,graphql} β€” input file type (default: auto). use 'jsonschema', 'openapi', 'asyncapi', 'graphql', 'mcp-tools', 'xmlschema', 'protobuf', or 'avro' for schema definitions. use 'json', 'yaml', or 'csv' for raw sample data and it'll infer a schema automatically. it's giving mind-reading ✨
  • --input-model MODULE_OR_PATH:NAME β€” Python import path or file path to a Pydantic v2 model or schema dict (e.g., 'mypackage.module:ClassName', './models.py:ClassName', or 'mypackage.schemas:SCHEMA_DICT'). can be specified multiple times for related models with inheritance. for dict input, --input-file-type is required. cannot be used with --input or --url.
  • --input-model-ref-strategy {regenerate-all,reuse-foreign,reuse-all} β€” strategy for referenced types in --input-model. 'regenerate-all': regenerate all types. 'reuseforeign': reuse types from different families (Enum, etc.), regenerate same-family. 'reuse-all': reuse all referenced types via import. if you don't specify anything, it defaults to regenerate-all behavior.
  • --output OUTPUT β€” output file (default: stdout).
  • --output-model-type {pydantic_v2.BaseModel,pydantic_v2.dataclass,dataclasses.dataclass,typing.TypedDict,msgspec.Struct} β€” output model type (default: pydantic_v2.BaseModel).
  • --preset {standard-py310-20260619,standard-py311-20260619,standard-py312-20260619,standard-py313-20260619,standard-py314-20260619,practical-py310-20260619,practical-py311-20260619,practical-py312-20260619,practical-py313-20260619,practical-py314-20260619} β€” apply an immutable built-in option preset. the preset names include the target Python version so your generated syntax is pinned. locked in. πŸ”’
  • --schema-version SCHEMA_VERSION β€” schema version. valid values depend on input type: JsonSchema: auto, draft-04, draft-06, draft-07, 2019-09, 2020-12. OpenAPI: auto, 3.0, 3.1, 3.2. AsyncAPI: auto, 2.0, 3.0. XMLSchema: auto, 1.0, 1.1. Protobuf: auto, proto2, proto3, 2023. (default: auto β€” detected from $schema, openapi/asyncapi field, XML Schema versioning attributes, or Protobuf syntax/edition)
  • --schema-version-mode {lenient,strict} β€” schema version validation mode. 'lenient': accept all features regardless of version (default). 'strict': warn on features outside the declared/detected version. strict is the friend who actually reads the syllabus. πŸ‘€
  • --strict-refs β€” treat unresolved local $ref JSON pointers as errors instead of generating fallback Any models. no silent coping allowed.
  • --url URL β€” input file URL. --input is ignored when --url is used.

πŸ’œ Typing customization πŸ’œ

this is the glow-up section. it's where you make your generated types exactly what you want them to be. obsessed. πŸ’–

  • --allof-class-hierarchy {if-no-conflict,always} β€” how to map allOf references to class hierarchies. 'ifno-conflict': only create subclasses when the parent class has no conflicting property definition. 'always': always create subclasses.
  • --allof-merge-mode {constraints,all,none} β€” mode for field merging in allOf schemas. 'constraints': merge only constraints (minItems, maxItems, pattern, etc.) from the parent (default). 'all': merge constraints plus annotations (default, examples) from the parent (default, examples). 'none': do not merge any fields from parent properties.
  • --base-class BASE_CLASS β€” base Class (default: pydantic.BaseModel).
  • --base-class-map BASE_CLASS_MAP β€” model-specific base class mapping (JSON or JSON file path). example: '{"MyModel": "custom.BaseA", "OtherModel": "custom.BaseB"}'. priority: base-classmap > customBasePath (in schema) > base-class. the hierarchy is real, respect the hierarchy. πŸ‘‘
  • --disable-future-imports β€” disable __future__ imports.
  • --enum-field-as-literal {all,one,none} β€” parse enum field as literal. all: all enum field types are Literal. one: field type is Literal when an enum has only one possible value. none: always use an Enum class (never convert to Literal).
  • --enum-field-as-literal-map ENUM_FIELD_AS_LITERAL_MAP β€” per-field override for enum/literal generation (JSON or JSON file path). format: JSON object mapping field names to 'literal' or 'enum'. example: '{"status": "literal", "priority": "enum"}'. overrides --enumfield-as-literal for matched fields.
  • --field-constraints β€” use field constraints and not con* annotations.
  • --ignore-enum-constraints β€” ignore enum constraints and use the base type (e.g., str, int) instead of generating Enum classes. sometimes you just want the plain thing, and that's valid. πŸ“
  • --set-default-enum-member β€” set enum members as default values for the enum field.
  • --strict-types {str,bytes,int,float,bool} [{str,bytes,int,float,bool} ...] β€” use strict types.
  • --type-mappings TYPE_MAPPINGS [TYPE_MAPPINGS ...] β€” override default type mappings. format: "type+format=target" (e.g., "string+binary=string" to map binary format to string type) or "format=target" (e.g., "binary=string"). can be specified multiple times. πŸ’…
  • --type-overrides TYPE_OVERRIDES β€” replace schema model types with custom Python types. format: JSON object mapping model names to Python import paths. model-level: '{"CustomType": "my_app.types.MyType"}' replaces all references. scoped: '{"User.field": "my_app.Type"}' replaces that specific field only. precision, bestie. 🎯
  • --use-annotated, --no-use-annotated β€” use typing.Annotated for Field(). also, the --fieldconstraints option will be enabled. will become default for Pydantic v2 in a future version. ⚠️
  • --use-closed-typed-dict, --no-use-closed-typed-dict β€” generate TypedDict with PEP 728 closed=True/extra_items for additionalProperties constraints. use --no-use-closed-typed-dict for type checkers that don't yet support PEP 728 (e.g., mypy). be nice to mypy, it's trying.
  • --use-decimal-for-multiple-of β€” use condecimal instead of confloat for float/number fields with a multipleOf constraint (Pydantic only). avoids floating-point precision issues in validation. no more 0.30000000000000004 jumpscare πŸ™ˆ
  • --use-enum-values-in-discriminator β€” use enum member literals in discriminator fields instead of string literals.
  • --use-generic-container-types β€” use generic container types for type hinting (typing.Sequence, typing.Mapping). if the --use-standardcollections option is set, then import from collections.abc instead of typing.
  • --use-non-positive-negative-number-constrained-types β€” use the Non{Positive,Negative}{FloatInt} types instead of the corresponding con* constrained types.
  • --use-object-type β€” use object instead of Any for unspecified JSON Schema object and array values.
  • --use-one-literal-as-default β€” use one literal as the default value for a one-literal field.
  • --use-root-model-type-alias β€” use type alias format for RootModel (e.g., Foo = RootModel[Bar]) instead of class inheritance (Pydantic v2 only).
  • --use-serialize-as-any β€” use pydantic.SerializeAsAny for fields with types that have subtypes (Pydantic v2 only).
  • --use-specialized-enum, --no-use-specialized-enum β€” use specialized Enum class (StrEnum, IntEnum). requires --target-python-version 3.11+ 🚨
  • --use-standard-collections, --no-use-standard-collections β€” uses standard collections for type hinting (list, dict) πŸ’… Default: enabled ✨
  • --use-subclass-enum β€” defines the generic Enum class as a subclass with a field type when the enum has a type (int, float, bytes, str)
  • --use-tuple-for-fixed-items β€” generates tuple types for arrays with the items-array syntax when minItems equals maxItems equals the items length 🎯
  • --use-type-alias β€” uses TypeAlias instead of root models (experimental πŸ‘€)
  • --use-union-operator, --no-use-union-operator β€” uses the | operator for the Union type (PEP 604). Default: enabled 🌈
  • --use-unique-items-as-set β€” defines the field type as set when the field attribute has uniqueItems πŸ“

πŸŽ€ Field customization: πŸŽ€

  • --capitalise-enum-members, --capitalize-enum-members β€” capitalizes field names on the enum πŸ”₯
  • --empty-enum-field-name EMPTY_ENUM_FIELD_NAME β€” sets the field name when the enum value is empty (default: _)
  • --field-extra-keys FIELD_EXTRA_KEYS [FIELD_EXTRA_KEYS ...] β€” adds extra keys to the field parameters
  • --field-extra-keys-without-x-prefix FIELD_EXTRA_KEYS_WITHOUT_X_PREFIX [FIELD_EXTRA_KEYS_WITHOUT_X_PREFIX ...] β€” adds extra keys with the x- prefix to field parameters. The extra keys are stripped of the x- prefix, no cap πŸ’…
  • --field-include-all-keys β€” adds all the keys to field parameters
  • --field-type-collision-strategy {rename-field,rename-type} β€” strategy for handling collisions between a field name and a type name (Pydantic v2 only). 'rename-field': rename the field with a suffix and add an alias (default). 'renametype': rename the type class with a suffix to preserve the field name.
  • --force-optional β€” forces required fields to be optional πŸ‘€
  • --model-extra-keys MODEL_EXTRA_KEYS [MODEL_EXTRA_KEYS ...] β€” adds extra keys from schema extensions (x-* fields) to model_config json_schema_extra
  • --model-extra-keys-without-x-prefix MODEL_EXTRA_KEYS_WITHOUT_X_PREFIX [MODEL_EXTRA_KEYS_WITHOUT_X_PREFIX ...] β€” adds extra keys with the x- prefix to model_config json_schema_extra. The extra keys are stripped of the x- prefix.
  • --no-alias β€” does not add a field alias. E.g. if --snake-case-field is used along with a base class that has an alias_generator
  • --original-field-name-delimiter ORIGINAL_FIELD_NAME_DELIMITER β€” sets the delimiter used to convert to snake case. Bestie, this option only can be used with --snake-case-field (default: _ )
  • --remove-special-field-name-prefix β€” removes the field name prefix if it has a special meaning, e.g. underscores
  • --serialization-aliases SERIALIZATION_ALIASES β€” serialization alias mapping as inline JSON or a JSON file path, for Pydantic v2. Format: {'<schema_field>': '<serialization_alias>'}. Supports hierarchical formats: Flat: {'name': 'fullName'} applies to all occurrences. Scoped: {'User.name': 'fullName'} applies to a specific class. ✨
  • --snake-case-field, --no-snake-case-field β€” changes a camel-case field name to snake-case 🐍
  • --special-field-name-prefix SPECIAL_FIELD_NAME_PREFIX β€” sets the field name prefix when the first character can't be used as a Python field name (default: field)
  • --strict-nullable β€” treats a default field as a non-nullable field
  • --strip-default-none β€” strips default None on fields
  • --union-mode {smart,left_to_right} β€” union mode, for pydantic v2 fields only
  • --use-attribute-docstrings β€” sets use_attribute_docstrings=True in the Pydantic v2 ConfigDict
  • --use-default β€” uses the default value even if a field is required
  • --use-default-factory-for-optional-nested-models β€” uses default_factory for optional nested model fields instead of a None default. E.g. field: Model | None = Field(default_factory=Model) instead of field: Model | None = None
  • --use-default-kwarg β€” uses default= instead of a positional argument for Fields that have default values.
  • --use-field-description β€” uses the schema description to populate the field docstring
  • --use-field-description-example β€” uses the schema example to populate the field docstring
  • --use-frozen-field, --no-use-frozen-field β€” uses Field(frozen=True) for readOnly fields (Pydantic v2). πŸ₯Ά
  • --use-inline-field-description β€” uses the schema description to populate the field docstring as an inline docstring
  • --use-missing-sentinel β€” uses pydantic.experimental.missing_sentinel.MISSING for optional fields without defaults (Pydantic v2.12+).
  • --use-serialization-alias β€” uses serialization_alias instead of alias for field aliasing (Pydantic v2 only). This lets you set values using the Pythonic field name while serializing to the original name. πŸ’…
  • --use-single-line-docstring β€” uses single-line docstrings when the content fits on one line

πŸ‘‘ Model customization: πŸ‘‘

  • --alias-generator {to_camel,to_pascal,to_snake} β€” the Pydantic v2 BaseModel alias generator to use in ConfigDict. Matching generated aliases are omitted from individual Field() calls.
  • --all-exports-collision-strategy {error,minimal-prefix,full-prefix} β€” strategy for name collisions when using --all-exportsscope=recursive. 'error': raise an error (default). 'minimal-prefix': add the module prefix only to colliding names. 'full-prefix': add the full module path prefix to colliding names.
  • --all-exports-scope {children,recursive} β€” generates __all__ in __init__.py with re-exports. 'children': export from direct child modules only. 'recursive': export from all descendant modules.
  • --allow-extra-fields β€” Deprecated 🚨: --allow-extra-fields is deprecated. Use --extra-fields=allow instead.
  • --allow-leading-underscore-class-name β€” allows an explicitly specified root class name to start with an underscore
  • --allow-population-by-field-name, --no-allow-population-by-field-name β€” allows population by field name
  • --class-name CLASS_NAME β€” sets the class name of the root model
  • --class-name-affix-scope {all,models,enums} β€” scope for applying --class-name-prefix/--class-namesuffix. 'all': applies to all classes including enums (default). 'models': applies only to model classes. 'enums': applies only to enum classes.
  • --class-name-prefix CLASS_NAME_PREFIX β€” prefix to add to generated class names (e.g. 'Api' produces 'ApiUser'). Doesn't apply to the root model when --class-name is specified.
  • --class-name-suffix CLASS_NAME_SUFFIX β€” suffix to add to generated class names (e.g. 'Schema' produces 'UserSchema'). Doesn't apply to the root model when --class-name is specified.
  • --collapse-reuse-models β€” when used with --reuse-model, collapses duplicate models by replacing references instead of creating empty inheritance subclasses. This eliminates 'class Foo(Bar): pass' patterns
  • --collapse-root-models, --no-collapse-root-models β€” models generated with a root-type field get merged into the models using that root-type model
  • --collapse-root-models-name-strategy {child,parent} β€” naming strategy when collapsing root models that reference other models. 'child': keep the inner model's name (default). 'parent': use the wrapper's name for the inner model. Requires --collapse-root-models to be set.
  • --dataclass-arguments DATACLASS_ARGUMENTS β€” custom dataclass arguments as a JSON dictionary, e.g. '{"frozen": true, "kw_only": true}'. Overrides --frozen-dataclasses and similar flags.
  • --disable-appending-item-suffix β€” disables appending the Item suffix to the model name in an array
  • --disable-timestamp β€” disables the timestamp on file headers
  • --duplicate-name-suffix DUPLICATE_NAME_SUFFIX β€” JSON mapping of type to suffix for resolving duplicate name conflicts. Example: '{"model": "Schema"}' changes Address1 to AddressSchema. Keys: 'model' (for classes), 'enum' (for enums), 'default' (fallback). When not specified, uses a numeric suffix (Address1, Address2).
  • --enable-command-header β€” enables command-line options on file headers for reproducibility
  • --enable-faux-immutability β€” enables faux immutability
  • --enable-generated-header-marker β€” enables the @generated marker on file headers
  • --enable-version-header β€” enables the package version on file headers
  • --extra-fields {allow,ignore,forbid} β€” sets the generated models to allow, forbid, or ignore extra fields.
  • --frozen-dataclasses β€” generates frozen dataclasses (dataclass(frozen=True)). Only applies to dataclass output. πŸ₯Ά
  • --infer-union-variant-names β€” infers inline oneOf/anyOf branch model names from literal discriminator-style fields
  • --keep-model-order β€” keeps the generated models' order
  • --keyword-only β€” defines models as keyword only (for example dataclass(kw_only=True)).
  • --model-name-map MODEL_NAME_MAP β€” renames generated model classes by schema ref or current generated class name, using a JSON object or JSON file.
  • --module-split-mode {single} β€” splits generated models into separate files. 'single': generate one file per model class.
  • --naming-strategy {numbered,parent-prefixed,full-path,primary-first} β€” strategy for generating unique model names when duplicates occur. 'numbered' (default): append a numeric suffix (Address, Address1, Address2). Simple but the names don't indicate context. 'parent-prefixed': prefix with the parent model name using an underscore (Company_Address, Company_Employee_Address for nested). Names show hierarchy. 'full-path': similar to parent-prefixed but joins with CamelCase (CompanyAddress, CompanyEmployeeAddress). More readable for deep nesting. 'primary-first': keep clean names for primary definitions (in /definitions/ or /components/schemas/), and only add a suffix to inline/nested duplicates.
  • --output-date-class {date,PastDate,FutureDate} β€” choose the Date class between PastDate, FutureDate or date. (Pydantic v2 only) Each output model has its default mapping.
  • --output-datetime-class {datetime,AwareDatetime,NaiveDatetime,PastDatetime,FutureDatetime} β€” choose the Datetime class between AwareDatetime, NaiveDatetime, PastDatetime, FutureDatetime or datetime. Each output model has its default mapping (for example pydantic: datetime, dataclass: str, ...)
  • --parent-scoped-naming β€” bestie this one's deprecated 😭 do not start here. Use --naming-strategy parent-prefixed instead, she's the upgraded version πŸ’…
  • --reuse-model β€” reuse models on the field when a module already has a model with the same content. Recycling but make it ✨codegen✨
  • --reuse-scope {module,tree} β€” the scope for model reuse deduplication: module = per-file (that's the default, btw) or tree = cross-file with a shared module. Heads up: this only does anything when --reuse-model is set. No --reuse-model, no vibes πŸ¦‹
  • --shared-module-name SHARED_MODULE_NAME β€” the name of the shared module for --reuse-scope=tree (default: "shared"). Use this option if your schema has a file named "shared" so nothing gets messy πŸŽ€
  • --skip-root-model β€” skip generating the model for the root schema element. Root? Never met her πŸ™ˆ
  • --strict-dotted-module-names, --no-strict-dotted-module-names β€” only infer dotted schema names as module paths when every single segment is a canonical Python identifier. Fr fr this one applies only to automatic inference and it does not override --treat-dot-as-module or --no-treat-dot-asmodule.
  • --target-pydantic-version {2,2.11,2.12} β€” the Pydantic version your generated code is aimed at πŸ‘‘
    • 2: Pydantic 2.0+ compatible (default, uses populate_by_name)
    • 2.11: Pydantic 2.11+ (uses validate_by_name)
    • 2.12: Pydantic 2.12+ (supports MISSING sentinel)
  • --target-python-version {3.10,3.11,3.12,3.13,3.14} β€” target python version. Pick your girl 🫢
  • --treat-dot-as-module, --no-treat-dot-as-module β€” treat dotted schema names as module paths, creating nested directory structures (so foo.bar.Model becomes foo/bar.py). Use --no-treat-dot-as-module to keep dots in names as underscores for single-file output 🐍
  • --use-exact-imports β€” import exact types instead of modules, like: from .foo import Bar instead of from . import foo with foo.Bar. Chef's kiss precision 🎯
  • --use-generic-base-class β€” generate a shared base class with model configuration (e.g. extra='forbid') instead of repeating that config in each model. Keeps code DRY. Iconic, no notes πŸ’…
  • --use-pendulum β€” use pendulum instead of datetime πŸ•°οΈ
  • --use-root-model-sequence-interface β€” make non-null sequence-like Pydantic v2 RootModel classes implement collections.abc.Sequence by adding Sequence[T] inheritance and root-delegating __iter__, __getitem__, and __len__ methods. She's SO fancy 🧚
  • --use-schema-description β€” use schema description to populate the class docstring πŸ“
  • --use-standard-primitive-types, --no-use-standard-primitive-types β€” use Python standard library types for string formats (UUID, IPv4Address, etc.) instead of str. Affects dataclass, msgspec, TypedDict output. Pydantic already uses these types by default, so she's ahead of the game ⭐
  • --use-title-as-name β€” use titles as class names of models. Main character naming rights πŸ‘‘

πŸŽ€ Template customization πŸŽ€

  • --aliases ALIASES β€” alias mapping as inline JSON or a JSON file path for renaming fields. Format: {'<schema_field>': '<python_name>'} β€” the schema field name becomes the Pydantic alias. Supports hierarchical formats: Flat: {'id': 'id_'} applies to all occurrences. Scoped: {'User.name': 'user_name'} applies to a specific class. Priority: scoped > flat. Multiple aliases (Pydantic v2 only): {'field': ['alt1', 'alt2']} uses AliasChoices for validation. Example: {'User.name': 'user_name', 'id': 'id_'} generates id_: ... = Field(alias='id'). 😌
  • --custom-file-header CUSTOM_FILE_HEADER β€” custom file header ✨
  • --custom-file-header-mode {replace,prepend} β€” how to combine a custom file header with the generated header (default: replace) πŸ¦‹
  • --custom-file-header-path CUSTOM_FILE_HEADER_PATH β€” custom file header file path πŸ“
  • --custom-formatters-kwargs CUSTOM_FORMATTERS_KWARGS β€” custom formatter kwargs as inline JSON or a JSON file path.
  • --custom-template-dir CUSTOM_TEMPLATE_DIR β€” custom template directory 🧡
  • --default-values DEFAULT_VALUES β€” default value overrides as inline JSON or a JSON file path. Supports hierarchical formats: Flat: {'field': value} applies to all occurrences. Scoped: {'ClassName.field': value} applies to a specific class. Priority: scoped > flat. Note: scoped keys use the generated class name for JSON Schema/OpenAPI. Required fields stay required unless --use-default is also specified. Example: {'User.status': 'active', 'page': 1, 'limit': 10} πŸ’œ
  • --encoding ENCODING β€” the encoding of input and output (default: utf-8) 🌈
  • --extra-template-data EXTRA_TEMPLATE_DATA β€” extra template data for output models as inline JSON or a JSON file path. For OpenAPI and Jsonschema the keys are the spec path of the object, or the name of the object if you want to apply the template data to multiple objects with the same name. If you're using another input file type (e.g. GraphQL), the key is the name of the object. The value is a dictionary of the template data to add πŸ“
  • --generate-schema-validators β€” generate Pydantic v2 model validators for JSON Schema rules that can't be represented as type hints (experimental). ⚠️
  • --schema-validator-base-class-name SCHEMA_VALIDATOR_BASE_CLASS_NAME β€” set the generated shared Pydantic v2 schema runtime validator base class name.
  • --schema-validator-type {pydantic-v2} β€” select the schema-derived runtime validator backend. 'pydantic-v2' generates Pydantic v2 model validators (experimental). ⚠️
  • --use-double-quotes β€” model generated with double quotes. Single quotes, or your black config skip_string_normalization value, will be used without this option. Pick a quote and commit bestie πŸŽ€
  • --use-type-checking-imports, --no-use-type-checking-imports β€” allow Ruff to move typing-only imports into TYPE_CHECKING blocks. By default this stays enabled, except for multi-module Ruff formatting of modular Pydantic output where referenced models stay imported at runtime. Use --no-use-type-checking-imports to force runtime imports πŸ”₯
  • --validators VALIDATORS β€” validators configuration as inline JSON or a JSON file path. Defines field validators for Pydantic v2 models. Keys are model names, values contain validator definitions with field, function, and mode.
  • --wrap-string-literal β€” wrap string literal by using black experimentalstring-processing option (require black 20.8b0 or later) 🧚

🌸 OpenAPI-only options 🌸

  • --include-path-parameters β€” include path parameters in generated parameter models in addition to query parameters (Only OpenAPI) πŸ›£οΈ
  • --openapi-include-info-version β€” emit OpenAPI info.version as OPENAPI_INFO_VERSION in generated models.
  • --openapi-include-paths PATTERN [PATTERN ...] β€” include only OpenAPI paths matching fnmatch patterns. Use wildcards: '*' matches any chars, '?' matches a single char. Example: '/users/*' '/products'. Requires '--openapi-scopes' to include 'paths'. πŸ”
  • --openapi-scopes {schemas,paths,tags,parameters,webhooks,requestbodies} [{schemas,paths,tags,parameters,webhooks,requestbodies} ...] β€” scopes of OpenAPI model generation (default: schemas).
  • --read-only-write-only-model-type {request-response,all} β€” model generation for readOnly/writeOnly fields: 'request-response' = Request/Response models only (no base model), 'all' = Base + Request + Response models. πŸ’…
  • --use-operation-id-as-name β€” use operation id of OpenAPI as class names of models.
  • --use-status-code-in-response-name β€” include HTTP status code in response model names (e.g., ResourceGetResponse200, ResourceGetResponseDefault) πŸ“Ÿ
  • --validation β€” Deprecated: the --validation option is deprecated and will be removed in a future release. Use --fieldconstraints instead. Don't get attached 😭

πŸ¦‹ GraphQL-only options πŸ¦‹

  • --graphql-no-typename β€” exclude __typename field from generated GraphQL models. Useful when using generated models for GraphQL mutations. Bye bye __typename πŸ‘‹

πŸ‘‘ General options πŸ‘‘

  • --check β€” verify generated files are up-to-date without modifying them. Exits with code 1 if differences are found, 0 if up-to-date. Useful for CI to ensure generated code is committed. Your CI bestie fr fr βœ…
  • --debug β€” show debug message (require "debug". $ pip install 'datamodel-code-generator[debug]') πŸ›
  • --disable-warnings β€” disable warnings. Ignorance is bliss ✨
  • --fail-on-multi-module-stdout β€” return an error instead of concatenating multiple generated modules in text stdout. This does not affect single-module, JSON, or file output.
  • --generate-cli-command β€” generate CLI command from pyproject.toml configuration and exit ⚑
  • --generate-prompt [QUESTION] β€” generate a prompt for consulting LLMs about CLI options. Optionally provide your question as an argument. Pipe to CLI tools (e.g., | claude -p, | codex exec) or copy to clipboard (e.g., | pbcopy, | xclip) for web LLM chats πŸ€–
  • --generate-pyproject-config β€” generate pyproject.toml configuration from the provided CLI arguments and exit πŸ“
  • --ignore-pyproject β€” ignore pyproject.toml configuration πŸ™ˆ
  • --list-deprecations [{table,json,markdown}] β€” list registered deprecations and scheduled breaking changes, then exit πŸ’€
  • --list-experimental [{table,json,markdown}] β€” list registered experimental features, then exit πŸ§ͺ
  • --no-color β€” disable colorized output. Monochrome moment πŸ–€
  • --output-format {text,json} β€” format for command output (default: text). Use json for structured output when supported.
  • --output-format-json-schema {config,generate-prompt,generation,model-metadata,structured-output} β€” output JSON Schema for the selected JSON output or JSON configuration format and exit πŸ“‹
  • --profile PROFILE β€” use a named profile from pyproject.toml [tool.datamodel-codegen.profiles.<name>] 🎭
  • --version β€” show version ⭐
  • --watch β€” watch input file(s) for changes and regenerate output automatically πŸ‘€
  • --watch-delay WATCH_DELAY β€” debounce delay in seconds for watch mode (default: 0.5) ⏱️
  • -h, --help β€” show this help message and exit 🫢

✨ Documentation: https://datamodel-code-generator.koxudaxi.dev Agent skill: https://datamodel-code-generator.koxudaxi.dev/coding-agent-skill/ GitHub: https://github.com/koxudaxi/datamodel-code-generator Go read the docs bestie, they're literally right there πŸ’–

and that's the whole page, we ate 🍽️✨ no crumbs. this was datamodel-codegen 0.71.0-1, dated July 2026, page DATAMODEL-CODEGEN(1) β€” periodt πŸ’…πŸŽ€

πŸ“¦ where this page comes from