Skip to content

🔍 Quick Reference

All CLI options in one page for easy Ctrl+F searching.

👆 Click any option to see detailed documentation with examples.


datamodel-codegen [OPTIONS]

📂 All Options by Category

📁 Base Options

Option Description
--emit-model-metadata Write a separate JSON map from the final generated models, modules, fields, and ...
--encoding Specify character encoding for input and output files.
--external-ref-mapping Map external $ref files to Python packages.
--http-backend Select the HTTP client backend for remote schemas.
--ignore-ref-siblings-by-schema-version Read a $ref as its target alone where the schema version ignores the keywords ...
--input Specify the input schema file path.
--input-file-type Specify the input file type for code generation.
--input-model Import a Python type or dict schema from a module or Python file.
--input-model-ref-strategy Strategy for referenced types when using --input-model.
--output Specify the destination path for generated Python code.
--preset Apply an immutable built-in option preset.
--read-dynamic-anchors-in-document-order Resolve a $dynamicRef to the first $dynamicAnchor of its name in document or...
--read-escaped-ref-pointers Read the escapes of a $ref JSON pointer as the characters they encode.
--read-input-model-dataclass-fields-by-alias Read the fields of a Pydantic dataclass by their aliases with --input-model.
--read-schema-version-per-document Read each document by the schema version it declares.
--reuse-every-reached-input-model-type Reach the types to reuse through every model kind and write no copy of an import...
--schema-version Schema version to use for parsing.
--schema-version-mode Schema version validation mode.
--url Fetch a schema from a URL with custom HTTP headers.

🔧 Typing Customization

Option Description
--allof-class-hierarchy Controls how allOf schemas are represented in the generated class hierarchy. `--...
--allof-merge-mode Merge constraints from root model references in allOf schemas.
--disable-future-imports Prevent automatic addition of future imports in generated code.
--distribute-allof-over-unions Read an allOf with the anyOf and oneOf it holds or sits beside, as JSON Sc...
--enum-field-as-literal Convert all enum fields to Literal types instead of Enum classes.
--enum-field-as-literal-map Override enum/literal generation per-field via JSON mapping.
--filter-literal-values Keep only the values of a const or an enum that meet the constraints beside ...
--ignore-enum-constraints Ignore enum constraints and use base string type instead of Enum classes.
--import-overrides Override modules for generated imports by symbol name.
--intersect-allof-keywords Combine the keywords of every part of an allOf, a $ref with siblings or an o...
--intersect-combined-schema-keywords Combine the keywords beside an anyOf or oneOf with each branch, as JSON Sche...
--keep-enum-member-values Give an enum class a value base only when it keeps every member value.
--no-use-closed-typed-dict Disable PEP 728 TypedDict closed/extra_items generation.
--no-use-specialized-enum Disable specialized Enum classes for Python 3.11+ code generation.
--no-use-standard-collections Use typing.Dict/List instead of built-in dict/list for container types.
--no-use-union-operator Use Union[X, Y] / Optional[X] instead of X
--output-date-class Specify date class type for date schema fields.
--output-datetime-class Specify datetime class type for date-time schema fields.
--read-allof-parents-in-mro-order Read the allOf parents of every inherited schema in the order of the class bases...
--read-const-beside-enum Read a const beside an enum as JSON Schema does.
--read-unevaluated-properties Read a schema-valued unevaluatedProperties as additionalProperties.
--strict-types Enable strict type validation for specified Python types.
--type-mappings Override default type mappings for schema formats.
--type-overrides Replace schema model types with custom Python types via JSON mapping.
--type-overrides-replace-whole-type Make every --type-overrides value of a field replace the field's whole type.
--use-annotated Use typing.Annotated for Field() with constraints.
--use-bytes-for-content-media-type Type an OpenAPI string with a contentMediaType and no contentEncoding as `by...
--use-closed-typed-dict Generate TypedDict with PEP 728 closed/extra_items (default: enabled).
--use-decimal-for-multiple-of Generate Decimal types for fields with multipleOf constraint.
--use-decimal-in-field-forms Write Decimal for a number with multipleOf in the field forms too.
--use-encoded-str-for-constrained-base64 Check the constraints of a format: byte string on its base64 text in the field...
--use-generic-container-types Use generic container types (Sequence, Mapping) for type hinting.
--use-non-positive-negative-number-constrained-types Use NonPositive/NonNegative types for number constraints.
--use-object-type Use object instead of Any for unspecified object and array values.
--use-pendulum Use pendulum types for date, time, and duration fields.
--use-plain-alias-for-recursive-models Write the type alias of a model that names itself as a plain alias in Pydantic o...
--use-root-model-type-alias Generate RootModel as type alias format for better mypy support.
--use-single-dict-for-object-maps Type an object map as one dict instead of a union of dicts.
--use-single-value-enum-as-const Treat enum with a single value as const with that value.
--use-specialized-enum Generate StrEnum/IntEnum for string/integer enums (Python 3.11+).
--use-standard-collections Use built-in dict/list instead of typing.Dict/List.
--use-standard-primitive-types Use Python standard library types for string formats instead of str.
--use-strict-str-for-base64 Make a format: byte string strict under --strict-types str.
--use-total-false-for-typed-dict Generate TypedDict declarations with total=False.
--use-tuple-for-closed-arrays Generate tuple types for positional arrays that no other item can follow.
--use-tuple-for-fixed-items Generate tuple types for arrays with items array syntax.
--use-tuple-for-fixed-length-arrays Generate tuple types for homogeneous fixed-length arrays.
--use-type-alias Use TypeAlias instead of root models for type definitions (experimental).
--use-type-alias-type Use runtime TypeAliasType objects for aliases before Python 3.12 (experimental).
--use-typed-map-values-beside-other-types Type the map values of type arrays that list object beside other types.
--use-typed-nullable-map-values Type the values of nullable maps as their schemas say instead of Any.
--use-union-operator Use
--use-unique-items-as-set Generate set types for arrays with uniqueItems constraint.
--use-unique-items-as-set-by-value Write a uniqueItems set only where its final items hash by value.
--use-x-python-type-as-written Write a field's x-python-type as given: unions of every spelling and container...

🏷️ Field Customization

Option Description
--aliases Apply custom field and class name aliases via inline JSON or a JSON file path.
--capitalize-enum-members Capitalize enum member names to UPPER_CASE format.
--capitalize-numbered-enum-members Capitalize the numbered name an enum member takes when its name is taken.
--default-values Override field default values via inline JSON or a JSON file path.
--deserialize-default-values Deserialize selected direct scalar field defaults into their generated Python ty...
--empty-enum-field-name Name for empty string enum field values.
--extra-fields Configure how generated models handle extra fields not defined in schema.
--field-constraints Generate Field() with validation constraints from schema.
--field-extra-keys Include specific extra keys in Field() definitions.
--field-extra-keys-without-x-prefix Include schema extension keys in Field() without requiring 'x-' prefix.
--field-include-all-keys Include all schema keys in Field() json_schema_extra.
--field-type-collision-strategy Rename type class instead of field when names collide (Pydantic v2 only).
--infer-union-variant-names Name inline oneOf/anyOf branch models after the value of their tag field (Pet ...
--merge-shared-variant-tags Give a variant that discriminated unions tag differently every tag they give it.
--name-allof-union-members-after-branches Name the classes an allOf gives the branches of a oneOf or anyOf it holds after ...
--no-alias Disable Field alias generation for non-Python-safe property names.
--no-deserialize-default-values Keep serialized schema defaults instead of deserializing selected types.
--omit-redundant-constraints Do not write a constraint again beside a type that already enforces it.
--original-field-name-delimiter Specify delimiter for original field names when using snake-case conversion.
--read-length-keywords-by-type Read the string and the array keywords for their own kind only, as JSON Schema d...
--read-msgspec-union-bounds-exactly Decide the bounds of the int member of a msgspec union on the bounds the schema ...
--remove-special-field-name-prefix Remove the special prefix from field names.
--serialization-aliases Apply custom Pydantic v2 serialization aliases via inline JSON or a JSON file pa...
--set-default-enum-member Use the legacy flag for deserializing enum defaults.
--snake-case-field Convert field names to snake_case format.
--special-field-name-prefix Prefix to add to special field names (like reserved keywords).
--use-attribute-docstrings Generate field descriptions as attribute docstrings instead of Field description...
--use-enum-values-in-discriminator Use enum values in discriminator mappings for union types.
--use-field-description Include schema descriptions as Field docstrings.
--use-field-description-example Add field examples to docstrings.
--use-inline-field-description Add field descriptions as inline comments.
--use-one-model-per-ref-site Give an object $ref with sibling keywords one model per place it is written.
--use-schema-description Use schema description as class docstring.
--use-serialization-alias Use serialization_alias instead of alias for field aliasing (Pydantic v2 only).
--use-single-line-docstring Emit short docstrings on a single line.
--use-site-models-for-constrained-refs Give an allOf of $ref members whose other parts add assertions its own model.
--use-tag-as-union-variant-name Name inline oneOf/anyOf branch models after their tag: what `--infer-union-varia...
--use-title-as-name Use schema title as the generated class name.

🏗️ Model Customization

Option Description
--alias-generator Use a Pydantic v2 alias generator in model_config.
--allow-extra-fields Allow extra fields in generated Pydantic models (extra='allow').
--allow-leading-underscore-class-name Allow an explicitly specified root class name to start with an underscore.
--allow-population-by-field-name Allow Pydantic model population by field name (not just alias).
--apply-field-options-to-every-field Give every kind of field the field options the other fields take.
--base-class Specify a custom base class for generated models.
--base-class-map Specify different base classes for specific models via JSON mapping.
--class-name Override the auto-generated class name with a custom name.
--class-name-affix-scope Control which classes receive the prefix/suffix.
--class-name-prefix Add a prefix to all generated class names.
--class-name-suffix Add a suffix to all generated class names.
--collapse-constrained-root-models-as-annotated Inline a constrained string root model into a union or a container as `Annotated...
--collapse-reuse-models Collapse duplicate models by replacing references instead of inheritance.
--collapse-root-models Inline root model definitions instead of creating separate wrapper classes.
--collapse-root-models-name-strategy Select which name to keep when collapsing root models with object references.
--collapse-shared-parent-wrappers Collapse a parent-strategy wrapper in every model that references it.
--dataclass-arguments Customize dataclass decorator arguments via JSON dictionary.
--duplicate-name-suffix Customize suffix for duplicate model names.
--enable-faux-immutability Enable faux immutability in Pydantic models (frozen=True).
--force-optional Force all fields to be Optional regardless of required status.
--frozen-dataclasses Generate frozen dataclasses with optional keyword-only fields.
--keep-constrained-root-models-in-every-container Keep constrained root models named in every container of a holder.
--keep-defaults-of-inherited-required-fields Keep under --use-default the default of a property only an inherited schema ma...
--keep-enum-literal-aliases Keep a named enum written as a Literal type alias named under collapse.
--keep-false-dataclass-arguments Write every dataclass decorator argument set to false.
--keep-field-defaults-off-branch-roots Leave a property's default off the root models extracted from its anyOf or `on...
--keep-model-order Keep generated model order deterministic while respecting dependency constraints...
--keep-reference-null-on-collapsed-root-models Keep the null of a root model that admits null where --collapse-root-models in...
--keep-reference-null-on-merged-models Keep the null a reference's schema admits when its model is merged.
--keep-self-referencing-array-items Keep the items of an array whose items name the array itself.
--keep-shared-members-on-collapsed-root-models Keep each member of a root type that collapse inlined at several sites at every ...
--keyword-only Generate dataclasses with keyword-only fields (Python 3.10+).
--merge-message-trait-headers Give an AsyncAPI message the headers of all its traits, merged in order, and the...
--model-extra-keys Add model-level schema extensions to ConfigDict json_schema_extra.
--model-extra-keys-without-x-prefix Strip x- prefix from model-level schema extensions and add to ConfigDict json_sc...
--model-name-map Rename generated model classes from a JSON mapping.
--name-converted-payloads-by-message Name a converted payload that names no type of its own after its message.
--naming-strategy Choose how models are named and how duplicate model names are told apart.
--omit-incomplete-model-defaults Write a property whose object default lacks required fields of its model without...
--omit-redundant-reference-null Do not write None again at a reference to a model that holds null itself.
--order-constructor-fields-by Order constructor fields by final names or by written defaults.
--output-model-type Select the output model type (Pydantic v2, Pydantic v2 dataclass, dataclasses, T...
--parent-scoped-naming Namespace models by their parent scope to avoid naming conflicts.
--pin-aliases-with-alias-generator Decide a field's alias by the alias generator its model applies.
--read-nullable-beside-type-list Write the null that nullable: true declares beside a type list into the root...
--remove-unused-models-beside-type-overrides Remove the unused models from a module that a model-level --type-overrides key...
--reuse-model Reuse identical model definitions instead of generating duplicates.
--reuse-scope Scope for model reuse detection (root or tree).
--singularize-last-word-of-item-names Name the item model of an array by singularizing only the last word of its name.
--skip-root-model Skip generation of root model when schema contains nested definitions.
--strict-nullable Treat default field as a non-nullable field.
--strip-default-none Remove fields with None as default value from generated models.
--tag-msgspec-by-payload-name Tag the structs of a msgspec discriminated union with the property name of the d...
--target-pydantic-version Target Pydantic version for generated code compatibility.
--target-python-version Target Python version for generated code syntax and imports.
--union-mode Union mode for combining anyOf/oneOf schemas (smart or left_to_right).
--use-default Use default values from schema in generated models.
--use-default-factory-for-optional-nested-models Generate default_factory for optional nested model fields.
--use-default-kwarg Use default= keyword argument instead of positional argument for fields with def...
--use-duplicate-name-suffix-for-every-collision Give the --duplicate-name-suffix suffix to every model renamed in its module.
--use-frozen-field Generate frozen (immutable) field definitions for readOnly properties.
--use-generic-base-class Generate a shared base class with model configuration to avoid repetition (DRY).
--use-missing-sentinel Use Pydantic's MISSING sentinel for unset optional BaseModel or dataclass fields...
--use-msgspec-forbid-unknown-fields Reject the unknown fields of a msgspec Struct whose schema admits no property bu...
--use-msgspec-meta-for-map-keys Check the keys of a msgspec map whose keys propertyNames or patternProperties co...
--use-msgspec-nullable-enum-alias Write a msgspec.Struct enum that lists null as an Enum and a nullable alias.
--use-msgspec-tagged-unions Write a msgspec.Struct discriminated union as tagged structs as a whole.
--use-one-literal-as-default Use single literal value as default when enum has only one option.
--use-root-model-sequence-interface Make non-null sequence-like Pydantic v2 RootModel classes implement collections....
--use-serialize-as-any Wrap fields with subtypes in Pydantic's SerializeAsAny.
--use-serialize-as-any-for-every-subclass Wrap a field in SerializeAsAny when any subclass of its model adds fields.
--use-subclass-enum Generate typed Enum subclasses for enums with specific field types.

🎨 Template Customization

Option Description
--additional-imports Add custom imports to generated output files.
--check-pattern-maps-strictly Check every key of the pattern maps that --generate-schema-validators validate...
--class-decorators Add custom decorators to generated model classes.
--custom-file-header Add custom header text to the generated file.
--custom-file-header-mode Choose how a custom file header combines with generated provenance.
--custom-file-header-path Add custom header content from file to generated code.
--custom-formatters Apply custom Python code formatters to generated output.
--custom-formatters-kwargs Pass custom arguments to custom formatters via inline JSON or a JSON file path.
--custom-template-dir Use custom Jinja2 templates for model generation.
--disable-appending-item-suffix Disable appending 'Item' suffix to array item types.
--disable-timestamp Disable timestamp in generated file header for reproducible output.
--enable-command-header Include command-line options in file header for reproducibility.
--enable-generated-header-marker Include the @generated marker in file header for generated-code tooling.
--enable-version-header Include tool version information in file header.
--extra-template-data Pass custom template variables via inline JSON or a JSON file path.
--formatters Specify code formatters to apply to generated output.
--generate-schema-validators Generate experimental Pydantic v2 model validators for JSON Schema runtime rules...
--no-formatters Select no formatter for the generated output.
--no-treat-dot-as-module Keep dots in schema names as underscores for flat output.
--no-use-type-checking-imports Keep generated model imports available at runtime when using Ruff fixes.
--rename-submodules-hidden-by-classes Rename a submodule named like a class of its package.
--schema-validator-base-class-name Set the generated shared Pydantic v2 schema runtime validator base class name.
--schema-validator-type Select the schema-derived runtime validator backend.
--strict-dotted-module-names Require canonical Python identifiers when inferring dotted module paths.
--treat-dot-as-module Treat dots in schema names as module separators.
--use-double-quotes Use double quotes for string literals in generated code.
--use-exact-imports Import exact types instead of modules.
--use-type-checking-imports Allow Ruff to move typing-only imports into TYPE_CHECKING blocks.
--validators Add custom field validators to generated Pydantic v2 models.
--wrap-string-literal Wrap long string literals across multiple lines.

📘 OpenAPI-only Options

Option Description
--dedupe-numbered-request-response-variants Deduplicate a Request or Response variant of a numbered model like the model.
--dedupe-request-response-variants Decide Request/Response variants from the schema graph and build each inline mod...
--include-path-parameters Include OpenAPI path parameters in generated parameter models.
--keep-content-parameter-refs Type a parameter whose content media schema is a $ref by the model the $ref ...
--keep-first-character-of-path-keys Strip only a leading slash from a paths key when naming its operation models.
--openapi-as-definitions Give OpenAPI paths bodies or ref components the models their definitions get.
--openapi-include-info-version Emit OpenAPI info.version as a generated constant.
--openapi-include-paths Filter OpenAPI paths to include in model generation.
--openapi-scopes Specify OpenAPI scopes to generate (schemas, paths, parameters).
--read-only-write-only-model-type Generate separate request and response models for readOnly/writeOnly fields.
--skip-path-extension-keys Skip the x- keys of paths in the paths scope, as the api scope does.
--use-enum-field-as-literal-in-operations Write an operation body or response enum as a Literal root model as a definition...
--use-operation-id-as-name Use OpenAPI operationId as the generated function/class name.
--use-status-code-in-response-name Include HTTP status code in response model names.
--validation Enable validation constraints (deprecated, use --field-constraints).

📋 GraphQL-only Options

Option Description
--graphql-no-typename Exclude __typename field from generated GraphQL models.

⚙️ General Options

Option Description
--all-exports-collision-strategy Handle name collisions when exporting recursive module hierarchies.
--all-exports-scope Generate all exports for child modules in init.py files.
--allow-private-network Allow HTTP requests to private network schema endpoints.
--allow-remote-refs Enable fetching of $ref targets over HTTP/HTTPS.
--check Verify generated code matches existing output without modifying files.
--diff-against Compare generated code from a baseline input with the current schema without wri...
--disable-warnings Suppress warning messages during code generation.
--fail-on-multi-module-stdout Fail instead of concatenating multiple modules in text stdout.
--generate-cli-command Generate CLI command from pyproject.toml configuration.
--generate-pyproject-config Generate pyproject.toml configuration from CLI arguments.
--http-headers Fetch a schema from a URL with custom HTTP headers.
--http-ignore-tls Disable TLS certificate verification for HTTPS requests.
--http-local-ref-path Resolve HTTP references from local schema files.
--http-query-parameters Add query parameters to HTTP requests for remote schemas.
--http-timeout Set timeout for HTTP requests to remote hosts.
--ignore-pyproject Ignore pyproject.toml configuration file.
--locked Require an existing remote lock and validate each fetched resource against it (e...
--lockfile Select the remote reference integrity lock file (experimental).
--module-split-mode Split generated models into separate files, one per model class.
--recommend-options Recommend options for the input schema on top of the latest dated preset (experi...
--shared-module-name Customize the name of the shared module for deduplicated models.
--strict-refs Treat unresolved local $ref JSON pointers as errors.
--update-lock Create or atomically update the selected remote lock after generation (experimen...
--watch Watch input file(s) for changes and regenerate output automatically.
--watch-delay Set debounce delay in seconds for watch mode.

🚀 Target Generation Options

Option Description
--client-body-arguments Choose how operation methods take request bodies (experimental).
--client-default-base-url Set the server URL of operations that declare no servers (experimental).
--client-model-package Name the import path of the models the client package imports (experimental).
--client-operations Set the client settings of single operations (experimental).
--client-output Write the client package to this directory (experimental).
--client-package Name the import path of the client package (experimental).
--client-protocols Declare the protocol helpers of the client package (experimental).
--client-resource-names Name the resources of tags (experimental).
--client-server-base-url Resolve relative server URLs against this base URL (experimental).
--client-signature-style Declare the arguments of the operation methods (experimental).
--generate-client Generate an HTTPX2 client package for the models (experimental).
--generate-server Generate a FastAPI server package for the models (experimental).
--server-body-mode Choose how service methods receive request bodies (experimental).
--server-body-modes Set the body mode of single operations (experimental).
--server-handler-mode Declare the service methods as plain or coroutine functions (experimental).
--server-handler-modes Set the handler mode of single operations (experimental).
--server-include-request Pass the Starlette Request to every service method (experimental).
--server-layout Choose how the server package lays out its routes (experimental).
--server-model-package Name the import path of the models the server package imports (experimental).
--server-operation-names Name the service methods of single operations (experimental).
--server-output Write the server package to this directory (experimental).
--server-package Name the import path of the server package (experimental).
--server-parameter-names Name the method arguments of single operations (experimental).
--server-primary-responses Choose the response a bare return value of an operation takes (experimental).
--server-router-names Name router groups (experimental).

📝 Utility Options

Option Description
--all-jobs Run every named generation job from pyproject.toml (experimental)
--debug Show debug messages during code generation
--generate-prompt Generate a prompt for consulting LLMs about CLI options
--help Show help message and exit
--install-skill Install the bundled Agent Skill (experimental)
--job Run a named generation job from pyproject.toml (experimental)
--list-deprecations List registered deprecations and scheduled breaking changes
--list-experimental List registered experimental features
--no-color Disable colorized output
--output-format Choose the command output format
--output-format-json-schema Output JSON Schema for structured command output or JSON configuration
--overwrite-skill Replace an existing Agent Skill installation
--profile Use a named profile from pyproject.toml
--skill-scope Choose an Agent Skill installation scope
--version Show program version and exit

🔤 Alphabetical Index

All options sorted alphabetically: