Skip to main content

High-performance WebSockets for your Flask apps powered by uWSGI.

Project description

High-performance WebSockets for your Flask apps powered by uWSGI. Low-level uWSGI WebSocket API access and flexible high-level abstractions for building complex WebSocket applications with Flask. Supports several different concurrency models including Gevent. Inspired by Flask-Sockets.

from flask import Flask
from flask.ext.uwsgi_websocket import GeventWebSocket

app = Flask(__name__)
ws = GeventWebSocket(app)

def echo(ws):
    while True:
        msg = ws.receive()

if __name__ == '__main__':


Preferred method of installation is via pip:

$ pip install Flask-uWSGI-WebSocket


You can use uWSGI’s built-in HTTP router to get up and running quickly:

$ uwsgi --master --http :8080 --http-websockets --wsgi echo:app

…which is what does after wrapping your Flask app:, host='localhost', port=8080, master=true, processes=8)

uWSGI supports several concurrency models, in particular it has nice support for Gevent. If you want to use Gevent, import flask.ext.uwsgi_websocket.GeventWebSocket and configure uWSGI to use the gevent loop engine:

$ uwsgi --master --http :8080 --http-websockets --gevent 100 --wsgi echo:app

…or:, gevent=100)

For production you’ll probably want to run uWSGI behind Haproxy or nginx, instead of using the built-int HTTP router. Explore the uWSGI documentation for more detail about the various concurrency and deployment options.


It’s possible to take advantage of Flask’s interactive debugger by installing werkzeug’s DebuggedApplication middleware:

from werkzeug.debug import DebuggedApplication
app.wsgi_app = DebuggedApplication(app.wsgi_app, True)

…and running uWSGI with only a single worker:

$ uwsgi --master --http :8080 --http-websockets --wsgi-file --workers 1 --threads 8

If you use or export FLASK_UWSGI_DEBUG, Flask-uWSGI-Websocket will do this automatically for you.



Automatically performs WebSocket handshake for you, but otherwise only exposes the uWSGI WebSocket API.

websocket.recv() (alias websocket.receive())





websocket.send_from_sharedarea(id, pos)

websocket.send_binary_from_sharedarea(id, pos)


Fancier WebSocket abstraction that takes advantage of Gevent loop engine. Route handlers are spawned in their own greenlets and able to easily send messages to each other.





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-uWSGI-WebSocket-0.2.2.tar.gz (4.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page