singingwolfboy/flask-sse

Server-Sent Events for Flask

Python

324

37 commits

updated Jun 7, 2024

See the code

README

Flask SSE |build-status| |coverage-status| |docs|
=================================================
A Flask extension for HTML5 `server-sent events`_ support, powered by Redis_.

Example of sending events:

.. code-block:: python

    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:

.. code-block:: javascript

    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. <http://flask-sse.readthedocs.org/>`_

.. _server-sent events: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events
.. _Redis: http://www.redis.io/

.. |build-status| image:: https://github.com/singingwolfboy/flask-sse/workflows/Test/badge.svg
   :target: https://github.com/singingwolfboy/flask-sse/actions?query=workflow%3ATest
   :alt: Build status
.. |coverage-status| image:: http://codecov.io/github/singingwolfboy/flask-sse/coverage.svg?branch=master
   :target: http://codecov.io/github/singingwolfboy/flask-sse?branch=master
   :alt: Test coverage
.. |docs| image:: https://readthedocs.org/projects/flask-sse/badge/?version=latest&style=flat
   :target: http://flask-sse.readthedocs.org/
   :alt: Documentation

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

singingwolfboy/flask-sse

Server-Sent Events for Flask

Python

324

37 commits

updated Jun 7, 2024

See the code

README

Flask SSE |build-status| |coverage-status| |docs|
=================================================
A Flask extension for HTML5 `server-sent events`_ support, powered by Redis_.

Example of sending events:

.. code-block:: python

    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:

.. code-block:: javascript

    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. <http://flask-sse.readthedocs.org/>`_

.. _server-sent events: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events
.. _Redis: http://www.redis.io/

.. |build-status| image:: https://github.com/singingwolfboy/flask-sse/workflows/Test/badge.svg
   :target: https://github.com/singingwolfboy/flask-sse/actions?query=workflow%3ATest
   :alt: Build status
.. |coverage-status| image:: http://codecov.io/github/singingwolfboy/flask-sse/coverage.svg?branch=master
   :target: http://codecov.io/github/singingwolfboy/flask-sse?branch=master
   :alt: Test coverage
.. |docs| image:: https://readthedocs.org/projects/flask-sse/badge/?version=latest&style=flat
   :target: http://flask-sse.readthedocs.org/
   :alt: Documentation

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

Project health

Overall

3.4/10

Maintained

0/10

Code review

0/10
OpenSSF Scorecard

Latest release

1.0.0 · Jan 10, 2021

Releases this year

0

Significant stargazers

Frank Sachsenheim

34 followers · starred Jan 2021

Ujjwal Ojha

57 followers · starred Apr 2018

Jesse

31 followers · starred Feb 2019

takatost

563 followers · starred May 2023