GithubHelp home page GithubHelp logo

debian-python-sseclient's Introduction

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.

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

debian-python-sseclient's People

Contributors

fpytloun avatar

Stargazers

HamZag avatar

Watchers

James Cloos avatar  avatar Aleš Komárek avatar Michael Kutý avatar Jakub Pavlik avatar Adam Skotnický avatar Alena Holanova avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.