Skip to main content

Server-Sent Events for Flask

Project description

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.

Project details


Download files

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

Files for Flask-SSE, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size Flask_SSE-0.2.1-py2.7.egg (7.6 kB) File type Egg Python version 2.7 Upload date Hashes View hashes
Filename, size Flask_SSE-0.2.1-py2.py3-none-any.whl (5.9 kB) File type Wheel Python version 2.7 Upload date Hashes View hashes
Filename, size Flask-SSE-0.2.1.tar.gz (482.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page