websocket package

Submodules

websocket.client module

class websocket.client.WebsocketClient(server: str, log=<module 'logging' from '/usr/lib/python3.8/logging/__init__.py'>)[source]

Bases: object

A client for connecting to a WebSocket server and sending/receiving messages.

_parse_server(server)[source]

Parses the server address to extract the server name.

Parameters:

server – The server address.

Returns:

The parsed server name.

send(channel: str, message, headers=None)[source]

Sends a message to a specified channel on the WebSocket server.

Parameters:
  • channel – The channel to send the message to.

  • message – The message to be sent.

  • headers – Optional headers to include in the WebSocket connection.

wait_message(channel, timeout=30, headers=None)[source]

Waits for a message from a specified channel on the WebSocket server.

Parameters:
  • channel – The channel to listen for messages.

  • timeout – The time in seconds to wait for a message before timing out.

  • headers – Optional headers to include in the WebSocket connection.

Returns:

The received message, or None if an error occurs or timeout is reached.

Module contents