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
| Attribute | Type | Description |
|---|---|---|
| data | Any = None | The 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 | `str | None` = None |
| event | `str | None` = None |
| id | `str | None` = None |
| retry | `int | None` = None |
| comment | `str | None` = None |