labthings_fastapi.client
Code to access Thing features over HTTP.
This module defines a base class for controlling LabThings-FastAPI over HTTP.
It is based on httpx, and attempts to create a simple wrapper such that
each Action becomes a method and each Property becomes an attribute.
Functions
|
Poll a invocation until it finishes, and return the output. |
Package Contents
- labthings_fastapi.client.poll_invocation(client: httpx.Client, invocation: dict, interval: float = 0.5, first_interval: float = 0.05) dict
Poll a invocation until it finishes, and return the output.
When actions are invoked in a LabThings-FastAPI server, the initial POST request returns immediately. The returned invocation includes a link that may be polled to find out when the action has completed, whether it was successful, and retrieve its output.
- Parameters:
client – the
httpx.Clientto use for HTTP requests.invocation – the dictionary returned from the initial POST request.
interval – sets how frequently we poll, in seconds.
first_interval – sets how long we wait before the first polling request. Often, it makes sense for this to be a short interval, in case the action fails (or returns) immediately.
- Returns:
the completed invocation as a dictionary.