Streaming & Server-Sent Events
Large downloads and real-time push โ over plain WSGI, no websockets.
@app.get("/export.csv")
class=kw>def export(req):
class=kw>return Response.stream(rows_as_csv(), content_type="text/csv")
Response.stream(iterable) yields str/bytes chunks lazily, so you can produce a large
CSV or file without buffering it in memory.
Server-Sent Events
@app.get("/events")
class=kw>def events(req):
class=kw>def stream():
for i in range(10):
yield ("tick", str(i)) class=com># (event, data) โ or just a data string
time.sleep(1)
class=kw>return Response.sse(stream())
SSE is a one-directional real-time channel that works on any WSGI server โ ideal for live
dashboards, progress bars, notifications and log tails. Larz frames each item as
text/event-stream. Full bidirectional WebSockets arrive with the async core.
Guide: Server-Sent Events in Python.