data_structures#

class litestar.dto.data_structures.DTOData#

Bases: Generic[T]

DTO validated data and utility methods.

__init__(backend: DTOBackend, data_as_builtins: Any) None#
create_instance(**kwargs: Any) T#

Create an instance of the DTO validated data.

Parameters:

**kwargs – Additional data to create the instance with. Takes precedence over DTO validated data.

update_instance(instance: T, **kwargs: Any) T#

Update an instance with the DTO validated data.

Parameters:
  • instance – The instance to update.

  • **kwargs – Additional data to update the instance with. Takes precedence over DTO validated data.

as_builtins() Any#

Return the DTO validated data as builtins.

class litestar.dto.data_structures.DTOFieldDefinition#

Bases: FieldDefinition

A model field representation for purposes of generating a DTO backend model type.

model_name: str#

The name of the model for which the field is generated.

default_factory: Callable[[], Any] | None#

Default factory of the field.

dto_field: DTOField#

DTO field configuration.

__init__(raw: Any, annotation: Any, type_wrappers: tuple[type, ...], origin: Any, args: tuple[Any, ...], metadata: tuple[Any, ...], instantiable_origin: Any, safe_generic_origin: Any, inner_types: tuple[FieldDefinition, ...], default: Any, extra: dict[str, Any], kwarg_definition: KwargDefinition | DependencyKwarg | None, name: str, model_name: str, default_factory: Callable[[], Any] | None, dto_field: DTOField, passthrough_constraints: bool) None#
passthrough_constraints: bool#

Pass constraints of the source annotation to be validated by the DTO backend

classmethod from_field_definition(field_definition: FieldDefinition, model_name: str, default_factory: Callable[[], Any] | None, dto_field: DTOField, passthrough_constraints: bool = True) DTOFieldDefinition#

Create a FieldDefinition from a FieldDefinition.

Parameters:
  • field_definition – A FieldDefinition to create a FieldDefinition from.

  • model_name – The name of the model.

  • default_factory – Default factory function, if any.

  • dto_field – DTOField instance.

  • passthrough_constraints – Pass constraints of the source annotation to be validated by the DTO backend

Returns:

A FieldDefinition instance.