The `sseclient` library (version 0.0.27) is a Python client for consuming Server-Sent Events (SSE) streams, also known as EventSource. It provides an `SSEClient` class that acts as an iterator, allowing easy processing of messages from a server. This version, last updated in September 2020, handles automatic reconnections and parses event data. While functional, it is no longer actively developed, with more recent and actively maintained forks (e.g., `sseclient-py`) addressing modern Python features and known issues.
pip install sseclientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to an SSE endpoint using `requests` and iterate over incoming Server-Sent Events with `SSEClient`. Each `event` object typically has `data`, and optional `id`, `event` (type), and `retry` attributes.
Consider using a more actively maintained fork like `sseclient-py` (mpetazzoni/sseclient) or explicitly apply the patch from Issue #19 (`https://github.com/btubbs/sseclient/issues/19`) if sticking to `btubbs/sseclient`. Ensure your server sends complete, non-fragmented event data if possible.
For new projects or if encountering persistent issues, evaluate `sseclient-py` (on PyPI, `mpetazzoni/sseclient` on GitHub) which is an actively maintained fork with better Python 3.x and `httpx` integration.
Always include `headers={'Accept': 'text/event-stream'}` in your `requests.get` call to explicitly request an SSE stream.As per warnings, this is a known issue with `sseclient` 0.0.27. Consider using `sseclient-py` which has addressed this, or implement robust error handling around `json.loads` and potentially reassemble fragmented data manually if the server is known to send it that way.
Initialize the `SSEClient` with the `requests.Response` object directly: `client = SSEClient(response)` where `response = requests.get(url, stream=True, ...)`.
Ensure you are using `requests.get()` to initiate the SSE stream. If the server requires parameters, include them as `params` in the `requests.get()` call.