Skip to main content

ServerSentEvent

This class represents a single Server-Sent Event. When yielded from a path operation function using response_class=EventSourceResponse, each ServerSentEvent is encoded into the SSE wire format (text/event-stream). If a plain object is yielded instead, it is automatically JSON-encoded and sent as the data: field.

Attributes

AttributeTypeDescription
dataAny = NoneThe event payload. Can be any JSON-serializable value: a Pydantic model, dict, list, string, number, etc. It is always serialized to JSON: strings are quoted ("hello" becomes data: "hello" on the wire). Mutually exclusive with raw_data.
raw_data`strNone` = None
event`strNone` = None
id`strNone` = None
retry`intNone` = None
comment`strNone` = None