1
1
Flask-uWSGI-WebSocket
2
2
=====================
3
3
High-performance WebSockets for your Flask apps powered by `uWSGI
4
- <http://uwsgi-docs.readthedocs.org/en/latest/> `_. Inspired by `Flask-Sockets
4
+ <http://uwsgi-docs.readthedocs.org/en/latest/> `_. Low-level uWSGI WebSocket API
5
+ access and flexible high-level abstractions for building complex WebSocket
6
+ applications with Flask. Supports several different concurrency models
7
+ including Gevent. Inspired by `Flask-Sockets
5
8
<https://github.com/kennethreitz/flask-sockets> `_.
6
9
7
10
.. code-block :: python
8
11
9
12
from flask import Flask
10
- from flask.ext.uwsgi_websocket import WebSocket
13
+ from flask.ext.uwsgi_websocket import GeventWebSocket
11
14
12
15
app = Flask(__name__ )
13
- ws = WebSocket (app)
16
+ ws = GeventWebSocket (app)
14
17
15
18
@ws.route (' /echo' )
16
19
def echo (ws ):
@@ -19,30 +22,30 @@ High-performance WebSockets for your Flask apps powered by `uWSGI
19
22
ws.send(message)
20
23
21
24
if __name__ == ' __main__' :
22
- app.run(debug = True , threads = 16 )
25
+ app.run(gevent = 100 )
23
26
24
27
Installation
25
28
------------
26
- To install Flask-uWSGI-WebSocket, simply ::
29
+ Preferred method of installation is via pip ::
27
30
28
31
$ pip install Flask-uWSGI-WebSocket
29
32
30
33
Deployment
31
34
----------
32
35
You can use uWSGI's built-in HTTP router to get up and running quickly::
33
36
34
- $ uwsgi --master --http :8080 --http-websockets --wsgi-file app.py
37
+ $ uwsgi --master --http :8080 --http-websockets --wsgi echo: app
35
38
36
- ...or call ``app.run ``, passing uwsgi any arguments you like ::
39
+ ...which is what ``app.run `` does after wrapping your Flask app ::
37
40
38
41
app.run(debug=True, host='localhost', port=8080, master=true, processes=8)
39
42
40
43
uWSGI supports several concurrency models, in particular it has nice support
41
44
for Gevent. If you want to use Gevent, import
42
45
``flask.ext.uwsgi_websocket.GeventWebSocket `` and configure uWSGI to use the
43
- gevent loop engine:
46
+ gevent loop engine::
44
47
45
- $ uwsgi --master --http :8080 --http-websockets --gevent 100 --wsgi-file app.py
48
+ $ uwsgi --master --http :8080 --http-websockets --gevent 100 --wsgi echo: app
46
49
47
50
...or::
48
51
@@ -66,8 +69,8 @@ werkzeug's ``DebuggedApplication`` middleware::
66
69
67
70
$ uwsgi --master --http :8080 --http-websockets --wsgi-file --workers 1 --threads 8 app.py
68
71
69
- If you use ``app.run(debug=True) ``, Flask-uWSGI-Websocket will do this
70
- automatically for you.
72
+ If you use ``app.run(debug=True) `` or export `` FLASK_UWSGI_DEBUG ``,
73
+ Flask-uWSGI-Websocket will do this automatically for you.
71
74
72
75
73
76
API
0 commit comments