StationControlClient#
Module: iqm.station_control.client.station_control_client
- class StationControlClient(station_control_url, *, token=None, tokens_file=None, get_token_callback=None, client_signature=None)#
Bases:
SerializableClient implementation for station control service REST API.
Requests are sent through one shared
requests.Session, which is not thread-safe: do not use the same client instance from multiple threads concurrently.- Parameters:
station_control_url (str) – Remote station control service URL.
token (str | None) – Long-lived authentication token in plain text format. If
tokenis given no other user authentication parameters should be given.tokens_file (str | None) – Path to a tokens file used for authentication. If
tokens_fileis given no other user authentication parameters should be given.get_token_callback (Callable[[], str] | None) – Callback function that returns an Authorization header containing a bearer token. If
get_token_callbackis given no other user authentication parameters should be given.client_signature (str | None) – String that is added to the User-Agent header of requests sent to the server.
Attributes
Version of the Station Control API this client is using.
Methods
Close the HTTP session and release its pooled connections.
Reconstruct an instance from a dictionary payload.
deserialize_responseget_aboutSend an HTTP request.
Serialize the object instance into a dictionary payload.
Serialize a Pydantic model into a JSON string.
Serialize query parameters, skipping None values and empty dictionaries.
- classmethod deserialize(data)#
Reconstruct an instance from a dictionary payload.
- Parameters:
- Return type:
- close()#
Close the HTTP session and release its pooled connections.
The client must not be used for requests after this call.
- Return type:
None
- serialize_query_params(params)#
Serialize query parameters, skipping None values and empty dictionaries.
- send_request(http_method, url_path, *, headers=None, params=None, json_data=None, octets=None, timeout=600)#
Send an HTTP request.
Parameters
json_dataandoctetsare mutually exclusive. The first non-None argument (in this order) will be used to construct the body of the request.- Parameters:
http_method (Callable[[...], Response]) – HTTP method to use for the request, any of requests.[post|get|put|head|delete|patch|options]. Only its name is used, the request is sent through the client’s shared session.
url_path (str) – URL for the request.
headers (dict[str, str] | None) – Additional HTTP headers for the request. Some may be overridden.
params (dict[str, Any] | None) – HTTP query parameters to store in the query string of the request URL.
json_data (str | None) – JSON string to store in the body, may contain arbitrary Unicode characters.
octets (bytes | None) – Pre-serialized binary data to store in the body.
timeout (int) – Timeout for the request in seconds.
- Returns:
Response to the request.
- Raises:
IQMError – Request was not successful.
- Return type:
Response
- static serialize_model(model)#
Serialize a Pydantic model into a JSON string.
All Pydantic models should be serialized using this method, to keep the client behavior uniform.
- Parameters:
model (BaseModel) – Pydantic model to JSON-serialize.
- Returns:
Corresponding JSON string, may contain arbitrary Unicode characters.
- Return type:
Inheritance
