Server-Sent Events for Flask
Python
Switch branches/tags
Nothing to show
Latest commit a5c6afe Jan 15, 2017 @singingwolfboy committed on GitHub Merge pull request #2 from wgwz/master
Add doc snippets for configuring redis with passwords
Permalink
Failed to load latest commit information.
docs Add doc snippets for configuring redis with passwords Jan 15, 2017
tests Test specifying channel via query arg Apr 12, 2016
.gitignore
.gitmodules Initial commit Apr 11, 2016
.travis.yml flask_sse not flask_dance Apr 12, 2016
CHANGELOG.rst
LICENSE Initial commit Apr 11, 2016
MANIFEST.in Packaging fixes Apr 12, 2016
README.rst remove unused json from README Apr 13, 2016
flask_sse.py
setup.cfg
setup.py

README.rst

Flask SSE Build status Test coverage Documentation

A Flask extension for HTML5 server-sent events support, powered by Redis.

Example of sending events:

from flask import Flask
from flask_sse import sse

app = Flask(__name__)
app.config["REDIS_URL"] = "redis://localhost"
app.register_blueprint(sse, url_prefix='/stream')

@app.route('/send')
def send_message():
    sse.publish({"message": "Hello!"}, type='greeting')
    return "Message sent!"

To receive events on a webpage, use Javascript to connect to the event stream, like this:

var source = new EventSource("{{ url_for('sse.stream') }}");
source.addEventListener('greeting', function(event) {
    var data = JSON.parse(event.data);
    // do what you want with this data
}, false);

The full documentation for this project is hosted on ReadTheDocs.