You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

flask-queue-sse

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flask-queue-sse

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

0.1.3
pipPyPI
Maintainers
1
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:

📰 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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts