SHC Client Interface

class shc.interfaces.shc_client.SHCWebClient(server: str, auto_reconnect: bool = True, failsafe_start: bool = False, client_online_object: Optional[str] = None)

Client for connecting to remote SHC instances via the websocket API, provided by shc.web.WebServer

For each API object (shc.web.WebApiObject) on the remote server, a local “proxy” object can be created by calling object() with the server object’s name and correct type. This object (WebApiClientObject) forwards local read and write calls to the server and remote writes from the server to locally subscribed objects.

Parameters:
  • server – Base URL of the remote SHC webserver instance without trailing slash, e.g. ‘https://example.com/shc’. The path of the API websocket (‘/api/v1/ws’) is appended internally.

  • auto_reconnect – If True (default), the API client tries to reconnect automatically on connection errors with exponential backoff (1 * 1.25^n seconds sleep). Otherwise, the complete SHC system is shut down, when a connection error occurs.

  • failsafe_start – If True and auto_reconnect is True, the API client allows SHC to start up, even if the API connection can not be established in the first try. The connection is retried in background with exponential backoff (see auto_reconnect option). Otherwise (default), the first connection attempt on startup is not retried and will shutdown the SHC application on failure, even if auto_reconnect is True.

  • client_online_object – The (optional) name of an API object of the SHC API server to be used as a server-side online indicator for this client. The object must be of bool type. The client will automatically send a True value to this object when (re)connecting and use the server’s ‘last will’ feature to let a False value be published when the websocket connection is lost.

object(type_: Type, name: str) WebApiClientObject

Create a Connectable object for communicating with an API object on the remote SHC server.

The returned object is Subscribable, Readable and Writable. Read and write calls are basically forwarded to the corresponding WebApiObject of the server; new values, pushed from the server, are published to the object’s subscribers.

Parameters:
  • type – The data type of the server’s API object. This is also the type of the returned Connectable object.

  • name – The name of the server’s API object