{"id":641,"library":"httpx-sse","title":"httpx-sse","description":"httpx-sse is a Python library designed to consume Server-Sent Event (SSE) messages, integrating seamlessly with the HTTPX client. It provides both synchronous and asynchronous helpers to connect to SSE endpoints and iterate over the received events. Currently at version 0.4.3, the library is actively maintained with regular updates and fixes.","status":"active","version":"0.4.3","language":"python","source_language":"en","source_url":"https://github.com/florimondmanca/httpx-sse","tags":["http","sse","event-stream","httpx","client","async"],"install":[{"cmd":"pip install httpx-sse","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Core dependency for making HTTP requests. The library is built as an extension for HTTPX.","package":"httpx","optional":false}],"imports":[{"wrong":"from httpx_sse import connect_sse","symbol":"connect_sse","correct":"from httpx_sse import connect_sse"}],"quickstart":{"code":"import asyncio\nimport httpx\nfrom httpx_sse import aconnect_sse, ServerSentEvent\nimport os\n\nasync def consume_sse_stream(url: str):\n    # Ensure a long enough timeout for SSE streams, or set to None\n    # if the stream is expected to be indefinite.\n    # httpx.AsyncClient(timeout=None) or httpx.Timeout(60.0, connect=5.0)\n    async with httpx.AsyncClient(timeout=None) as client:\n        try:\n            async with aconnect_sse(client, \"GET\", url) as event_source:\n                async for sse in event_source.aiter_sse():\n                    print(f\"Event: {sse.event}, Data: {sse.data}, ID: {sse.id}, Retry: {sse.retry}\")\n                    if sse.event == \"end\":\n                        break\n        except httpx.RequestError as exc:\n            print(f\"An error occurred while requesting {exc.request.url!r}: {exc}\")\n        except Exception as e:\n            print(f\"An unexpected error occurred: {e}\")\n\n# Example usage (replace with your actual SSE endpoint)\n# For local testing, you might run a simple SSE server.\nSSE_ENDPOINT_URL = os.environ.get(\"SSE_TEST_URL\", \"http://localhost:8000/sse\")\n\nif __name__ == \"__main__\":\n    print(f\"Connecting to SSE endpoint: {SSE_ENDPOINT_URL}\")\n    asyncio.run(consume_sse_stream(SSE_ENDPOINT_URL))\n","lang":"python","description":"Demonstrates how to establish an asynchronous connection to an SSE endpoint using `aconnect_sse` and iterate through incoming `ServerSentEvent` objects. It includes error handling and a common pattern for managing HTTPX client timeouts, which is crucial for long-lived SSE connections."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer. The library requires Python >=3.9 since 0.4.0.","message":"Python 3.7 support was officially dropped as it reached End-of-Life.","severity":"breaking","affected_versions":"0.4.0 and later"},{"fix":"If your code relied on `SSEError` being raised immediately during connection, you might need to adjust error handling to occur during iteration, or explicitly check `event_source.response.headers['Content-Type']` before iterating.","message":"The timing of `SSEError` (for non `text/event-stream` Content-Type) was moved from `connect_sse()` to `iter_sse()`/`aiter_sse()`. This allows inspecting the raw response before content type validation.","severity":"gotcha","affected_versions":"0.3.0 and later"},{"fix":"Ensure your SSE server emits events strictly according to the SSE specification to avoid unexpected parsing behavior or silent data loss. Update to `0.4.2` or later for correct parsing.","message":"Incorrect newline parsing that was not compliant with the SSE specification was fixed. If you were working around previous parsing quirks, your code might need adjustment.","severity":"gotcha","affected_versions":"0.4.2"},{"fix":"If you experienced performance degradation after upgrading to `0.4.2`, update to `0.4.3` or newer to resolve the issue.","message":"A performance issue was introduced in `0.4.2` due to improved line parsing, which was subsequently fixed.","severity":"gotcha","affected_versions":"0.4.2"},{"fix":"Install `httpx` using `pip install httpx`.","message":"The `httpx` library is a required dependency. Failure to install it will result in a `ModuleNotFoundError`.","severity":"breaking","affected_versions":"all versions"},{"fix":"Ensure `httpx` is installed in your environment by running `pip install httpx`. If you are installing the main library, ensure its dependencies are correctly resolved (e.g., install it within a virtual environment or avoid `pip install --no-deps`).","message":"A required dependency, `httpx`, was not found. This error occurs when the `httpx` library is not installed in the execution environment, preventing the application from running.","severity":"breaking","affected_versions":"all versions"}],"env_vars":null,"search_vec":"'0.4.3':47 'activ':51 'async':65 'asynchron':31 'client':25,64 'connect':34 'consum':13 'current':44 'design':11 'endpoint':37 'event':17,43,61 'event-stream':60 'fix':57 'helper':32 'http':58 'httpx':2,5,24,63 'httpx-sse':1,4 'integr':20 'iter':39 'librari':10,49 'maintain':52 'messag':19 'provid':27 'python':9 'receiv':42 'regular':54 'seamless':21 'sent':16 'server':15 'server-s':14 'sse':3,6,18,36,59 'stream':62 'synchron':29 'updat':55 'version':46","created_at":"2026-03-28T17:08:28.683265+00:00","updated_at":"2026-04-16T15:38:04.865437+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmpv068xvej/venv/lib/python3.12/site-packages/httpx_sse/__init__.py\", line 1, in <module>\n    from ._api import EventSource, aconnect_sse, connect_sse\n  File \"/tmp/tmpv068xvej/venv/lib/python3.12/site-packages/htt"},"ecosystem":"pypi","meta_description":null,"install_score":0,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"0.4.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/florimondmanca/httpx-sse","docs":null,"changelog":null,"pypi":"https://pypi.org/project/httpx-sse/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":"stale"}}