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.
pip install httpx-sseVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade to Python 3.8 or newer. The library requires Python >=3.9 since 0.4.0.
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.
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.
If you experienced performance degradation after upgrading to `0.4.2`, update to `0.4.3` or newer to resolve the issue.
Install `httpx` using `pip install httpx`.
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`).