Skip to content

utils

Things that make working with DTOs nicer.

config

config(purpose, exclude=None)

Parameters:

Name Type Description Default
purpose Purpose | Literal['read', 'write']

Is the DTO for parsing "write" data, or serializing "read" data?

required
exclude set[str] | None

Omit fields from dto by key name.

None

Returns:

Type Description
DTOConfig

DTOConfig object configured per parameters.

field

field(mark=None, pydantic_type=None, pydantic_field=None, validators=None)

Create dto.DTOField() wrapped in a dict for SQLAlchemy info field.

Parameters:

Name Type Description Default
mark Mark | Literal['read-only', 'private'] | None

How this field should be treated by the model factory.

None
pydantic_type Any | None

Override the type annotation for this field.

None
pydantic_field FieldInfo | None

Result of Pydantic's DTOField() function. Override the FieldInfo instance used by the generated model.

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

Added to the generated model as validators, with allow_reuse=True.

None