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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-SSE-1.0.0.tar.gz
(16.2 kB
view hashes)
Built Distribution
Close
Hashes for Flask_SSE-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f86d7ecff0607333755c444130c395e7a133fb7ae6cf76fbd29b1da36d34776b |
|
MD5 | ca76365a57e16292f6c3bac6126f3266 |
|
BLAKE2b-256 | 7183f9fe86f554a153fdd300fb8027121d508a2177605bd158d967ddd7325948 |