Skip to main content

Server-Sent Events for Flask

Project description

Flask SSE Datastar Build Status Test Coverage Documentation

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

This version has had a minor change so that it works with Datastar.

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.

Source Distribution

flask-sse-datastar-0.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_sse_datastar-0.1.0-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file flask-sse-datastar-0.1.0.tar.gz.

File metadata

  • Download URL: flask-sse-datastar-0.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.4

File hashes

Hashes for flask-sse-datastar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efa56e1794c9ac874c4662b56ece2e0be8067525f13355feb70119e8ff39a877
MD5 ecb911a4c49fed1de127c22d1ade3dea
BLAKE2b-256 8a538c75690efaf45d380ca8d76b22f2e2fe930addaa52b61ae3ad1c7f23f0b8

See more details on using hashes here.

File details

Details for the file flask_sse_datastar-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sse_datastar-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 202960ed31c4bad3b7dff6fb2357b581ff0e898733c735cd9472039a56eacd6e
MD5 4e7666882e634d57203252e8ab9c269a
BLAKE2b-256 4150f79e6246bf0448eacf99fc366f999967f4d694b78ba17540b61e9a3df5ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page