Registry / http-networking / aiohttp-sse-client2

aiohttp-sse-client2

JSON →
library0.3.0pypypi✓ verified 22d ago

aiohttp-sse-client2 is a Python client library for Server-Sent Events (SSE) built on top of aiohttp, providing a straightforward interface for consuming event streams. It is a fork of the original `aiohttp-sse-client` project, featuring improved error messages and updated compatibility with newer Python versions. The current version is 0.3.0, released in February 2023, indicating an infrequent release cadence.

pip install aiohttp-sse-client2
INSTALL
IMPORT
SIG · AIOHTTP-SSE-CLIENT
A
aiohttp-sse-client2
http-networkingpythonv0.3.0
Install
4.0s avg
Import
581ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.612s · 27MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.550s · 29MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EventSource
from aiohttp_sse_client2 import client as sse_client # then use sse_client.EventSource

This quickstart demonstrates connecting to a public SSE stream and iterating over incoming events. It also includes basic error handling for common connection issues. For long-running connections, consider configuring `aiohttp.ClientTimeout` explicitly.

import asyncio from aiohttp_sse_client2 import client as sse_client async def main(): # Replace with your SSE endpoint sse_url = "https://stream.wikimedia.org/v2/stream/recentchange" # It's recommended to pass an aiohttp.ClientSession with a custom timeout # if long-lived connections are expected (e.g., timeout=aiohttp.ClientTimeout(total=None)) # For this quickstart, we'll use the default behavior. async with sse_client.EventSource(sse_url) as event_source: try: async for event in event_source: print(f"Received event: {event.id} - {event.event} - {event.data}") except ConnectionError: print("Connection closed unexpectedly or failed to establish.") except asyncio.TimeoutError: print("Connection timed out.") except Exception as e: print(f"An unexpected error occurred: {e}") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingPython version support has changed between major versions. Version 0.2.0 dropped support for Python 3.5, and version 0.3.0 dropped support for Python 3.6.
fix
Ensure your environment uses Python 3.7 or newer for version 0.3.0, or Python 3.6 or newer for 0.2.x releases.
affects: 0.2.0, 0.3.0
gotchaThe underlying `aiohttp.ClientSession` used by `EventSource` has a default total timeout (typically 5 minutes). For long-lived SSE connections, this can lead to `asyncio.TimeoutError` or `ClientOSError: [Errno 104] Connection reset by peer` even with server-side keep-alives.
fix
When initializing `EventSource`, pass a custom `aiohttp.ClientSession` with an explicitly configured timeout, typically `aiohttp.ClientTimeout(total=None)` for indefinite connections, or a sufficiently large value. Example: `session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=None))` then `sse_client.EventSource(url, session=session)`.
affects: All versions
gotchaThis library is a fork of `aiohttp-sse-client`, and its long-term maintenance is conditional: 'The fork will be retired if the upstream package comes back alive.'
fix
Be aware of the project's fork status. Monitor the GitHub repository for updates regarding its maintenance and consider the implications for long-term project stability if the original `aiohttp-sse-client` project becomes active again.
affects: All versions
gotchaAsynchronous network operations are inherently prone to disconnections. The quickstart example explicitly includes `except ConnectionError: pass`, indicating that connection failures are common and client applications should implement robust error handling and reconnection logic.
fix
Implement comprehensive `try...except` blocks around the event iteration to gracefully handle `ConnectionError`, `asyncio.TimeoutError`, and other network-related exceptions. Consider adding retry mechanisms with exponential backoff for resilience.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'aiohttp_sse_client2'
The 'aiohttp_sse_client2' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install aiohttp-sse-client2'.
ImportError: cannot import name 'EventSource' from 'aiohttp_sse_client2.client'
The import statement is incorrect or the 'EventSource' class does not exist in the specified module.
fix
Ensure the correct import statement: 'from aiohttp_sse_client2 import client as sse_client'.
AttributeError: module 'aiohttp_sse_client2.client' has no attribute 'EventSource'
The 'EventSource' class is not defined in the 'client' module of 'aiohttp_sse_client2'.
fix
Verify the library's documentation for the correct usage and available classes.
TypeError: 'NoneType' object is not iterable
Attempting to iterate over a 'None' object, possibly due to a failed connection or missing event source.
fix
Check the connection to the event source and ensure it returns a valid iterable object.
RuntimeError: Event loop is closed
The asyncio event loop has been closed before all asynchronous tasks were completed.
fix
Ensure the event loop remains open until all tasks are finished, or restart the event loop if necessary.
Upgrade
Version history
0.3.0latest on PyPI · released Feb 7, 2023
Audit
Dependencies
aiohttprequiredThe library is built on aiohttp for asynchronous HTTP client capabilities.
Agent activity
39 hits · last 30 days
node
30
OpenAI (training)
2
Amazon
1
Resources
aiohttp-sse-client2 — pip install aiohttp-sse-client2 · libregistry