Skip to main content

Python client library for reading Server Sent Event streams.

Project description

This is a Python client library for iterating over http Server Sent Event (SSE) streams. 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 test dependencies:

pip install pytest mock

And run the tests:

$ py.test
================== test session starts ===================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
collected 9 items

test_sseclient.py .........

================ 9 passed in 0.31 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sseclient-0.0.9.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file sseclient-0.0.9.tar.gz.

File metadata

  • Download URL: sseclient-0.0.9.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sseclient-0.0.9.tar.gz
Algorithm Hash digest
SHA256 b3aaab590af2ea8404bf1b442fc10d1aa631090236fc3375524364a03b2a1c70
MD5 3a615796daeab80ef3de146746243a34
BLAKE2b-256 6c876f71df6ff232f4b557b27fde5066a820aa0ad3eccf2279e8b9938b4e2e80

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page