Skip to main content

This is a Python client library for iterating over http Server Sent Event (SSE) streams (also known as EventSource, after the name of the Javascript interface inside browsers). The SSEClient class accepts a url on init, and is then an iterator over messages coming from the server.

Installation

Use pip:

pip install sseclient

Usage

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:

  • last_id: If provided, this parameter will be sent to the server to tell it to return only messages more recent than this ID.

  • retry: Number of milliseconds to wait after disconnects before attempting to reconnect. The server may change this by including a ‘retry’ line in a message. Retries are handled automatically by the SSEClient object.

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’.

Development

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.

Additional Resources

Release files for sseclient 0.0.23

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sseclient 0.0.23
File Size Uploaded
sseclient-0.0.23.tar.gz 6.8 kB Details

Release files / sseclient-0.0.23.tar.gz

Download URL sseclient-0.0.23.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
82a1d281b2bcb98847882069bde57a6772156f9539ddefbb78fea4f915197ec3
BLAKE2b-256 checksum
How to use checksums
e1cc4e186ec4365dcbfd17f466db59c69b5185e993ec8818dda2782ecf7f2047
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.5

Release history Release notifications | RSS feed

0.0.27

1 release file

0.0.26

1 release file

0.0.25

1 release file

0.0.24

1 release file

This release

0.0.23 This release

1 release file

0.0.22

1 release file

0.0.20

1 release file

0.0.19

1 release file

0.0.18

1 release file

0.0.17

1 release file

0.0.15

1 release file

0.0.14

1 release file

0.0.13

1 release file

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page