Functions
handle_sse
7
None
▼
Stream Server-Sent Events over an ASGI connection.
1. Sends ``http.response.st…
async
handle_sse
7
None
▼
async def handle_sse(event_stream: EventStream, send: Send, receive: Receive, *, kida_env: Environment | None = None, debug: bool = False, retry_ms: int | None = None, close_event: str | None = None) -> None
Stream Server-Sent Events over an ASGI connection.
- Sends
http.response.startwithtext/event-streamheaders. - Launches two concurrent tasks:
- Event producer: consumes the async generator, converts each yielded value to SSE wire format, and sends as ASGI body chunks.
- Disconnect monitor: awaits
http.disconnectfrom the client and cancels the producer.
- Sends periodic heartbeat comments (
:) on idle.
Parameters
| Name | Type | Description |
|---|---|---|
event_stream |
EventStream |
|
send |
Send |
|
receive |
Receive |
|
kida_env |
Environment | None |
Default:None
|
debug |
bool |
Default:False
|
retry_ms |
int | None |
Default:None
|
close_event |
str | None |
Default:None
|
_format_event
3
str
▼
Convert a yielded value to SSE wire format.
Dispatch:
- ``SSEEvent`` -> en…
_format_event
3
str
▼
def _format_event(value: Any, *, default_event: str | None = None, kida_env: Environment | None = None) -> str
Convert a yielded value to SSE wire format.
Dispatch:
SSEEvent-> encode as-isFragment-> render via kida, wrap with event: fragmentstr-> wrap as datadict-> JSON-serialize as data
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
|
default_event |
str | None |
Default:None
|
kida_env |
Environment | None |
Default:None
|
Returns
str