Skip to content

WebsocketSession class

Class to handle websocket connections.

Supports 3 data modes: JSON, TEXT, and BYTES.

To know more about WebSockets, read the FastAPI documentation.

connect async

connect(websocket, mode=DataMode.JSON)

Connect to a websocket and yield data from it.

Parameters:

Name Type Description Default
websocket WebSocket

The websocket to connect to.

required
mode DataMode

The data mode to use. Defaults to DataMode.JSON.

JSON

Yields:

Name Type Description
Any Generator

data from client side.