~.websocket
Websocket
WebsocketPacket
Base websocket packet implementation.
WebsocketPacketBytes
dataclass
WebsocketPacketBytes(payload: bytes)
WebsocketPacketJSON
dataclass
Bases: WebsocketPacket
JSON-structured websocket packet.
WebsocketState
Bases: IntEnum
Websocket connection state.
CONNECTED
class-attribute
instance-attribute
CONNECTED = 0
Websocket is currently connected.
CONNECTING
class-attribute
instance-attribute
CONNECTING = 1
Websocket is currently connecting.
DISCONNECTED
class-attribute
instance-attribute
DISCONNECTED = 2
Websocket is currently disconnected.
DISCONNECTING
class-attribute
instance-attribute
DISCONNECTING = 3
Websocket is currently disconnecting.
Websocket
Websocket()
Custom websocket manager.
Create a new websocket.
connect
async
connect(url: str) -> None
Connect to a websocket endpoint.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
The URL/URI to connect to.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ReconnectSignal
|
Error occurred and further attempts should be made to connect. |
disconnect
async
disconnect() -> None
Disconnect the websocket.
receive
async
receive() -> WebsocketPacket
Block until a payload is received.
| RETURNS | DESCRIPTION |
|---|---|
WebsocketPacket
|
The received payload, either |
| RAISES | DESCRIPTION |
|---|---|
DisconnectSignal
|
Error occurred and no further attempts should be made to connect. |
ReconnectSignal
|
Error occurred and further attempts should be made to connect. |
RuntimeError
|
An unexpected payload type was received. |
ResumeSignal
|
Error occurred and an attempt to resume the session should be made. |
send_bytes
async
send_bytes(data: bytes) -> None
Send a bytes payload through the websocket.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
DisconnectSignal
|
Error occurred and no further attempts should be made to connect. |
ReconnectSignal
|
Error occurred and further attempts should be made to connect. |
ResumeSignal
|
Error occurred and an attempt to resume the session should be made. |
send_json
async
Send a JSON payload through the websocket.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The JSON payload to send. |
| RAISES | DESCRIPTION |
|---|---|
DisconnectSignal
|
Error occurred and no further attempts should be made to connect. |
ReconnectSignal
|
Error occurred and further attempts should be made to connect. |
ResumeSignal
|
Error occurred and an attempt to resume the session should be made. |