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
_format_error_event
2
str
▼
Format an error as an SSE event for a failed render.
For ``Fragment`` values, …
_format_error_event
2
str
▼
def _format_error_event(value: Any, exc: Exception) -> str
Format an error as an SSE event for a failed render.
ForFragmentvalues, uses the fragment's target as the SSE event
name so the error replaces the specific block in the DOM. This lets
the developer see exactly which block broke, inline where it should be.
For other value types, sends a genericerrorevent.
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
|
exc |
Exception |
Returns
str