seldon_core package¶
Subpackages¶
Submodules¶
seldon_core.api_tester module¶
-
seldon_core.api_tester.
get_seldon_client
(args)[source]¶ Get the appropriate Seldon Client based on args
- Parameters
args – Command line args
- Return type
- Returns
A Seldon Client
seldon_core.batch_processor module¶
-
seldon_core.batch_processor.
start_multithreaded_batch_worker
(deployment_name, gateway_type, namespace, host, transport, data_type, payload_type, workers, retries, batch_size, input_data_path, output_data_path, method, log_level, benchmark, batch_id, batch_interval, call_credentials_token, use_ssl, ssl_verify)[source]¶ Starts the multithreaded batch worker which consists of three worker types and two queues; the input_file_worker which reads a file and puts all lines in an input queue, which are then read by the multiple request_processor_workers (the number of parallel workers is specified by the workers param), which puts the output in the output queue and then the output_file_worker which puts all the outputs in the output file in a thread-safe approach.
All parameters are defined and explained in detail in the run_cli function.
- Return type
seldon_core.env_utils module¶
Utilities to deal with Environment variables
-
seldon_core.env_utils.
get_deployment_name
(default_val='NOT_IMPLEMENTED')[source]¶ Get deployment name from ENV_SELDON_DEPLOYMENT_NAME environment variable. If not set return default_val
-
seldon_core.env_utils.
get_image_name
(default_val='NOT_IMPLEMENTED:NOT_IMPLEMENTED')[source]¶ Get model image name from ENV_MODEL_IMAGE environment variable. If not set return default_val
-
seldon_core.env_utils.
get_model_name
(default_val='NOT_IMPLEMENTED')[source]¶ Get model name from ENV_MODEL_NAME environment variable. If not set return default_val
-
seldon_core.env_utils.
get_predictor_name
(default_val='NOT_IMPLEMENTED')[source]¶ Get predictor name from ENV_PREDICTOR_NAME environment variable. If not set return default_val
seldon_core.flask_utils module¶
-
exception
seldon_core.flask_utils.
SeldonMicroserviceException
(message, status_code=None, payload=None, reason='MICROSERVICE_BAD_DATA')[source]¶ Bases:
Exception
-
status_code
= 400¶
-
-
seldon_core.flask_utils.
get_multi_form_data_request
()[source]¶ Parses a request submitted with Content-type:multipart/form-data all the keys under SeldonMessage are accepted as form input binData can only be passed as file input strData can be passed as file or text input the file input is base64 encoded
- Return type
- Returns
JSON Dict
seldon_core.gunicorn_utils module¶
-
class
seldon_core.gunicorn_utils.
StandaloneApplication
(app, options=None)[source]¶ Bases:
gunicorn.app.base.BaseApplication
Standalone Application to run a Flask app in Gunicorn.
-
class
seldon_core.gunicorn_utils.
UserModelApplication
(app, user_object, tracing, jaeger_extra_tags, interface_name, options=None)[source]¶ Bases:
seldon_core.gunicorn_utils.StandaloneApplication
Gunicorn application to run a Flask app in Gunicorn loading first the user’s model.
-
seldon_core.gunicorn_utils.
accesslog
(flag)[source]¶ Enable / disable access log in Gunicorn depending on the flag.
seldon_core.imports_helper module¶
seldon_core.metadata module¶
-
seldon_core.metadata.
validate_model_metadata
(data)[source]¶ Validate metadata.
- Parameters
data (
Dict
) – User defined model metadata (json)- Return type
- Returns
Validated model metadata (json)
- Raises
SeldonInvalidMetadataError – if data cannot be properly validated:
Notes
Read data from json and validate against v1 or v2 metadata schema. SeldonInvalidMetadataError exception will be raised if validation fails.
seldon_core.metrics module¶
-
class
seldon_core.metrics.
SeldonMetrics
(worker_id_func=<built-in function getpid>, extra_default_labels={})[source]¶ Bases:
object
Class to manage custom metrics stored in shared memory.
-
seldon_core.metrics.
create_counter
(key, value)[source]¶ Utility method to create a counter metric :type key:
str
:param key: Counter name :type value:float
:param value: Counter value- Returns
Valid counter metric dict
-
seldon_core.metrics.
create_gauge
(key, value)[source]¶ Utility method to create a gauge metric :type key:
str
:param key: Gauge name :type value:float
:param value: Gauge value- Return type
- Returns
Valid Gauge metric dict
-
seldon_core.metrics.
create_timer
(key, value)[source]¶ Utility mehtod to create a timer metric :type key:
str
:param key: Name of metric :type value:float
:param value: Value for metric- Return type
- Returns
Valid timer metric dict
seldon_core.microservice module¶
-
class
seldon_core.microservice.
MetricsEndpointFilter
(name='')[source]¶ Bases:
logging.Filter
seldon_core.microservice_tester module¶
-
seldon_core.microservice_tester.
gen_categorical
(values, n)[source]¶ Generate a random categorical feature
-
seldon_core.microservice_tester.
gen_continuous
(f_range, n)[source]¶ Create a continuous feature based on given range
-
seldon_core.microservice_tester.
reconciliate_cont_type
(feature, dtype)[source]¶ Ensure numpy arrays are always of type float
- Parameters
feature (
ndarray
) – Feature valuesdtype (
str
) – The required type in the contract
- Return type
ndarray
- Returns
Numpy array
-
seldon_core.microservice_tester.
run_method
(args, method)[source]¶ Make a predict call to microservice
- Parameters
args – Command line args
seldon_core.mlmd_utils module¶
seldon_core.seldon_client module¶
-
class
seldon_core.seldon_client.
SeldonCallCredentials
(token=None)[source]¶ Bases:
object
- Credentials for each call, currently implements the ability to provide
an OAuth token which is currently made available through REST via the X-Auth-Token header, and via GRPC via the metadata call creds.
-
class
seldon_core.seldon_client.
SeldonChannelCredentials
(verify=True, root_certificates_file=None, private_key_file=None, certificate_chain_file=None)[source]¶ Bases:
object
Channel credentials.
Presently just denotes an SSL connection. For GRPC in order to be properly implemented, you need to provide either the root_certificate_files, or all the file paths. The verify attribute currently is used to avoid SSL verification in REST however for GRPC it is recommended that you provide a path at least for the root_certificates_file otherwise it may not work as expected.
-
class
seldon_core.seldon_client.
SeldonClient
(gateway='ambassador', transport='rest', namespace=None, deployment_name=None, payload_type='tensor', gateway_endpoint='localhost:8003', microservice_endpoint='localhost:5000', grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, channel_credentials=None, call_credentials=None, debug=False, client_return_type='dict', ssl=None)[source]¶ Bases:
object
A reference Seldon API Client
-
__init__
(gateway='ambassador', transport='rest', namespace=None, deployment_name=None, payload_type='tensor', gateway_endpoint='localhost:8003', microservice_endpoint='localhost:5000', grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, channel_credentials=None, call_credentials=None, debug=False, client_return_type='dict', ssl=None)[source]¶ - Parameters
gateway (
str
) – API Gateway - either ambassador, istio or seldontransport (
str
) – API transport - grpc or restnamespace (
Optional
[str
]) – k8s namespace of running deploymentpayload_type (
str
) – type of payload - tensor, ndarray or tftensorgateway_endpoint (
str
) – Gateway endpointmicroservice_endpoint (
str
) – Running microservice endpointgrpc_max_send_message_length (
int
) – Max grpc send message size in bytesgrpc_max_receive_message_length (
int
) – Max grpc receive message size in bytesclient_return_type (
str
) – the return type of all functions can be either dict or proto
-
explain
(gateway=None, transport=None, deployment_name=None, payload_type=None, gateway_endpoint=None, shape=1, 1, namespace=None, data=None, bin_data=None, str_data=None, json_data=None, names=None, gateway_prefix=None, headers=None, http_path=None, client_return_type=None, predictor=None, ssl=None)[source]¶ - Parameters
gateway (
Optional
[str
]) – API Gateway - either ambassador, istio or seldonnamespace (
Optional
[str
]) – k8s namespace of running deploymentpayload_type (
Optional
[str
]) – type of payload - tensor, ndarray or tftensormicroservice_endpoint – Running microservice endpoint
grpc_max_send_message_length – Max grpc send message size in bytes
grpc_max_receive_message_length – Max grpc receive message size in bytes
data (
Optional
[ndarray
]) – Numpy Array Payload to sendbin_data (
Union
[bytes
,bytearray
,None
]) – Binary payload to send - will override datastr_data (
Optional
[str
]) – String payload to send - will override datajson_data (
Optional
[str
]) – JSON payload to send - will override datagateway_prefix (
Optional
[str
]) – prefix path for gateway URL endpointhttp_path (
Optional
[str
]) – Custom http path for predict call to useclient_return_type (
Optional
[str
]) – the return type of all functions can be either dict or protopredictor (
Optional
[str
]) – The name of the predictor to send the explanations to
- Return type
-
feedback
(prediction_request=None, prediction_response=None, prediction_truth=None, reward=0, gateway=None, transport=None, deployment_name=None, payload_type=None, gateway_endpoint=None, microservice_endpoint=None, method=None, shape=1, 1, namespace=None, gateway_prefix=None, client_return_type=None, raw_request=None, ssl=None)[source]¶ - Parameters
prediction_request (
Optional
[SeldonMessage
]) – Previous prediction requestprediction_response (
Optional
[SeldonMessage
]) – Previous prediction responsereward (
float
) – A reward to send in feedbackgateway (
Optional
[str
]) – API Gateway - either ambassador, istio or seldonpayload_type (
Optional
[str
]) – payload - tensor, ndarray or tftensormicroservice_endpoint (
Optional
[str
]) – Running microservice endpointgrpc_max_send_message_length – Max grpc send message size in bytes
grpc_max_receive_message_length – Max grpc receive message size in bytes
shape (
Tuple
) – The shape of the data to sendnamespace (
Optional
[str
]) – k8s namespace of running deploymentclient_return_type (
Optional
[str
]) – the return type of all functions can be either dict or proto
- Return type
-
microservice
(gateway=None, transport=None, deployment_name=None, payload_type=None, gateway_endpoint=None, microservice_endpoint=None, method=None, shape=1, 1, namespace=None, data=None, datas=None, ndatas=None, bin_data=None, str_data=None, json_data=None, custom_data=None, names=None)[source]¶ - Parameters
gateway (
Optional
[str
]) – API Gateway - either ambassador, istio or seldonpayload_type (
Optional
[str
]) – payload - tensor, ndarray or tftensormicroservice_endpoint (
Optional
[str
]) – Running microservice endpointgrpc_max_send_message_length – Max grpc send message size in bytes
grpc_max_receive_message_length – Max grpc receive message size in bytes
shape (
Tuple
) – The shape of the data to sendnamespace (
Optional
[str
]) – k8s namespace of running deploymentdata (
Optional
[ndarray
]) – Numpy Array Payload to sendbin_data (
Union
[bytes
,bytearray
,None
]) – Binary payload to send - will override datastr_data (
Optional
[str
]) – String payload to send - will override datajson_data (
Union
[str
,List
,Dict
,None
]) – String payload to send - will override datacustom_data (
Optional
[Any
]) – Custom payload to send - will override datandatas (
Optional
[int
]) – Multiple numpy arrays to send for aggregationbin_data – Binary data payload
str_data – String data payload
- Return type
- Returns
A prediction result
-
microservice_feedback
(prediction_request=None, prediction_response=None, reward=0, gateway=None, transport=None, deployment_name=None, payload_type=None, gateway_endpoint=None, microservice_endpoint=None, method=None, shape=1, 1, namespace=None)[source]¶ - Parameters
prediction_request (
Optional
[SeldonMessage
]) – Previous prediction requestprediction_response (
Optional
[SeldonMessage
]) – Previous prediction responsereward (
float
) – A reward to send in feedbackgateway (
Optional
[str
]) – API Gateway - either Gateway or seldonpayload_type (
Optional
[str
]) – payload - tensor, ndarray or tftensormicroservice_endpoint (
Optional
[str
]) – Running microservice endpointgrpc_max_send_message_length – Max grpc send message size in bytes
grpc_max_receive_message_length – Max grpc receive message size in bytes
shape (
Tuple
) – The shape of the data to sendnamespace (
Optional
[str
]) – k8s namespace of running deployment
- Return type
- Returns
A client response
-
predict
(gateway=None, transport=None, deployment_name=None, payload_type=None, gateway_endpoint=None, microservice_endpoint=None, method=None, shape=1, 1, namespace=None, data=None, bin_data=None, str_data=None, json_data=None, custom_data=None, names=None, gateway_prefix=None, headers=None, http_path=None, meta=None, client_return_type=None, raw_data=None, ssl=None)[source]¶ - Parameters
gateway (
Optional
[str
]) – API Gateway - either ambassador, istio or seldonnamespace (
Optional
[str
]) – k8s namespace of running deploymentpayload_type (
Optional
[str
]) – type of payload - tensor, ndarray or tftensormicroservice_endpoint (
Optional
[str
]) – Running microservice endpointgrpc_max_send_message_length – Max grpc send message size in bytes
grpc_max_receive_message_length – Max grpc receive message size in bytes
data (
Optional
[ndarray
]) – Numpy Array Payload to sendbin_data (
Union
[bytes
,bytearray
,None
]) – Binary payload to send - will override datastr_data (
Optional
[str
]) – String payload to send - will override datajson_data (
Union
[str
,List
,Dict
,None
]) – JSON payload to send - will override datacustom_data (
Optional
[Any
]) – Custom payload to send - will override datagateway_prefix (
Optional
[str
]) – prefix path for gateway URL endpointhttp_path (
Optional
[str
]) – Custom http path for predict call to useclient_return_type (
Optional
[str
]) – the return type of all functions can be either dict or protoraw_data (
Optional
[Dict
]) – Raw payload, a dictionary representing the json request or the raw grpc proto
- Return type
-
-
class
seldon_core.seldon_client.
SeldonClientCombine
(request, response, success=True, msg='')[source]¶ Bases:
object
Data class to return from Seldon Client for aggregate calls
-
exception
seldon_core.seldon_client.
SeldonClientException
(message)[source]¶ Bases:
Exception
Seldon Client Exception
-
status_code
= 400¶
-
-
class
seldon_core.seldon_client.
SeldonClientFeedback
(request, response, success=True, msg='')[source]¶ Bases:
object
Data class to return from Seldon Client for feedback calls
-
class
seldon_core.seldon_client.
SeldonClientPrediction
(request, response, success=True, msg='')[source]¶ Bases:
object
Data class to return from Seldon Client
-
seldon_core.seldon_client.
explain_predict_gateway
(deployment_name, namespace=None, gateway_endpoint='localhost:8003', gateway=None, transport='rest', shape=1, 1, data=None, headers=None, gateway_prefix=None, payload_type='tensor', bin_data=None, str_data=None, json_data=None, names=None, call_credentials=None, channel_credentials=None, http_path=None, client_return_type='dict', predictor=None, ssl=None, **kwargs)[source]¶ REST explain request to Gateway Ingress
- Parameters
deployment_name (
str
) – The name of the Seldon Deploymentnamespace (
Optional
[str
]) – k8s namespace of running deploymentgateway_endpoint (
str
) – The host:port of gatewaygateway (
Optional
[str
]) – The type of gateway which can be seldon or ambassador/istiotransport (
str
) – The type of transport, in this case only rest is supporteddata (
Optional
[ndarray
]) – The numpy data to sendgateway_prefix (
Optional
[str
]) – The prefix path to add to the requestpayload_type (
str
) – payload - tensor, ndarray or tftensorbin_data (
Union
[bytes
,bytearray
,None
]) – Binary data to sendjson_data (
Union
[str
,List
,Dict
,None
]) – JSON data to sendcall_credentials (
Optional
[SeldonCallCredentials
]) – Call credentials - see SeldonCallCredentialschannel_credentials (
Optional
[SeldonChannelCredentials
]) – Channel credentials - see SeldonChannelCredentialsclient_return_type (
str
) – the return type of all functions can be either dict or proto
- Return type
- Returns
A JSON Dict
-
seldon_core.seldon_client.
grpc_feedback_gateway
(prediction_request=None, prediction_response=None, prediction_truth=None, reward=0, deployment_name='', namespace=None, gateway_endpoint='localhost:8003', headers=None, grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, client_return_type='proto', raw_request=None, **kwargs)[source]¶ - Parameters
prediction_request (
Optional
[SeldonMessage
]) – Previous prediction requestprediction_response (
Optional
[SeldonMessage
]) – Previous prediction responsereward (
float
) – A reward to send in feedbackdeployment_name (
str
) – The name of the running Seldon deploymentnamespace (
Optional
[str
]) – k8s namespace of running deploymentgateway_endpoint (
str
) – The gateway host:port endpointgrpc_max_send_message_length (
int
) – Max grpc send message size in bytesgrpc_max_receive_message_length (
int
) – Max grpc receive message size in bytesclient_return_type (
str
) – the return type of all functions can be either dict or protokwargs –
- Return type
-
seldon_core.seldon_client.
grpc_feedback_seldon
(prediction_request=None, prediction_response=None, prediction_truth=None, reward=0, namespace=None, gateway_endpoint='localhost:8004', grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, client_return_type='proto', raw_request=None, **kwargs)[source]¶ Send feedback to Seldon API gateway via gRPC
- Parameters
prediction_request (
Optional
[SeldonMessage
]) – Previous prediction requestprediction_response (
Optional
[SeldonMessage
]) – Previous prediction responsereward (
float
) – A reward to send in feedbacknamespace (
Optional
[str
]) – k8s namespace of running deploymentgrpc_max_send_message_length (
int
) – Max grpc send message size in bytesgrpc_max_receive_message_length (
int
) – Max grpc receive message size in bytesclient_return_type (
str
) – the return type of all functions can be either dict or protokwargs –
- Return type
-
seldon_core.seldon_client.
grpc_predict_gateway
(deployment_name, namespace=None, gateway_endpoint='localhost:8003', shape=1, 1, data=None, headers=None, payload_type='tensor', bin_data=None, str_data=None, json_data=None, custom_data=None, grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, names=None, call_credentials=None, channel_credentials=None, meta={}, client_return_type='proto', raw_data=None, ssl=None, **kwargs)[source]¶ gRPC request to Gateway Ingress
- Parameters
deployment_name (
str
) – Deployment name of Seldon Deploymentnamespace (
Optional
[str
]) – The namespace the Seldon Deployment is running ingateway_endpoint (
str
) – The endpoint for gatewaydata (
Optional
[ndarray
]) – The numpy array data to sendheaders (
Optional
[Dict
]) – A Dict of key value pairs to add to gRPC HTTP Headerspayload_type (
str
) – payload - tensor, ndarray or tftensorbin_data (
Union
[bytes
,bytearray
,None
]) – Binary data to sendjson_data (
Union
[str
,List
,Dict
,None
]) – JSON data to sendcustom_data (
Optional
[Any
]) – Custom data to sendgrpc_max_send_message_length (
int
) – Max grpc send message size in bytesgrpc_max_receive_message_length (
int
) – Max grpc receive message size in bytescall_credentials (
Optional
[SeldonCallCredentials
]) – Call credentials - see SeldonCallCredentialschannel_credentials (
Optional
[SeldonChannelCredentials
]) – Channel credentials - see SeldonChannelCredentialsmeta (
Dict
) – Custom meta data map, supplied as tagsclient_return_type (
str
) – the return type of all functions can be either dict or protoraw_data (
Optional
[Dict
]) – Raw payload (dictionary or proto) given by the user
- Return type
- Returns
A SeldonMessage proto response
-
seldon_core.seldon_client.
grpc_predict_seldon
(namespace=None, gateway_endpoint='localhost:8004', shape=1, 1, data=None, payload_type='tensor', bin_data=None, str_data=None, json_data=None, custom_data=None, grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, names=None, client_return_type='proto', raw_data=None, **kwargs)[source]¶ Call Seldon gRPC API Gateway endpoint
- Parameters
namespace (
Optional
[str
]) – k8s namespace of running deploymentdata (
Optional
[ndarray
]) – Data to sendpayload_type (
str
) – payload - tensor, ndarray or tftensorbin_data (
Union
[bytes
,bytearray
,None
]) – Binary data to sendjson_data (
Union
[str
,List
,Dict
,None
]) – JSON data to sendcustom_data (
Optional
[Any
]) – Custom data to sendgrpc_max_send_message_length (
int
) – Max grpc send message size in bytesgrpc_max_receive_message_length (
int
) – Max grpc receive message size in bytesclient_return_type (
str
) – the return type of all functions can be either dict or protoraw_data (
Optional
[Dict
]) – Raw payload (dictionary or proto) given by the userkwargs –
- Return type
- Returns
A SeldonMessage proto
-
seldon_core.seldon_client.
microservice_api_grpc_aggregate
(microservice_endpoint='localhost:5000', shape=1, 1, datas=None, ndatas=None, payload_type='tensor', grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, names=None, **kwargs)[source]¶ Call Seldon microservice gRPC API aggregate
- Parameters
microservice_endpoint (
str
) – Microservice API endpointshape (
Tuple
) – Shape of the data to senddatas (
Optional
[List
[ndarray
]]) – List of Numpy array data to sendndatas (
Optional
[int
]) – Multiple numpy arrays to send for aggregationpayload_type (
str
) – payload - tensor, ndarray or tftensorgrpc_max_send_message_length (
int
) – Max grpc send message size in bytesgrpc_max_receive_message_length (
int
) – Max grpc receive message size in byteskwargs –
- Return type
- Returns
SeldonClientCombine
-
seldon_core.seldon_client.
microservice_api_grpc_feedback
(prediction_request=None, prediction_response=None, reward=0, microservice_endpoint=None, grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, **kwargs)[source]¶ Call Seldon gRPC
- Parameters
- Return type
-
seldon_core.seldon_client.
microservice_api_grpc_seldon_message
(method='predict', microservice_endpoint='localhost:5000', shape=1, 1, data=None, payload_type='tensor', bin_data=None, str_data=None, json_data=None, custom_data=None, grpc_max_send_message_length=4194304, grpc_max_receive_message_length=4194304, names=None, **kwargs)[source]¶ Call Seldon microservice gRPC API
- Parameters
method (
str
) – Method to callmicroservice_endpoint (
str
) – Running microservice endpointshape (
Tuple
) – The shape of the data to sendpayload_type (
str
) – payload - tensor, ndarray or tftensorbin_data (
Union
[bytes
,bytearray
,None
]) – Binary data to sendjson_data (
Union
[str
,List
,Dict
,None
]) – JSON data to sendcustom_data (
Optional
[Any
]) – Custom data to sendgrpc_max_send_message_length (
int
) – Max grpc send message size in bytesgrpc_max_receive_message_length (
int
) – Max grpc receive message size in byteskwargs –
- Return type
- Returns
SeldonClientPrediction
-
seldon_core.seldon_client.
microservice_api_rest_aggregate
(microservice_endpoint='localhost:5000', shape=1, 1, datas=None, ndatas=None, payload_type='tensor', names=None, **kwargs)[source]¶ Call Seldon microservice REST API aggregate endpoint
- Parameters
microservice_endpoint (
str
) – Running microservice endpointshape (
Tuple
) – The shape of the data to senddatas (
Optional
[List
[ndarray
]]) – List of Numpy array data to sendndatas (
Optional
[int
]) – Multiple numpy arrays to send for aggregationpayload_type (
str
) – payload - tensor, ndarray or tftensorkwargs –
- Return type
- Returns
A SeldonClientPrediction
-
seldon_core.seldon_client.
microservice_api_rest_feedback
(prediction_request=None, prediction_response=None, reward=0, microservice_endpoint=None, **kwargs)[source]¶ Call Seldon microserice REST API to send feedback
- Parameters
- Return type
- Returns
A SeldonClientFeedback
-
seldon_core.seldon_client.
microservice_api_rest_seldon_message
(method='predict', microservice_endpoint='localhost:5000', shape=1, 1, data=None, payload_type='tensor', bin_data=None, str_data=None, json_data=None, names=None, **kwargs)[source]¶ Call Seldon microservice REST API
- Parameters
method (
str
) – The microservice method to callmicroservice_endpoint (
str
) – Running microservice endpointgrpc_max_send_message_length – Max grpc send message size in bytes
grpc_max_receive_message_length – Max grpc receive message size in bytes
method – The microservice method to call
shape (
Tuple
) – The shape of the data to sendnamespace – k8s namespace of running deployment
shape – Shape of the data to send
payload_type (
str
) – payload - tensor, ndarray or tftensorbin_data (
Union
[bytes
,bytearray
,None
]) – Binary data payloadjson_data (
Union
[str
,List
,Dict
,None
]) – JSON data payloadkwargs –
- Return type
- Returns
A SeldonClientPrediction data response
-
seldon_core.seldon_client.
rest_feedback_gateway
(prediction_request=None, prediction_response=None, prediction_truth=None, reward=0, deployment_name='', namespace=None, gateway_endpoint='localhost:8003', headers=None, gateway_prefix=None, client_return_type='proto', raw_request=None, **kwargs)[source]¶ Send Feedback to Seldon via gateway using REST
- Parameters
prediction_request (
Optional
[SeldonMessage
]) – Previous prediction requestprediction_response (
Optional
[SeldonMessage
]) – Previous prediction responsereward (
float
) – A reward to send in feedbackdeployment_name (
str
) – The name of the running Seldon deploymentnamespace (
Optional
[str
]) – k8s namespace of running deploymentgateway_endpoint (
str
) – The gateway host:port endpointgateway_prefix (
Optional
[str
]) – The prefix to add to the request path for gatewayclient_return_type (
str
) – the return type of all functions can be either dict or protokwargs –
- Return type
- Returns
A Seldon Feedback Response
-
seldon_core.seldon_client.
rest_feedback_seldon
(prediction_request=None, prediction_response=None, prediction_truth=None, reward=0, namespace=None, gateway_endpoint='localhost:8002', client_return_type='proto', raw_request=None, **kwargs)[source]¶ Send Feedback to Seldon API Gateway using REST
- Parameters
prediction_request (
Optional
[SeldonMessage
]) – Previous prediction requestprediction_response (
Optional
[SeldonMessage
]) – Previous prediction responsereward (
float
) – A reward to send in feedbacknamespace (
Optional
[str
]) – k8s namespace of running deploymentclient_return_type (
str
) – the return type of all functions can be either dict or protokwargs –
- Return type
-
seldon_core.seldon_client.
rest_predict_gateway
(deployment_name, namespace=None, gateway_endpoint='localhost:8003', shape=1, 1, data=None, headers=None, gateway_prefix=None, payload_type='tensor', bin_data=None, str_data=None, json_data=None, names=None, call_credentials=None, channel_credentials=None, http_path=None, meta={}, client_return_type='proto', raw_data=None, ssl=None, **kwargs)[source]¶ REST request to Gateway Ingress
- Parameters
deployment_name (
str
) – The name of the Seldon Deploymentnamespace (
Optional
[str
]) – k8s namespace of running deploymentgateway_endpoint (
str
) – The host:port of gatewaydata (
Optional
[ndarray
]) – The numpy data to sendgateway_prefix (
Optional
[str
]) – The prefix path to add to the requestpayload_type (
str
) – payload - tensor, ndarray or tftensorbin_data (
Union
[bytes
,bytearray
,None
]) – Binary data to sendjson_data (
Union
[str
,List
,Dict
,None
]) – JSON data to send as str, dict or listcall_credentials (
Optional
[SeldonCallCredentials
]) – Call credentials - see SeldonCallCredentialschannel_credentials (
Optional
[SeldonChannelCredentials
]) – Channel credentials - see SeldonChannelCredentialsmeta (
Dict
) – Custom meta mapclient_return_type (
str
) – the return type of all functions can be either dict or protoraw_data (
Optional
[Dict
]) – Raw payload (dictionary) given by the user
- Return type
- Returns
A requests Response object
-
seldon_core.seldon_client.
rest_predict_seldon
(namespace=None, gateway_endpoint='localhost:8002', shape=1, 1, data=None, payload_type='tensor', bin_data=None, str_data=None, json_data=None, names=None, client_return_type='proto', raw_data=None, meta={}, **kwargs)[source]¶ Call Seldon API Gateway using REST
- Parameters
namespace (
Optional
[str
]) – k8s namespace of running deploymentshape (
Tuple
) – Shape of endpointpayload_type (
str
) – payload - tensor, ndarray or tftensorbin_data (
Union
[bytes
,bytearray
,None
]) – Binary data to sendjson_data (
Union
[str
,List
,Dict
,None
]) – JSON data to sendclient_return_type (
str
) – the return type of all functions can be either dict or protoraw_data (
Optional
[Dict
]) – Raw payload (dictionary) given by the usermeta (
Dict
) – Custom meta data map, supplied as tagskwargs –
- Return type
- Returns
Seldon Client Prediction
seldon_core.seldon_methods module¶
-
seldon_core.seldon_methods.
aggregate
(user_model, request, seldon_metrics)[source]¶ Aggregate a list of payloads
-
seldon_core.seldon_methods.
handle_raw_custom_metrics
(msg, seldon_metrics, is_proto, method)[source]¶ Update SeldonMetrics object with custom metrics from raw methods. If INCLUDE_METRICS_IN_CLIENT_RESPONSE environmental variable is set to “true” metrics will be dropped from msg.
-
seldon_core.seldon_methods.
health_status
(user_model, seldon_metrics)[source]¶ Call the user model to check the health of the model
- Parameters
user_model (
Any
) – User defined class instanceseldon_metrics (
SeldonMetrics
) – A SeldonMetrics instance
- Return type
- Returns
Health check output
-
seldon_core.seldon_methods.
init_metadata
(user_model)[source]¶ Call the user model to get the model init_metadata
-
seldon_core.seldon_methods.
predict
(user_model, request, seldon_metrics)[source]¶ Call the user model to get a prediction and package the response
-
seldon_core.seldon_methods.
send_feedback
(user_model, request, predictive_unit_id, seldon_metrics)[source]¶
seldon_core.serving_test_gen module¶
seldon_core.storage module¶
seldon_core.user_model module¶
-
class
seldon_core.user_model.
SeldonComponent
(**kwargs)[source]¶ Bases:
object
- Return type
-
exception
seldon_core.user_model.
SeldonNotImplementedError
(message)[source]¶ Bases:
seldon_core.flask_utils.SeldonMicroserviceException
-
status_code
= 400¶
-
-
class
seldon_core.user_model.
SeldonResponse
(data, tags=None, metrics=None)[source]¶ Bases:
object
Simple class to store data returned by SeldonComponent methods together with relevant runtime metrics and runtime request tags.
-
seldon_core.user_model.
client_aggregate
(user_model, features_list, feature_names_list)[source]¶ Aggregate payloads
- Parameters
- Return type
- Returns
An aggregated payload
-
seldon_core.user_model.
client_class_names
(user_model, predictions)[source]¶ Get class names from user model
- Parameters
user_model (
SeldonComponent
) – User defined class instancepredictions (
ndarray
) – Prediction results
- Return type
- Returns
Class names
-
seldon_core.user_model.
client_custom_metrics
(user_model, seldon_metrics, method, runtime_metrics=[])[source]¶ Get custom metrics for client and update SeldonMetrics.
This function will return empty list if INCLUDE_METRICS_IN_CLIENT_RESPONSE environmental variable is NOT set to “true” or “True”.
- Parameters
user_model (
SeldonComponent
) – A Seldon user modelseldon_metrics (
SeldonMetrics
) – A SeldonMetrics instancemethod (
str
) – tag of a method that collected the metricsruntime_metrics (
List
[Dict
]) – metrics that were defined on runtime
- Return type
- Returns
A list of custom metrics
Get tags from user model
- Parameters
user_model (
SeldonComponent
) –- Return type
- Returns
Dictionary of key value pairs
-
seldon_core.user_model.
client_feature_names
(user_model, original)[source]¶ Get feature names for user model
- Parameters
user_model (
SeldonComponent
) – A Seldon user model
- Return type
- Returns
A list if feature names
-
seldon_core.user_model.
client_health_status
(user_model)[source]¶ Perform a health check
- Parameters
user_model (
SeldonComponent
) – A Seldon user model- Return type
- Returns
Health check results
-
seldon_core.user_model.
client_predict
(user_model, features, feature_names, **kwargs)[source]¶ Get prediction from user model
- Parameters
- Return type
- Returns
A prediction from the user model
-
seldon_core.user_model.
client_route
(user_model, features, feature_names, **kwargs)[source]¶ Get routing from user model
- Parameters
- Return type
- Returns
Routing index for one of children
-
seldon_core.user_model.
client_send_feedback
(user_model, features, feature_names, reward, truth, routing)[source]¶ Feedback to user model
- Parameters
- Return type
- Returns
Optional payload
-
seldon_core.user_model.
client_transform_input
(user_model, features, feature_names, **kwargs)[source]¶ Transform data with user model
- Parameters
- Return type
- Returns
Transformed data
seldon_core.utils module¶
-
seldon_core.utils.
array_to_grpc_datadef
(data_type, array, names=[])[source]¶ Convert numpy array and optional column names into a SeldonMessage DefaultData proto
-
seldon_core.utils.
array_to_list_value
(array, lv=None)[source]¶ Construct a proto ListValue from numpy array
- Parameters
array (
ndarray
) – Numpy arraylv (
Optional
[ListValue
]) – Proto buffer ListValue to extend
- Return type
ListValue
- Returns
ListValue protobuf
-
seldon_core.utils.
array_to_rest_datadef
(data_type, array, names=[])[source]¶ Construct a payload Dict from a numpy array
-
seldon_core.utils.
construct_response
(user_model, is_request, client_request, client_raw_response, meta=None, custom_metrics=None, runtime_tags=None)[source]¶ - Parameters
- Return type
SeldonMessage
- Returns
A SeldonMessage proto response
-
seldon_core.utils.
construct_response_json
(user_model, is_request, client_request_raw, client_raw_response, meta=None, custom_metrics=None, runtime_tags=None)[source]¶ This class converts a raw REST response into a JSON object that has the same structure as the SeldonMessage proto. This is necessary as the conversion using the SeldonMessage proto changes the Numeric types of all ints in a JSON into Floats.
- Parameters
user_model (
SeldonComponent
) – Client user classis_request (
bool
) – Whether this is part of the request flow as opposed to the response flowclient_request_raw (
Union
[List
,Dict
]) – The request received in JSON formatclient_raw_response (
Union
[ndarray
,str
,bytes
,dict
]) – The raw client response from their model
- Return type
- Returns
A SeldonMessage JSON response
-
seldon_core.utils.
extract_feedback_request_parts
(request)[source]¶ Extract key parts of the Feedback Message
-
seldon_core.utils.
feedback_to_json
(message_proto)[source]¶ Convert a SeldonMessage proto to JSON Dict
- Parameters
message_proto (
Feedback
) – SeldonMessage proto- Return type
- Returns
JSON Dict
-
seldon_core.utils.
get_data_from_proto
(request)[source]¶ Extract the data payload from the SeldonMessage
-
seldon_core.utils.
get_meta_from_proto
(request)[source]¶ Convert SeldonMessage proto meta into Dict
- Parameters
request (
SeldonMessage
) – SeldonMessage proto- Return type
- Returns
Dict
-
seldon_core.utils.
getenv
(*env_vars, default=None)[source]¶ Overload of os.getenv() to allow falling back through multiple environment variables. The environment variables will be checked sequentially until one of them is found.
- Parameters
*env_vars – Variadic list of environment variable names to check.
default – Default value to return if none of the environment variables exist.
- Returns
Value of the first environment variable set or default.
-
seldon_core.utils.
getenv_as_bool
(*env_vars, default=False)[source]¶ Read environment variable, parsing it to a boolean.
-
seldon_core.utils.
grpc_datadef_to_array
(datadef)[source]¶ Convert a SeldonMessage DefaultData to a numpy array.
- Parameters
datadef (
DefaultData
) – SeldonMessage DefaultData- Return type
ndarray
- Returns
A numpy array
-
seldon_core.utils.
json_to_feedback
(message_json)[source]¶ Parse a JSON message to a Feedback proto
- Parameters
message_json (
Dict
) – Input json message- Return type
Feedback
- Returns
A SeldonMessage
-
seldon_core.utils.
json_to_seldon_message
(message_json)[source]¶ Parses JSON input to a SeldonMessage proto
-
seldon_core.utils.
json_to_seldon_model_metadata
(metadata_json)[source]¶ Parses JSON input to SeldonModelMetadata proto
- Parameters
metadata_json (
Dict
) – JSON input- Return type
SeldonModelMetadata
- Returns
SeldonModelMetadata
-
seldon_core.utils.
seldon_message_to_json
(message_proto)[source]¶ Convert a SeldonMessage proto to JSON Dict
- Parameters
message_proto (
SeldonMessage
) – SeldonMessage proto- Return type
- Returns
JSON Dict