• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python SSE Client

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.

Maintenance

I (btubbs) haven't been using this library in my own work for years, so I put limited time into maintaining it. I will check in on pull requests and issues once per month. If you are interested in providing more active support for the library, please reach out.

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

More Repositories

1

heroku-buildpack-shiny

For deploying apps running on R's "Shiny" web framework
Shell
55
star
2

pgq

An easy-to-use Postgres job queue library, for Go programs. Supports retries and exponential backoff.
Go
47
star
3

datetime

A Go (golang) library for parsing most ISO8601 timestamps
Go
24
star
4

todopy-pg

Clone of https://bitbucket.org/btubbs/todopy-pg, for debugging Heroku+Mercurial issues. Not guaranteed up to date.
JavaScript
17
star
5

spa

A Python micro framework for REST APIs and single-page-applications.
Python
11
star
6

pomegranate

A Postgres migrations tool with an emphasis on safety and transparency
Go
10
star
7

shiny-example-1

The first example from the Shiny tutorial, configured to run on Heroku.
R
7
star
8

thumpy

A Python web server that dynamically scales, crops, and transforms images
Python
6
star
9

garphunql

A Golang client library for making GraphQL requests
Go
5
star
10

graphql-sugar

Some helpers to make common patterns in graphql-go less boilerplatey.
Go
4
star
11

wsgi-jwt-session

A Python WSGI middleware that provides sessions via a JSON Web Token-encoded cookie
Python
2
star
12

haskell-gridfs

Haskell
2
star
13

gofluff

Gofluff is a fork of the Golint tool, adding command line flags for selecting the specific rules that you want to check.
Go
2
star
14

slapdash

Dashboard for software project managers
JavaScript
1
star
15

benadryl-cuttlefish

An exhaustive Benedict Cumberbatch name generator
Python
1
star
16

schmarchive

An inventory browser for Second Life objects, using JSONP
JavaScript
1
star
17

homebrew-nsq

A Homebrew Formula for NSQ that installs plists for both nsqd and nsqlookupd
Ruby
1
star