mindspore_serving.client
MindSpore Serving Client API, which can be used to access the Serving Server through gRPC
- class mindspore_serving.client.Client(address, servable_name, method_name, version_number=0, ssl_config=None)[source]
The Client encapsulates the serving gRPC API, which can be used to create requests, access serving, and parse results.
Note
The maximum amount of data that the client can send in one request is 512MB, and the maximum amount of data that the server can accept can be configured as 1~512MB, 100MB by default.
- Parameters
address (str) – Serving address.
servable_name (str) – The name of servable supplied by Serving.
method_name (str) – The name of method supplied by servable.
version_number (int, optional) – The version number of servable, 0 means the maximum version number in all running versions. Default: 0.
ssl_config (mindspore_serving.client.SSLConfig, optional) – The server’s ssl_config, if None, disabled ssl. Default: None.
- Raises
RuntimeError – The type or value of the parameters are invalid, or other errors happened.
Examples
>>> from mindspore_serving.client import Client >>> import numpy as np >>> client = Client("localhost:5500", "add", "add_cast") >>> instances = [] >>> x1 = np.ones((2, 2), np.int32) >>> x2 = np.ones((2, 2), np.int32) >>> instances.append({"x1": x1, "x2": x2}) >>> result = client.infer(instances) >>> print(result)
- infer(instances)[source]
Used to create requests, access serving service, and parse and return results.
- Parameters
instances (map, tuple of map) – Instance or tuple of instances, every instance item is the inputs map. The map key is the input name, and the value is the input value, the type of value can be python int, float, bool, str, bytes, numpy number, or numpy array object.
- Raises
RuntimeError – The type or value of the parameters is invalid, or other errors happened.
Examples
>>> from mindspore_serving.client import Client >>> import numpy as np >>> client = Client("localhost:5500", "add", "add_cast") >>> instances = [] >>> x1 = np.ones((2, 2), np.int32) >>> x2 = np.ones((2, 2), np.int32) >>> instances.append({"x1": x1, "x2": x2}) >>> result = client.infer(instances) >>> print(result)
- infer_async(instances)[source]
Used to create requests, async access serving.
- Parameters
instances (map, tuple of map) – Instance or tuple of instances, every instance item is the inputs map. The map key is the input name, and the value is the input value, the type of value can be python int, float, bool, str, bytes, numpy number, or numpy array object.
- Raises
RuntimeError – The type or value of the parameters is invalid, or other errors happened.
Examples
>>> from mindspore_serving.client import Client >>> import numpy as np >>> client = Client("localhost:5500", "add", "add_cast") >>> instances = [] >>> x1 = np.ones((2, 2), np.int32) >>> x2 = np.ones((2, 2), np.int32) >>> instances.append({"x1": x1, "x2": x2}) >>> result_future = client.infer_async(instances) >>> result = result_future.result() >>> print(result)
- class mindspore_serving.client.SSLConfig(certificate=None, private_key=None, custom_ca=None)[source]
The client’s ssl_config encapsulates grpc’s ssl channel credentials for SSL-enabled connections.
- Parameters
certificate (str, optional) – File holding the PEM-encoded certificate chain as a byte string to use or None if no certificate chain should be used. Default: None.
private_key (str, optional) – File holding the PEM-encoded private key as a byte string, or None if no private key should be used. Default: None.
custom_ca (str, optional) – File holding the PEM-encoded root certificates as a byte string, or None to retrieve them from a default location chosen by gRPC runtime. Default: None.
- Raises
RuntimeError – The type or value of the parameters is invalid.