Skip to content

models

Here's the reference for the SQLAlchemy model mixins provided by the models module.

You can import them directly from fastapi_toolsets.models:

from fastapi_toolsets.models import (
    EventSession,
    ModelEvent,
    UUIDMixin,
    UUIDv7Mixin,
    CreatedAtMixin,
    UpdatedAtMixin,
    TimestampMixin,
    listens_for,
)

fastapi_toolsets.models.EventSession

Bases: AsyncSession

AsyncSession subclass that dispatches lifecycle callbacks after commit.

fastapi_toolsets.models.ModelEvent

Bases: str, Enum

Event types dispatched by :class:EventSession.

fastapi_toolsets.models.UUIDMixin

Mixin that adds a UUID primary key auto-generated by the database.

fastapi_toolsets.models.UUIDv7Mixin

Mixin that adds a UUIDv7 primary key auto-generated by the database.

fastapi_toolsets.models.CreatedAtMixin

Mixin that adds a created_at timestamp column.

fastapi_toolsets.models.UpdatedAtMixin

Mixin that adds an updated_at timestamp column.

fastapi_toolsets.models.TimestampMixin

Bases: CreatedAtMixin, UpdatedAtMixin

Mixin that combines created_at and updated_at timestamp columns.

fastapi_toolsets.models.listens_for(model_class, event_types=None)

Register a callback for one or more model lifecycle events.

Parameters:

Name Type Description Default
model_class type

The SQLAlchemy model class to listen on.

required
event_types list[ModelEvent] | None

List of :class:ModelEvent values to listen for. Defaults to all event types.

None