Introduction¶
Installation¶
You can install this package in the usual way usingpip
:
pipinstallflask-socketio
Requirements¶
Flask-SocketIO is compatible with Python 3.6+. The asynchronous services thatthis package relies on can be selected among three choices:
eventlet is the best performant option, withsupport for long-polling and WebSocket transports.
gevent is supported in a number of differentconfigurations. The long-polling transport is fully supported with thegevent package, but unlike eventlet, gevent does not have native WebSocketsupport. To add support for WebSocket there are currently two options.Installing thegevent-websocketpackage adds WebSocket support to gevent or one can use theuWSGI web server, whichcomes with WebSocket functionality. The use of gevent is also a performantoption, but slightly lower than eventlet.
The Flask development server based on Werkzeug can be used as well, with thecaveat that this web server is intended only for development use, so itshould only be used to simplify the development workflow and not forproduction.
The extension automatically detects which asynchronous framework to use basedon what is installed. Preference is given to eventlet, followed by gevent.For WebSocket support in gevent, uWSGI is preferred, followed bygevent-websocket. If neither eventlet nor gevent are installed, then the Flaskdevelopment server is used.
If using multiple processes, a message queue service must be configured toallow the servers to coordinate operations such as broadcasting. The supportedqueues areRedis,RabbitMQ,Kafka, and any other message queues supported bytheKombu package.
On the client-side, the official Socket.IO Javascript client library can beused to establish a connection to the server. There are also official clientswritten in Swift, Java and C++. Unofficial clients may also work, as long asthey implement theSocket.IO protocol.Thepython-socketiopackage (which provides the Socket.IO server implementation used byFlask-SocketIO) includes a Python client.
Version compatibility¶
The Socket.IO protocol has been through a number of revisions, and some of theseintroduced backward incompatible changes, which means that the client and theserver must use compatible versions for everything to work.
The version compatibility chart below maps versions of this package to versionsof the JavaScript reference implementation and the versions of the Socket.IO andEngine.IO protocols.
JavaScript Socket.IO version | Socket.IO protocol revision | Engine.IO protocol revision | Flask-SocketIO version | python-socketio version | python-engineio version |
---|---|---|---|---|---|
0.9.x | 1, 2 | 1, 2 | Not supported | Not supported | Not supported |
1.x and 2.x | 3, 4 | 3 | 4.x | 4.x | 3.x |
3.x and 4.x | 5 | 4 | 5.x | 5.x | 4.x |