Skip to main content

A simple implementation of Server-Sent Events for Flask that doesn't require Redis pub/sub.

Project description

flask-queue-sse

A simple implementation of Server-Sent Events for Flask that doesn't require Redis pub/sub.


flask-queue-sse is my first ever Python library. It implements the Server-Sent Events protocol using the built-in Python Queue class. Please read why this package before using it in production.

Tweet to me @vsnthdev, I'd love to know your experience of this project 😀

💡 Why this package

Most implementations of Server-Sent Events available in PyPi for Flask require having a Redis database. This is to support horizontal scaling.

This library targets projects that don't want to deploy Redis seperately to get SSE working, and aren't aiming to horizontally scale (have multiple instances of your app running behind a load balancer).

💿 Installation

pip install flask-queue-sse

Python 3.10 and above is required.

🚀 Quick start

After installing flask-queue-sse, you can start using it in the following way:

from flask import Flask
from flask_queue_sse import ServerSentEvents

app = Flask(__name__)

# storing sse events channel in memory
sse: ServerSentEvents = None

@app.route("/subscribe")
def subscribe():
    # telling Python to refer to global sse variable
    global sse

    # create a new server sent events channel
    sse = ServerSentEvents()

    # create a new thread and do the actual work
    # on it, pass sse instance to it for emitting events
    
    # when an "error" or "end" event is emitted
    # the connection closes

    # return it as a response
    return sse.response()

Look into the examples or send me a message for any queries, questions or issues. I'm always happy to help 😊

💻 Building the project

  • 📁 Clone the repository.
  • 🏝️ Enter into the clonned directory & run python -m venv . to create a virtual environment.
  • 🔨 Install dependencies by running pip install -r ./requirements.txt.
  • 👨‍💻 Run the examples or edit the codebase.

🏷️ Referrences

This library has been inspired by, and developed after consuming following resources:

  1. Server-sent events in Flask without extra dependencies
  2. Why do I need redis?

📰 License

The flask-queue-sse project is released under the Zlib license.
Developed & maintained By Vasanth Srivatsa. Copyright 2023 © Vasanth Developer.


vsnth.dev  ·  YouTube @VasanthDeveloper  ·  Twitter @vsnthdev  ·  LinkedIn Vasanth Srivatsa

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_queue_sse-0.1.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

flask_queue_sse-0.1.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file flask_queue_sse-0.1.3.tar.gz.

File metadata

  • Download URL: flask_queue_sse-0.1.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Windows/10

File hashes

Hashes for flask_queue_sse-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b5ed11976bbaa4c61ed188bde3154244db9cc22ef6ea9f3ad7c33f8c5df3419d
MD5 ecebad1c6b5e3d9d99e632c9245bb940
BLAKE2b-256 7440626c44e1a75f1e7c828ccf14731c0be997463e29283802806876722cec7c

See more details on using hashes here.

File details

Details for the file flask_queue_sse-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: flask_queue_sse-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Windows/10

File hashes

Hashes for flask_queue_sse-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3f3dce49396c33545f0c053da612e6cdf36cf35cc34724404241e3ebf72a69da
MD5 18ae45a68152298df561f796c9c0cfc5
BLAKE2b-256 b2641405b9e82609da7908f3c78c0bb55ec008ee2b524cb4d1037de997ed7461

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