SSE (Server Sent Events)#
- class litestar.response.sse.ServerSentEvent#
Bases:
Stream
- __init__(content: str | bytes | StreamType[str | bytes], *, background: BackgroundTask | BackgroundTasks | None = None, cookies: ResponseCookies | None = None, encoding: str = 'utf-8', headers: ResponseHeaders | None = None, event_type: str | None = None, event_id: int | None = None, retry_duration: int | None = None, comment_message: str | None = None, status_code: int | None = None) None #
Initialize the response.
- Parameters:
content – Bytes, string or a sync or async iterator or iterable.
background – A
BackgroundTask
instance orBackgroundTasks
to execute after the response is finished. Defaults to None.cookies – A list of
Cookie
instances to be set under the responseSet-Cookie
header.encoding – The encoding to be used for the response headers.
headers – A string keyed dictionary of response headers. Header keys are insensitive.
status_code – The response status code. Defaults to 200.
event_type – The type of the SSE event. If given, the browser will sent the event to any ‘event-listener’ declared for it (e.g. via ‘addEventListener’ in JS).
event_id – The event ID. This sets the event source’s ‘last event id’.
retry_duration – Retry duration in milliseconds.
comment_message – A comment message. This value is ignored by clients and is used mostly for pinging.