DATAMODEL-CODEGEN(1)
π 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-privatenetworkto override it.--allow-remote-refs,--no-allow-remote-refsβ allows fetching remote$refreferences over HTTP/HTTPS. currently remote fetching is allowed by default BUT it emits a deprecation warning (π¨ yes, really). pass--allow-remote-refsto opt in without the warning, or--no-allow-remote-refsto 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$reffile 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$refpoints 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]; usebuiltinif 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$refURLs 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-typeis required. cannot be used with--inputor--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 toregenerate-allbehavior.--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$refJSON pointers as errors instead of generating fallbackAnymodels. no silent coping allowed.--url URLβ input file URL.--inputis ignored when--urlis 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 areLiteral.one: field type isLiteralwhen an enum has only one possible value.none: always use an Enum class (never convert toLiteral).--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-literalfor matched fields.--field-constraintsβ use field constraints and notcon*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β usetyping.AnnotatedforField(). also, the--fieldconstraintsoption 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 728closed=True/extra_itemsfor additionalProperties constraints. use--no-use-closed-typed-dictfor type checkers that don't yet support PEP 728 (e.g., mypy). be nice to mypy, it's trying.--use-decimal-for-multiple-ofβ usecondecimalinstead ofconfloatfor float/number fields with amultipleOfconstraint (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-standardcollectionsoption is set, then import fromcollections.abcinstead oftyping.--use-non-positive-negative-number-constrained-typesβ use theNon{Positive,Negative}{FloatInt}types instead of the correspondingcon*constrained types.--use-object-typeβ useobjectinstead ofAnyfor 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 forRootModel(e.g.,Foo = RootModel[Bar]) instead of class inheritance (Pydantic v2 only).--use-serialize-as-anyβ usepydantic.SerializeAsAnyfor 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 whenminItemsequalsmaxItemsequals the items length π―--use-type-aliasβ usesTypeAliasinstead 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 assetwhen the field attribute hasuniqueItemsπ
π 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 thex-prefix to field parameters. The extra keys are stripped of thex-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) tomodel_configjson_schema_extra--model-extra-keys-without-x-prefix MODEL_EXTRA_KEYS_WITHOUT_X_PREFIX [MODEL_EXTRA_KEYS_WITHOUT_X_PREFIX ...]β adds extra keys with thex-prefix tomodel_configjson_schema_extra. The extra keys are stripped of thex-prefix.--no-aliasβ does not add a field alias. E.g. if--snake-case-fieldis used along with a base class that has analias_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 defaultNoneon fields--union-mode {smart,left_to_right}β union mode, for pydantic v2 fields only--use-attribute-docstringsβ setsuse_attribute_docstrings=Truein the Pydantic v2ConfigDict--use-defaultβ uses the default value even if a field is required--use-default-factory-for-optional-nested-modelsβ usesdefault_factoryfor optional nested model fields instead of aNonedefault. E.g.field: Model | None = Field(default_factory=Model)instead offield: Model | None = None--use-default-kwargβ usesdefault=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β usesField(frozen=True)forreadOnlyfields (Pydantic v2). π₯Ά--use-inline-field-descriptionβ uses the schema description to populate the field docstring as an inline docstring--use-missing-sentinelβ usespydantic.experimental.missing_sentinel.MISSINGfor optional fields without defaults (Pydantic v2.12+).--use-serialization-aliasβ usesserialization_aliasinstead ofaliasfor 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 v2BaseModelalias generator to use inConfigDict. Matching generated aliases are omitted from individualField()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__.pywith re-exports.'children': export from direct child modules only.'recursive': export from all descendant modules.--allow-extra-fieldsβ Deprecated π¨:--allow-extra-fieldsis deprecated. Use--extra-fields=allowinstead.--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-nameis 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-nameis 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-modelsto be set.--dataclass-arguments DATACLASS_ARGUMENTSβ custom dataclass arguments as a JSON dictionary, e.g.'{"frozen": true, "kw_only": true}'. Overrides--frozen-dataclassesand similar flags.--disable-appending-item-suffixβ disables appending theItemsuffix 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"}'changesAddress1toAddressSchema. 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@generatedmarker 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 inlineoneOf/anyOfbranch model names from literal discriminator-style fields--keep-model-orderβ keeps the generated models' order--keyword-onlyβ defines models as keyword only (for exampledataclass(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_Addressfor 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 betweenPastDate,FutureDateordate. (Pydantic v2 only) Each output model has its default mapping.--output-datetime-class {datetime,AwareDatetime,NaiveDatetime,PastDatetime,FutureDatetime}β choose the Datetime class betweenAwareDatetime,NaiveDatetime,PastDatetime,FutureDatetimeordatetime. 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-prefixedinstead, 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) ortree= cross-file with a shared module. Heads up: this only does anything when--reuse-modelis 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-moduleor--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, usespopulate_by_name)2.11: Pydantic 2.11+ (usesvalidate_by_name)2.12: Pydantic 2.12+ (supportsMISSINGsentinel)
--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 (sofoo.bar.Modelbecomesfoo/bar.py). Use--no-treat-dot-as-moduleto keep dots in names as underscores for single-file output π--use-exact-importsβ import exact types instead of modules, like:from .foo import Barinstead offrom . import foowithfoo.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β usependuluminstead ofdatetimeπ°οΈ--use-root-model-sequence-interfaceβ make non-null sequence-like Pydantic v2RootModelclasses implementcollections.abc.Sequenceby addingSequence[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 ofstr. Affectsdataclass,msgspec,TypedDictoutput. 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']}usesAliasChoicesfor validation. Example:{'User.name': 'user_name', 'id': 'id_'}generatesid_: ... = 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-defaultis 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 configskip_string_normalizationvalue, 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 intoTYPE_CHECKINGblocks. 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-importsto 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 withfield,function, andmode.--wrap-string-literalβ wrap string literal by using blackexperimentalstring-processingoption (require black20.8b0or 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 OpenAPIinfo.versionasOPENAPI_INFO_VERSIONin 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 forreadOnly/writeOnlyfields:'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--validationoption is deprecated and will be removed in a future release. Use--fieldconstraintsinstead. Don't get attached π
π¦ GraphQL-only options π¦
--graphql-no-typenameβ exclude__typenamefield 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 code1if differences are found,0if 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 frompyproject.tomlconfiguration 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β generatepyproject.tomlconfiguration from the provided CLI arguments and exit π--ignore-pyprojectβ ignorepyproject.tomlconfiguration π--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). Usejsonfor 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 frompyproject.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.devAgent skill:https://datamodel-code-generator.koxudaxi.dev/coding-agent-skill/GitHub:https://github.com/koxudaxi/datamodel-code-generatorGo 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
- ubuntu stonking: datamodel-codegen 0.71.0-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms