DTO domain types.

class litestar.dto.field.DTOField#

Bases: object

For configuring DTO behavior on model fields.

__init__(mark: Mark | Literal['read-only', 'write-only', 'private'] | None = None) None#
mark: Mark | Literal['read-only', 'write-only', 'private'] | None = None#

Mark the field as read-only, or private.

class litestar.dto.field.Mark#

Bases: str, Enum

For marking field definitions on domain models.

READ_ONLY = 'read-only'#

To mark a field that can be read, but not updated by clients.

WRITE_ONLY = 'write-only'#

To mark a field that can be written to, but not read by clients.

PRIVATE = 'private'#

To mark a field that can neither be read or updated by clients.

litestar.dto.field.dto_field(mark: Literal['read-only', 'write-only', 'private'] | Mark) dict[str, DTOField]#

Create a field metadata mapping.


mark – A DTO mark for the field, e.g., “read-only”.


A dict for setting as field metadata, such as the dataclass “metadata” field key, or the SQLAlchemy “info” field.

Marking a field automates its inclusion/exclusion from DTO field definitions, depending on the DTO’s purpose.

litestar.dto.field.extract_dto_field(field_definition: FieldDefinition, field_info_mapping: Mapping[str, Any]) DTOField#

Extract DTOField instance for a model field.

Supports DTOField to bet set via Annotated or via a field info/metadata mapping.

E.g., Annotated[str, DTOField(mark="read-only")] or info=dto_field(mark="read-only").

If a value is found in field_info_mapping, it is prioritized over the field definition’s metadata.

  • field_definition – A field definition.

  • field_info_mapping – A field metadata/info attribute mapping, e.g., SQLAlchemy’s info attribute, or dataclasses metadata attribute.


DTO field info, if any.