Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

heroku-python/flask-sockets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Flask-Sockets

Elegant WebSockets for your Flask apps.

from flask import Flask
from flask_sockets import Sockets

app = Flask(__name__)
sockets = Sockets(app)

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

@app.route('/')
def hello():
    return 'Hello World!'

Serving WebSockets in Python were really difficult. Now they're not.

Deployment

A custom Gunicorn worker is included to make deployment as friendly as possible:

$ gunicorn -k flask_sockets.worker hello:app

Production services are provided by gevent and gevent-websocket.

Anything that inserts wsgi.websocket into the WSGI environ is supported, but gevent-websocket is recommended.

WebSocket Interface

The websocket interface that is passed into your routes is provided by gevent-websocket. The basic methods are fairly straitforward — send, receive, send_fname, and close.

Hopefully, more documentation will be available soon.

About

[DEPRECATED] Alternative: https://github.com/miguelgrinberg/flask-sock

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages