Models

Warning

The Models client is in an Alpha release. Descartes Labs reserves the right to modify this API without any guarantees about backwards compatibility.


Models Models is a client for interacting with registered models and tracking the status of jobs.

class Models(host=None, port=None, auth=None, certificate=None, default_retry=None, default_metadata=None, use_insecure_channel=False)[source]

Models is a client for interacting with registered models and tracking the status of jobs.

Parameters:
  • host (str, optional) – The backend host to connect to. Defaults to the correct value. Only override when debugging.
  • port (int, optional) – The backend port to connect to. Defaults to the correct value. Only override when debugging.
  • auth (Auth, optional) – The authentication instance to use. Defaults to Auth.get_default_client().
  • certificate (bytes, optional) – The certificate to use when connecting to the backend service.
  • default_retry (Retry, int, optional) – The retry instance or number of times to retry a connection before giving up. Default is to retry 5 times for retryable status codes.
  • default_metadata (tuple, optional) – Metadata (headers) to send to every RPC when called. The default is empty.
  • use_insecure_channel (bool, optional) – If set, an insecure channel will be used. Default is secure; only use insecure when debugging.

Attributes:

DEFAULT_TIMEOUT
STREAM_TIMEOUT
api The available Client operations, as a dict.
certificate The Client SSL certificate.
channel The GRPC channel of the Client.
token The Client token.

Methods:

INSECURE_CHANNEL_FACTORY(target[, options, …]) Creates an insecure Channel to a server.
SECURE_CHANNEL_FACTORY(target, credentials) Creates a secure Channel to a server.
close() Close the GRPC channel associated with the Client.
get_default_client() Retrieve the default client.
get_model(model_name) Gets ModelSpec from model name.
get_status(work_id) Gets the status of a job
health([timeout]) Check the health of the GRPC server (SERVING, NOT_SERVING, UNKNOWN).
invoke(model_name, parameters) Invokes a model model_name with specified tuning parameters.
set_default_client(client) Change the default client to the given client.
static INSECURE_CHANNEL_FACTORY(target, options=None, compression=None)

Creates an insecure Channel to a server.

The returned Channel is thread-safe.

Parameters:
  • target – The server address
  • options – An optional list of key-value pairs (channel_arguments in gRPC Core runtime) to configure the channel.
  • compression – An optional value indicating the compression method to be used over the lifetime of the channel. This is an EXPERIMENTAL option.
Returns:

A Channel.

static SECURE_CHANNEL_FACTORY(target, credentials, options=None, compression=None)

Creates a secure Channel to a server.

The returned Channel is thread-safe.

Parameters:
  • target – The server address.
  • credentials – A ChannelCredentials instance.
  • options – An optional list of key-value pairs (channel_arguments in gRPC Core runtime) to configure the channel.
  • compression – An optional value indicating the compression method to be used over the lifetime of the channel. This is an EXPERIMENTAL option.
Returns:

A Channel.

close()

Close the GRPC channel associated with the Client.

classmethod get_default_client()

Retrieve the default client.

This client is used whenever you don’t explicitly set the client.

get_model(model_name: str) → descarteslabs.common.services.currier.spec.internal.ModelSpec[source]

Gets ModelSpec from model name.

Parameters:model_name (str) – Name of model to fetch.
Returns:model_spec – Deserialized ModelSpec object.
Return type:ModelSpec
get_status(work_id: str) → Dict[str, float][source]

Gets the status of a job

Parameters:work_id (str) – Work ID of the job to check the status on.
Returns:status – Percentages for work pending, running, cancelled, successful and failed.
Return type:Dict[str, float]
health(timeout=None)

Check the health of the GRPC server (SERVING, NOT_SERVING, UNKNOWN).

Example

>>> from descarteslabs.client.grpc import GrpcClient
>>> GrpcClient().health() 
SERVING
invoke(model_name: str, parameters: Dict[str, Any]) → str[source]

Invokes a model model_name with specified tuning parameters.

Parameters:
  • model_name (str) – Name of model to invoke.
  • parameters (Dict[str, Any]) – Input parameters for the model.
Returns:

work_id – Work ID of the invoked job. This can be used for checking the status of the work with get_status.

Return type:

str

classmethod set_default_client(client)

Change the default client to the given client.

This is the client that will be used whenever you don’t explicitly set the client

DEFAULT_TIMEOUT = 5
STREAM_TIMEOUT = 86400
property api

The available Client operations, as a dict.

property certificate

The Client SSL certificate.

property channel

The GRPC channel of the Client.

property token

The Client token.