Server-Sent Events — Aquilia Documentation
Comprehensive guide and documentation for Server-Sent Events in the Aquilia framework. View API reference, examples, and implementation patterns.
SSE SYSTEM / OVERVIEW Server-Sent Events (SSE) Unidirectional real-time server push for Aquilia applications. Learn how the SSE subsystem keeps connection channels open to stream updates dynamically over standard HTTP. What is SSE? Server-Sent Events (SSE) is a web technology enabling servers to push real-time event updates to clients over a single long-lived TCP connection. Defined as part of the HTML5 standard, it is natively supported by all modern browsers via the EventSource API. Unlike WebSockets, which are bi-directional and require custom handshake protocols, SSE operates over standard HTTP, making it simpler to deploy, compatible with HTTP/2 multiplexing, and highly resilient through automatic client-side reconnection. Aquilia SSE Architecture In Aquilia, SSE streams are managed by SSEResponse . When returned from a controller method, it binds an asynchronous event iterator directly into the ASGI server write pipeline. The server streams bytes chunk-by-chunk, flushing buffers immediately after each event is written. import asyncio from aquilia.controller import Controller, GET, RequestCtx from aquilia.sse import SSEResponse, SSEEvent class LiveController(Controller): @GET("/sse/stream") async def stream_live(self, ctx: RequestCtx): # Wraps an async generator yielding SSEEvent objects return SSEResponse(self._event_source()) async def _event_source(self): for i in range(5): yield SSEEvent(data=f"message ") await asyncio.sleep(1.0) Protocol Transport Headers To prevent proxies and browsers from buffering or caching events, the SSEResponse engine configures the following transport headers automatically: Content-Type: set to text/event-stream; charset=utf-8. Cache-Control: set to no-cache, no-transform to bypass intermediate proxy memory caches. Connection: set to keep-alive to instruct ASGI servers to preserve the request connection channel. X-Accel-Buffering: set to no. This tells Nginx to disable buffering and stream output immediately. Custom Effects Standard Events )
Go to Homepage