Python client library for reading Server Sent Event streams.
pip install sseclient
from sseclient import SSEClient messages = SSEClient('http://mysite.com/sse_stream/') for msg in messages: do_something_useful(msg)
Each message object will have a ‘data’ attribute, as well as optional ‘event’, ‘id’, and ‘retry’ attributes.
Optional init parameters:
You may also provide any additional keyword arguments supported by the Requests library, such as a ‘headers’ dict and a (username, password) tuple for ‘auth’.
Install the library in editable mode:
pip install -e .
Install the test dependencies:
pip install pytest backports.unittest_mock
Run the tests with py.test:
(sseclient)vagrant sseclient $ py.test ===================== test session starts ====================== platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2 rootdir: /vagrant/code/sseclient, inifile: plugins: backports.unittest-mock collected 11 items test_sseclient.py ........... ================== 11 passed in 0.19 seconds ===================
There are a couple TODO items in the code for getting the implementation completely in line with the finer points of the SSE spec.