Skip to content

types

DTO domain types.

DTOConfig dataclass

Control the generated DTO.

exclude class-attribute

exclude: set[str] = field(default_factory=set)

Explicitly exclude fields from the generated DTO.

purpose class-attribute

purpose: Purpose

Configure the DTO for "read" or "write" operations.

DTOField dataclass

For configuring DTO behavior on SQLAlchemy model fields.

mark class-attribute

mark: Mark | None = None

Mark the field as read-only, or private.

pydantic_field class-attribute

pydantic_field: FieldInfo | None = None

If provided, used for the pydantic model for this attribute.

pydantic_type class-attribute

pydantic_type: Any | None = None

Override the field type on the pydantic model for this attribute.

validators class-attribute

validators: Iterable[Callable[[Any], Any]] | None = None

Single argument callables that are defined on the DTO as validators for the field.

Mark

Bases: str, Enum

For marking column definitions on the domain models.

Example:

class Model(Base):
    ...
    updated_at: Mapped[datetime] = mapped_column(info={"dto": Mark.READ_ONLY})

PRIVATE class-attribute

PRIVATE = 'private'

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

READ_ONLY class-attribute

READ_ONLY = 'read-only'

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

Purpose

Bases: str, Enum

For identifying the purpose of a DTO to the factory.

The factory will exclude fields marked as private or read-only on the domain model depending on the purpose of the DTO.

Example:

ReadDTO = dto.factory("AuthorReadDTO", Author, purpose=dto.Purpose.READ)

READ class-attribute

READ = 'read'

To mark a DTO that is to be used to serialize data returned to clients.

WRITE class-attribute

WRITE = 'write'

To mark a DTO that is to deserialize and validate data provided by clients.