Skip to main content
Help us improve Python packaging – donate today!

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

Project Description

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

from flask import Flask
from flask.ext.uwsgi_websocket import WebSocket

app = Flask(__name__)
ws = WebSocket(app)

@ws.route('/echo')
def echo(ws):
    while True:
        msg = ws.receive()
        ws.send(message)

Installation

To install Flask-uWSGI-WebSocket, simply:

$ pip install Flask-uWSGI-WebSocket

Deployment

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

$ uwsgi --master --http :8080 --http-websockets --wsgi-file app.py

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

$ uwsgi –master –http :8080 –http-websockets –gevent 100 –wsgi-file app.py

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

Development

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 app.py

If you specify app.debug = True, Flask-uWSGI-Websocket will do this automatically for you.

API

Flask-uWSGI-Websocket automatically performs the WebSocket handshake for you and passes your router a websocket client exposing uWSGI’s WebSocket API.

websocket.recv()

websocket.send(msg)

websocket.send_binary(msg)

websocket.recv_nb()

websocket.send_from_sharedarea(id, pos)

websocket.send_binary_from_sharedarea(id, pos)

In addition there is a special websocket.receive() method which makes using non-blocking calls simpler.

Release history Release notifications

History Node

0.6.0

History Node

0.5.3

History Node

0.5.2

History Node

0.5.1

History Node

0.5.0

History Node

0.4.5

History Node

0.4.4

History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4.0

History Node

0.3.0

History Node

0.2.10

History Node

0.2.9

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.0

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

This version
History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Flask-uWSGI-WebSocket-0.0.3.tar.gz (3.1 kB) Copy SHA256 hash SHA256 Source None Jan 21, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page