API Reference

class flask_sock.Sock(app=None)

Instantiate the Flask-Sock extension.


app – The Flask application instance. If not provided, it must be initialized later by calling the Sock.init_app() method.


Initialize the Flask-Socket extension.


app – The Flask application instance. This method only needs to be called if the application instance was not passed as an argument to the constructor.

route(path, **kwargs)

Decorator to create a WebSocket route.

The decorated function will be invoked when a WebSocket client establishes a connection, with a WebSocket connection object passed as an argument. Example:

def websocket_route(ws):
    # The ws object has the following methods:
    # - ws.send(data)
    # - ws.receive(timeout=None)
    # - ws.close(reason=None, message=None)

If the route has variable components, the ws argument needs to be included before them.

  • path – the URL associated with the route.

  • kwargs – additional route options. See the Flask documentation for the app.route decorator for details.