Client#
- class gordo_client.client.Client(project: str, host: str = 'localhost', port: int = 443, scheme: str = 'https', metadata: dict | None = None, data_provider: GordoBaseDataProvider | None = None, prediction_forwarder: Callable[[DataFrame, Machine, dict, DataFrame], None] | None = None, batch_size: int = 100000, parallelism: int = 10, forward_resampled_sensors: bool = False, n_retries: int = 5, use_parquet: bool = False, session: Session | None = None, all_columns: bool = False)#
Bases:
object
Basic client shipped with Gordo
Enables some basic communication with a deployed Gordo project
- Parameters:
project – Name of the project.
host – Host of where to find controller and other services.
port – Port to communicate on.
scheme – The request scheme to use, ie ‘https’.
metadata – Arbitrary mapping of key-value pairs to save to influx with prediction runs in ‘tags’ property
data_provider – The data provider to use for the dataset. If not set, the client will fall back to using the
GET /prediction
machineprediction_forwarder – callable which will take a dataframe of predictions,
Machine
, the metadata, and the dataframe of resampled sensor values and forward them somewhere.batch_size – How many samples to send to the server, only applicable when data provider is supplied.
parallelism – The maximum number of tasks to run at a given time when running predictions
forward_resampled_sensors – If true then forward resampled sensor values to the prediction_forwarder
n_retries – Number of times the client should attempt to retry a failed prediction request. Each time the client retires the time it sleeps before retrying is exponentially calculated.
use_parquet – Pass the data to the server using the parquet protocol. Default is True and recommended as it’s more efficient for larger batch sizes. If False JSON is used for sending the data back and forth.
session – The http session object to use for making requests.
all_columns – Return all columns for prediction. Including smooth-.. columns
- static dataframe_from_response(response: dict | bytes) DataFrame #
Convert response from server into dataframe.
The response from the server, parsed as either JSON / dict or raw bytes, of which would be expected to be loadable from
gordo.server.utils.dataframe_from_parquet_bytes
- Parameters:
response – The parsed response from the ML server.
- Return type:
- download_model(revision=None, targets: List[str] | None = None) Dict[str, BaseEstimator] #
Download the actual model(s) from the ML server
/download-model
.- Return type:
Mapping of target name to the model
- get_available_machines(revision: str | None = None)#
Returns a dict representing the
/models
endpoint of the project for the given revision.Contains at least a key
models
which contains the name of the models the server can serve for that revision, and a keyrevision
containing the revision.
- get_machine_names(revision: str | None = None)#
Returns the list of machine names served by a given revision, or latest revision if no revision is passed
- get_metadata(revision: str | None = None, targets: List[str] | None = None) Dict[str, Metadata] #
Get the machine metadata for provided machines, or all if no machine names are provided.
- Parameters:
revision – Revision to fetch machines for. If None then the latest revision is fetched from the server.
targets – List of names of machines to fetch metadata for. If None then all machines for the given revision is fetched.
- Return type:
Mapping of target names to their metadata
- get_revisions()#
Gets the available revisions served by the server.
- Returns:
Dictionary with two keys,
available-revisions
andlatest
. The first isa list of all available revisions, and
latest
is the latest and defaultrevision.
- predict(start: datetime, end: datetime, targets: List[str] | None = None, revision: str | None = None) Iterable[Tuple[str, DataFrame, List[str]]] #
Start the prediction process.
- Parameters:
start –
end –
targets – Optionally only target certain machines, referring to them by name.
revision – Revision of the model to run predictions again, defaulting to latest.
- Raises:
ResourceGone – If the sever returns a 410, most likely because the revision is too old
- Returns:
0th element is the target name
1st element is the dataframe of the predictions; complete with a DateTime index.
2nd element is a list of error messages (if any) for running the predictions
- predict_single_machine(machine: Machine, start: datetime, end: datetime, revision: str) PredictionResult #
Get predictions based on the
/prediction
POST machine of Gordo ML Servers.- Parameters:
machine – Named tuple which has ‘machine’ specifying the full url to the base ml server
start –
end –
revision – Revision of the model to use
- Return type:
Prediction response from
/prediction
GET
- gordo_client.client.make_date_ranges(start: datetime, end: datetime, max_interval_days: int, freq: str = 'H')#
Split start and end datetimes into a list of datetime intervals.
If the interval between start and end is less than
max_interval_days
then the resulting list will contain the original start & end. ie. [(start, end)]Otherwise it will split the intervals by
freq
, parse-able by pandas.- Parameters:
start –
end –
max_interval_days – Maximum days between start and end before splitting into intervals
freq – String frequency parse-able by Pandas