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
--encoding Specify character encoding for input and output files.
--input Specify the input schema file path.
--input-file-type Specify the input file type for code generation.
--output Specify the destination path for generated Python code.
--url Fetch schema from URL with custom HTTP headers.

🔧 Typing Customization

Option Description
--allof-merge-mode Merge constraints from root model references in allOf schemas.
--disable-future-imports Prevent automatic addition of future imports in generated code.
--enum-field-as-literal Convert all enum fields to Literal types instead of Enum classes.
--no-use-specialized-enum Disable specialized Enum classes for Python 3.11+ code generation.
--output-datetime-class Specify datetime class type for date-time schema fields.
--strict-types Enable strict type validation for specified Python types.
--type-mappings Override default type mappings for schema formats.
--use-annotated Test GraphQL annotated types with standard collections and union operator.
--use-decimal-for-multiple-of Generate Decimal types for fields with multipleOf constraint.
--use-generic-container-types Use typing.Dict/List instead of dict/list for container types.
--use-non-positive-negative-number-constrained-types Use NonPositive/NonNegative types for number constraints.
--use-pendulum Use pendulum types for date/time fields instead of datetime module.
--use-standard-collections Use built-in dict/list instead of typing.Dict/List.
--use-type-alias Use TypeAlias instead of root models for type definitions (experimental).
--use-union-operator Test GraphQL annotated types with standard collections and union operator.
--use-unique-items-as-set Generate set types for arrays with uniqueItems constraint.

🏷️ Field Customization

Option Description
--aliases Apply custom field and class name aliases from JSON file.
--capitalize-enum-members Capitalize enum member names to UPPER_CASE format.
--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 specified schema extension keys in Field() without requiring 'x-' prefix...
--field-include-all-keys Include all schema keys in Field() json_schema_extra.
--no-alias Disable Field alias generation for non-Python-safe property names.
--original-field-name-delimiter Specify delimiter for original field names when using snake-case conversion.
--remove-special-field-name-prefix Remove the special prefix from field names.
--set-default-enum-member Set the first enum member as the default value for enum fields.
--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-inline-field-description Add field descriptions as inline comments.
--use-schema-description Use schema description as class docstring.
--use-title-as-name Use schema title as the generated class name.

🏗️ Model Customization

Option Description
--allow-extra-fields Allow extra fields in generated Pydantic models (extra='allow').
--allow-population-by-field-name Allow Pydantic model population by field name (not just alias).
--base-class Specify a custom base class for generated models.
--class-name Override the auto-generated class name with a custom name.
--collapse-root-models Inline root model definitions instead of creating separate wrapper classes.
--dataclass-arguments Customize dataclass decorator arguments via JSON dictionary.
--enable-faux-immutability Enable faux immutability in Pydantic v1 models (allow_mutation=False).
--force-optional Force all fields to be Optional regardless of required status.
--frozen-dataclasses Generate frozen dataclasses with optional keyword-only fields.
--keep-model-order Keep model definition order as specified in schema.
--keyword-only Generate dataclasses with keyword-only fields (Python 3.10+).
--output-model-type Select the output model type (Pydantic v1/v2, dataclasses, TypedDict, msgspec).
--parent-scoped-naming Namespace models by their parent scope to avoid naming conflicts.
--reuse-model Reuse identical model definitions instead of generating duplicates.
--reuse-scope Scope for model reuse detection (root or tree).
--skip-root-model Skip generation of root model when schema contains nested definitions.
--strict-nullable Strictly handle nullable types in OpenAPI schemas.
--strip-default-none Remove fields with None as default value from generated models.
--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-kwarg Use default= keyword argument instead of positional argument for fields with def...
--use-frozen-field Generate frozen (immutable) field definitions for readOnly properties.
--use-one-literal-as-default Use single literal value as default when enum has only one option.
--use-serialize-as-any Wrap fields with subtypes in Pydantic's SerializeAsAny.
--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.
--custom-file-header Add custom header text to the generated file.
--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 JSON file.
--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-version-header Include tool version information in file header.
--extra-template-data Pass custom template variables from JSON file for code generation.
--formatters Specify code formatters to apply to generated output.
--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.
--wrap-string-literal Wrap long string literals across multiple lines.

📘 OpenAPI-only Options

Option Description
--include-path-parameters Include OpenAPI path parameters in generated parameter models.
--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.
--use-operation-id-as-name Use OpenAPI operationId as the generated function/class name.
--validation Enable validation constraints (deprecated, use --field-constraints).

⚙️ 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.
--check Verify generated code matches existing output without modifying files.
--disable-warnings Suppress warning messages during code generation.
--generate-cli-command Generate CLI command from pyproject.toml configuration.
--generate-pyproject-config Generate pyproject.toml configuration from CLI arguments.
--http-headers Fetch schema from URL with custom HTTP headers.
--http-ignore-tls Disable TLS certificate verification for HTTPS requests.
--http-query-parameters Add query parameters to HTTP requests for remote schemas.
--ignore-pyproject Ignore pyproject.toml configuration file.
--shared-module-name Customize the name of the shared module for deduplicated models.

🔤 Alphabetical Index

All options sorted alphabetically: