Python client configuration

The Client class allows a client to obtain outputs from a Konduit Serving instance given a named set of inputs via the predict() method.

from konduit.client import Client 

Client(
    timeout=60,
    input_data_format='NUMPY',
    output_data_format='NUMPY',
    input_names=['default'],
    output_names=['default'],
    host='http://localhost',
    port=None, 
    prediction_type=None
)

Data formats

Data formats define how data is transported between the Client and the Konduit Serving instance. In addition to JSON, Konduit Serving also supports NUMPY, ARROW, RAW and IMAGEdata formats. Specify data formats as strings.

  • input_data_format defines the data format of inputs sent to the server via the predict() method.

  • output_data_formatdefines the data format returned by the API endpoint.

If you want to convert the result of your endpoint to another data format on return, change the convert_to_format attribute of the Client object:

client = Client(port=3226)
client.convert_to_format = "ARROW"

Input and output names

Both the input_names and output_names arguments accept a list of strings. Input and output names are defined by the inputs and outputs to the first and last pipeline steps in the Konduit Serving pipeline configuration respectively.

For ModelStep, input and output names should be configured when defining the model for training, or may need to be obtained by inspecting the model file. See the examples for details.

For PythonStep, input names are defined in the step() method of a PythonStep object.

Other arguments

  • timeout: Integer. Defaults to 60 (seconds).

  • host: String. If the model is hosted locally, the host should be specified as http://localhost (the default argument)

  • port: Integer.

The arguments output_data_format, input_data_format and prediction_type are obtained from the server when the Client object is initialized. Refer to the Server documentation for details.

.predict()method

The .predict()method takes a dictionary withinput_names as keys and the data inputs as values.

Example

Assume a Server object has been fully configured as server. Start the server:

server.start()

Define a Client:

client = Client(
    input_data_format='NUMPY',
    output_data_format="NUMPY",
    return_data_output_format='NUMPY',
    input_names=["input1"],
    host='http://localhost', 
    port=port
)

Request for a prediction:

client.predict({"input1": np.ones(5)})
server.stop()

YAML configuration

Refer to the YAML configuration page.

Last updated