{"id":4871,"library":"aiohttp-sse-client2","title":"aiohttp-sse-client2","description":"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.","status":"active","version":"0.3.0","language":"en","source_language":"en","source_url":"https://github.com/JelleZijlstra/aiohttp-sse-client2","tags":["asyncio","aiohttp","sse","client","server-sent events"],"install":[{"cmd":"pip install aiohttp-sse-client2","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"The library is built on aiohttp for asynchronous HTTP client capabilities.","package":"aiohttp"}],"imports":[{"symbol":"EventSource","correct":"from aiohttp_sse_client2 import client as sse_client\n# then use sse_client.EventSource"}],"quickstart":{"code":"import asyncio\nfrom aiohttp_sse_client2 import client as sse_client\n\nasync def main():\n    # Replace with your SSE endpoint\n    sse_url = \"https://stream.wikimedia.org/v2/stream/recentchange\"\n    \n    # It's recommended to pass an aiohttp.ClientSession with a custom timeout\n    # if long-lived connections are expected (e.g., timeout=aiohttp.ClientTimeout(total=None))\n    # For this quickstart, we'll use the default behavior.\n    \n    async with sse_client.EventSource(sse_url) as event_source:\n        try:\n            async for event in event_source:\n                print(f\"Received event: {event.id} - {event.event} - {event.data}\")\n        except ConnectionError:\n            print(\"Connection closed unexpectedly or failed to establish.\")\n        except asyncio.TimeoutError:\n            print(\"Connection timed out.\")\n        except Exception as e:\n            print(f\"An unexpected error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"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.","message":"Python 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.","severity":"breaking","affected_versions":"0.2.0, 0.3.0"},{"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)`.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"This 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.'","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Asynchronous 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}