SSE

Minimal Server-Sent Events with strings, SSEEvent, and Fragment payloads

1 min read 124 words

What It Teaches

Use this example when updates happen after the page is loaded.EventStream opens a long-lived SSE response and the generator yields values over time: plain strings, structuredSSEEvent payloads, or rendered Fragment(...) payloads.

This is intentionally not a Suspense example. Suspense is for initial render; SSE is for post-load updates.

Run It

PYTHONPATH=src python examples/standalone/sse/app.py

Open http://127.0.0.1:8000/.

Test It

pytest examples/standalone/sse/

Contract Surface

SSE examples exercise the per-event boundary: a bad fragment should not casually kill a stream intended to stay open. They also exercise template block cross-references between yieldedFragment(...) values and htmx sse-swap targets.

Source

Next