Skip to content

Instantly share code, notes, and snippets.

@dandynaufaldi
Created October 25, 2020 20:42
Show Gist options
  • Save dandynaufaldi/b0398a5354f6def120c46e7b3288ad3f to your computer and use it in GitHub Desktop.
Save dandynaufaldi/b0398a5354f6def120c46e7b3288ad3f to your computer and use it in GitHub Desktop.
Flask with SSE
import time
from flask import Flask, request
from flask_sse import sse
app = Flask(__name__)
app.config["REDIS_URL"] = "redis://localhost:6379"
app.register_blueprint(sse, url_prefix="/stream")
@app.route("/chat", methods=["POST"])
def chat():
chat = request.json
chat["time"] = time.strftime("%H:%M")
sse.publish(chat, type="chat")
return chat, 201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment