Client#
- class sayd.SaydClient(host: str = 'localhost', port: int = 7050, local_host: Optional[str] = None, local_port: Optional[Union[int, str]] = None, buffer: int = 128, timeout: int = 3, ping: int = 1, reconnect: bool = True, reconnect_timeout: int = 5, logger: Optional[Logger] = None, cert: Optional[str] = None)#
Client class.
- Parameters
host (str) – Server hostname, defaults to localhost.
port (int) – Server port, defaults to 7050.
local_host (str) – Local address to bind the client, defaults to None.
local_port (Optional[Union[int, str]]) – Local port to bind the client, defaults to None.
buffer (int) – Buffer size limit in KiB, defaults to 128.
timeout (int) – Time in seconds to disconnect from the server if is not responding, defaults to 3.
ping (int) – Frequency in seconds to ping the server, defaults to 1.
reconnect (bool) – If disconnected from the server try to reconnect, defaults to True.
reconnect_timeout (int) – Frequency in seconds to try to reconnect if disconnected, defaults to 5.
logger (Optional[Logger]) – Logger to use, defaults to None.
cert (Optional[str]) – Path to the TLS certificate, defaults to None.
- add_callback(name: str, function: Callable) None#
Method to bind functions to be called when a request is received.
- Parameters
name (str) – Name to bind the function.
function (Callable) – Function to bind.
- async call(name: str, data: Optional[dict] = None, instance: Optional[str] = None, wait: bool = True, wait_timeout: int = 3, _call_id: Optional[str] = None) Optional[Union[dict, bool, Exception]]#
Calls a function in the server.
- Parameters
name (str) – Name of the function.
data (dict) – Data to send, defaults to None.
instance (Optional[str]) – Instance to pass to the remote function, defaults to None.
wait (bool) – True to wait for a answer, defaults to True.
wait_timeout (int) – Time limit in seconds to wait for a answer, defaults to 3.
- Returns
The call result.
- Return type
Union[dict, bool, Exception, None]
- callback(name: str) Callable#
Decorator to bind functions to be called when a request is received.
- Parameters
name (str) – Name to bind the function.
- property connected: bool#
Returns the connection status.
- Returns
True if connected, else False.
- Return type
bool
- async start() None#
Starts the client.
- async stop() None#
Stops the client.