config#

class litestar.dto.config.DTOConfig#

Bases: object

Control the generated DTO.

exclude: AbstractSet[str]#

Explicitly exclude fields from the generated DTO.

If exclude is specified, all fields not specified in exclude will be included by default.

Notes

  • The field names are dot-separated paths to nested fields, e.g. "address.street" will

    exclude the "street" field from a nested "address" model.

  • ‘exclude’ mutually exclusive with ‘include’ - specifying both values will raise an

    ImproperlyConfiguredException.

include: AbstractSet[str]#

Explicitly include fields in the generated DTO.

If include is specified, all fields not specified in include will be excluded by default.

Notes

  • The field names are dot-separated paths to nested fields, e.g. "address.street" will

    include the "street" field from a nested "address" model.

  • ‘include’ mutually exclusive with ‘exclude’ - specifying both values will raise an

    ImproperlyConfiguredException.

rename_fields: dict[str, str]#

Mapping of field names, to new name.

rename_strategy: RenameStrategy | None = None#

Rename all fields using a pre-defined strategy or a custom strategy.

The pre-defined strategies are: upper, lower, camel, pascal.

A custom strategy is any callable that accepts a string as an argument and return a string.

Fields defined in rename_fields are ignored.

__init__(exclude: AbstractSet[str] = <factory>, include: AbstractSet[str] = <factory>, rename_fields: dict[str, str] = <factory>, rename_strategy: RenameStrategy | None = None, max_nested_depth: int = 1, partial: bool = False, underscore_fields_private: bool = True, experimental_codegen_backend: bool | None = None) None#
max_nested_depth: int = 1#

The maximum depth of nested items allowed for data transfer.

partial: bool = False#

Allow transfer of partial data.

underscore_fields_private: bool = True#

Fields starting with an underscore are considered private and excluded from data transfer.

experimental_codegen_backend: bool | None = None#

Use the experimental codegen backend