aiohttp-sse provides server-sent events support for aiohttp. It allows building real-time web applications where the server pushes updates to clients over a single HTTP connection. The current version is 2.2.0, and it has a relatively active release cadence with several updates per year, focusing on Python and aiohttp compatibility.
pip install aiohttp-sseVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up an aiohttp web server that serves an HTML page. The HTML page contains JavaScript that connects to a '/hello' endpoint via Server-Sent Events. The '/hello' endpoint uses `aiohttp-sse`'s `sse_response` context manager to continuously send the current server time to the connected client.
Upgrade Python to 3.8 or newer, or pin to an older `aiohttp-sse` version compatible with your Python environment.
Check the `aiohttp-sse` release notes for the exact `aiohttp` version compatibility. Upgrade both `aiohttp-sse` and `aiohttp` to compatible versions.
Send an initial 'comment' event (e.g., `await resp.send(None, event='comment', data='connected')`) after establishing the SSE connection. This signals the browser that the connection is live and usually stops the spinner.
Upgrade to `aiohttp-sse` version 2.2.0 or newer to benefit from the fix for `EventSourceResponse.wait()` cancellation behavior on Python 3.11+.
For client-side SSE consumption, consider using dedicated libraries like `aiohttp-sse-client` or `aiosseclient` built on top of `aiohttp`, or implement custom parsing logic.
Design client-side applications to manage and reuse SSE connections efficiently. Avoid opening an excessive number of simultaneous SSE streams from the same client to the same server. Adjusting browser settings (e.g., `network.http.speculative-parallel-limit` in Firefox) can also be done for testing, but is not a general solution for users.
Install the package using pip: 'pip install aiohttp-sse'.
Use 'sse_response' instead: 'from aiohttp_sse import sse_response'.
Use 'sse_response' which provides the 'send' method: 'from aiohttp_sse import sse_response'.
Install the library using pip: `pip install aiohttp-sse`
Rename any local file named `aiohttp.py` to something else (e.g., `my_aiohttp_app.py`). Ensure you are using `aiohttp.ClientSession()` for client requests, as direct `aiohttp.get()` was deprecated.