Core API
Runtime DTO derivation
For an entity User, derive read, write, or combined DTO classes:
from fastsprout.core import (
derive_read_dto,
derive_read_write_dto,
derive_write_dto,
)
UserRead = derive_read_dto(User)
UserCreate = derive_write_dto(User)
UserUpdate = derive_read_write_dto(User)
Each function reuses its class for the same entity. Visibility is enforced
at runtime; type checkers see type[User]. For static field restrictions,
declare class UserRead(ReadDTO, User): ... instead.
__all__
module-attribute
__all__ = [
"ActionGroupable",
"Actionable",
"BaseFastSproutError",
"BaseSchema",
"Chunk",
"Context",
"DependencyInjector",
"Depends",
"EntityVisibility",
"ExtraReadDTO",
"ExtraReadField",
"ExtraReadWriteDTO",
"ExtraWriteDTO",
"ExtraWriteField",
"FastSproutError",
"Field",
"IDType",
"IdentificatorType",
"InternalField",
"PublicIDType",
"ReadDTO",
"ReadField",
"ReadWriteDTO",
"Schema",
"TriggerActionable",
"Undefined",
"UndefinedType",
"WriteDTO",
"WriteField",
"dataclass",
"derive_read_dto",
"derive_read_write_dto",
"derive_write_dto",
"dto",
"hidden_lazy_await",
"inject_depends",
"lazy_await",
"typed_dataclass",
"typed_fields",
"typed_pyd_dataclass",
]
Actionable
ActionGroupable
TriggerActionable
DependencyInjector
Resolve Depends providers with per-call caching and callable overrides.
dependency_providers
instance-attribute
dependency_overrides
instance-attribute
dependency_key
dependency_key[**P, R](
provider: Callable[P, R], active: frozenset[int] = frozenset()
) -> UUID | None
call_async
async
staticmethod
arguments
arguments(
function: Callable[..., Any],
args: tuple[Any, ...],
kwargs: dict[str, Any],
supplied: BoundArguments | None = None,
) -> tuple[inspect.BoundArguments, list[tuple[str, Any, Any]]]
resolve_dependency
resolve_dependency(
marker: Any,
annotation: Any,
cache: dict[object, Any],
active: set[Callable[..., Any]],
) -> Any
aresolve_dependency
async
aresolve_dependency(
marker: Any,
annotation: Any,
cache: dict[object, Any],
active: set[Callable[..., Any]],
supplied: BoundArguments | None = None,
) -> Any
inject
inject(
function: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any]
) -> inspect.BoundArguments
ExtraReadDTO
ExtraReadWriteDTO
ExtraWriteDTO
ReadDTO
ReadWriteDTO
WriteDTO
BaseFastSproutError
Bases: Exception
Base for all fastsprout exceptions.
FastSproutError
Bases: BaseFastSproutError
Fastsprout exceptions.
EntityVisibility
Unrestricted source; DTO bases supply a concrete visibility mode.
Only this private marker is Any. Field value types remain fully typed. The open marker allows a DTO to narrow visibility without an incompatible override of a literal-valued member on its source entity.
ExtraReadField
Bases: Field[T, ExtraReadable]
Excluded from ordinary DTOs; requires extended read visibility.
ExtraWriteField
Bases: Field[T, ExtraWritable]
Excluded from ordinary DTOs; requires extended write visibility.
Field
Bases: Generic[T, FieldOwner, FieldOrm]
Typed field descriptor.
Annotation form: is_active: Field[bool]
Behavior
- On class:
Hero.is_active→ FieldRef[Hero, bool, OrmCtor] (carries entity binding for repository.select; the SQLAlchemy overload types.ormasMapped[T]) - On instance:
hero.is_active→ bool (the value)
Defaults are declared through the specifier, not raw assignment — this keeps both the type checker and the runtime model build happy:
class Hero(BaseSchema):
age: Field[int] = Field(default=0)
uid: Field[UUID] = Field(default_factory=uuid4)
Use .set(value) for partial-update assignment objects:
Hero.is_active.set(True) # FieldAssignment[bool]
__slots__
class-attribute
instance-attribute
__fastsprout_ops__
class-attribute
__init__
__init__(
*,
default: T | UndefinedType = Undefined,
default_factory: Callable[[], T] | None = None,
) -> None
descriptor
classmethod
Internal: build the descriptor installed on model classes.
Bypasses the public specifier constructor — framework use only (metaclasses), never part of the user-facing API.
__get__
InternalField
Bases: Field[T, Internalable]
Accessible on the entity, excluded from every public DTO.
ReadField
Bases: Field[T, Readable]
Included in read DTOs, excluded from write-only DTOs.
WriteField
Bases: Field[T, Writable]
Included in write DTOs, excluded from read-only DTOs.
BaseSchema
Bases: Schema, EntityVisibility, BaseModel
Base schema with type-safe field descriptors.
Subclasses declare fields with Field[T] annotations:
class Hero(BaseSchema):
id: Field[UUID]
is_active: Field[bool]
name: Field[str]
Then
hero = Hero(id=uuid(), is_active=True, name="SuperMan") hero.is_active # bool Hero.is_active # Field[bool] Hero.is_active.set(True) # FieldAssignment[bool]
Schema
Chunk
UndefinedType
Sentinel type for 'no value provided'.
fastsprout's own PydanticUndefined: a single shared singleton,
falsy, safe to copy/pickle, usable anywhere a missing value must be
distinguished from None (which is a real value).
Context
Request a typed value from the current invocation or its provider.
hidden_lazy_await
typed_dataclass
typed_dataclass[C](
cls: type[C] | None = None, *, frozen: bool = False, kw_only: bool = False
) -> type[C] | Callable[[type[C]], type[C]]
Apply stdlib @dataclass + install Field[T] descriptors.
Auto-generated init, repr, eq. No runtime validation.
Example
@typed_dataclass class User: field_int: Field[int] field_str: Field[str]
derive_read_dto
Derive a DTO exposing fields marked for reading.
derive_read_write_dto
Derive a DTO exposing read and write fields, excluding internal fields.
derive_write_dto
Derive a DTO exposing fields marked for writing.
dataclass
dataclass[C](
cls: type[C] | None = None, *, frozen: bool = False, kw_only: bool = False
) -> type[C] | Callable[[type[C]], type[C]]
Apply stdlib @dataclass + install Field[T] descriptors.
Auto-generated init, repr, eq. No runtime validation.
Example
@typed_dataclass class User: field_int: Field[int] field_str: Field[str]