Server-Sent Events
Streaming endpoints over text/event-stream. There are two entry points:
ServerSentEventsAPIView(fastapi_views.views.sse) — a view whose abstracteventsaction yields events; the route, framing, and OpenAPI content are generated for you.@sse_route(fastapi_views.views.functools) — decorate any method on aViewto turn its (async) iterator of events into a streaming route.
Event models live in fastapi_views.models (BaseServerSentEvent, IdBaseServerSentEvent, AnyServerSentEvent); any object matching the fastapi_views.types.ServerSentEventType protocol (id, event, data, retry) can be yielded.
For a complete walkthrough see Server Side Events.
Views
ServerSentEventsAPIView
Bases: APIView, Generic[P]
API view streaming Server-Sent Events yielded by the events action.
Source code in fastapi_views/views/sse.py
Route decorator
fastapi_views.views.functools.sse_route(path: str = '', serializer_options: SerializerOptions | None = None, headers: dict[str, str] | None = None, **kwargs: Unpack[RouteOptions]) -> Any
Source code in fastapi_views/views/functools.py
Streaming event models
Discriminated lifecycle events for long-running streamed operations, in
fastapi_views.models.streaming.
Universal responses schemas for streaming results, for example with SSE, loosely inspired by OpenAI responses API
TimestampData
Bases: BaseSchema
Payload base carrying the UTC timestamp of the event.
Source code in fastapi_views/models/streaming.py
StartedData
Bases: TimestampData
Payload of :class:ResponseStarted.
Source code in fastapi_views/models/streaming.py
ResponseStarted
Bases: _BaseEvent
Event emitted when the response stream starts.
Source code in fastapi_views/models/streaming.py
ErrorData
ResponseError
Bases: _BaseEvent
Event emitted when the stream fails with an error.
Source code in fastapi_views/models/streaming.py
ResultData
Bases: BaseSchema, Generic[T]
Payload of :class:ResponseResult: a batch of result items.
Source code in fastapi_views/models/streaming.py
ResponseResult
Bases: _BaseEvent, Generic[T]
Event carrying a batch of result items.
Source code in fastapi_views/models/streaming.py
FinishedData
Bases: TimestampData
Payload of :class:ResponseFinished.
Source code in fastapi_views/models/streaming.py
ResponseFinished
Bases: _BaseEvent
Event emitted when the stream completes successfully.
Source code in fastapi_views/models/streaming.py
CancelledData
Bases: TimestampData
Payload of :class:ResponseCancelled.
Source code in fastapi_views/models/streaming.py
ResponseCancelled
Bases: _BaseEvent
Event emitted when the stream is cancelled.