Predictors

Make real-time predictions against SageMaker endpoints with Python objects

class sagemaker.predictor.RealTimePredictor(endpoint, sagemaker_session=None, serializer=None, deserializer=None, content_type=None, accept=None)

Bases: object

Make prediction requests to an Amazon SageMaker endpoint.

Initialize a RealTimePredictor.

Behavior for serialization of input data and deserialization of result data can be configured through initializer arguments. If not specified, a sequence of bytes is expected and the API sends it in the request body without modifications. In response, the API returns the sequence of bytes from the prediction result without any modifications.

Parameters
  • endpoint (str) – Name of the Amazon SageMaker endpoint to which requests are sent.

  • sagemaker_session (sagemaker.session.Session) – A SageMaker Session object, used for SageMaker interactions (default: None). If not specified, one is created using the default AWS configuration chain.

  • serializer (callable) – Accepts a single argument, the input data, and returns a sequence of bytes. It may provide a content_type attribute that defines the endpoint request content type. If not specified, a sequence of bytes is expected for the data.

  • deserializer (callable) – Accepts two arguments, the result data and the response content type, and returns a sequence of bytes. It may provide a content_type attribute that defines the endpoint response’s “Accept” content type. If not specified, a sequence of bytes is expected for the data.

  • content_type (str) – The invocation’s “ContentType”, overriding any content_type from the serializer (default: None).

  • accept (str) – The invocation’s “Accept”, overriding any accept from the deserializer (default: None).

predict(data, initial_args=None, target_model=None)

Return the inference from the specified endpoint.

Parameters
  • data (object) – Input data for which you want the model to provide inference. If a serializer was specified when creating the RealTimePredictor, the result of the serializer is sent as input data. Otherwise the data must be sequence of bytes, and the predict method then sends the bytes in the request body as is.

  • initial_args (dict[str,str]) – Optional. Default arguments for boto3 invoke_endpoint call. Default is None (no default arguments).

  • target_model (str) – S3 model artifact path to run an inference request on, in case of a multi model endpoint. Does not apply to endpoints hosting single model (Default: None)

Returns

Inference for the given input. If a deserializer was specified when creating

the RealTimePredictor, the result of the deserializer is returned. Otherwise the response returns the sequence of bytes as is.

Return type

object

delete_endpoint(delete_endpoint_config=True)

Delete the Amazon SageMaker endpoint backing this predictor. Also delete the endpoint configuration attached to it if delete_endpoint_config is True.

Parameters

delete_endpoint_config (bool, optional) – Flag to indicate whether to delete endpoint configuration together with endpoint. Defaults to True. If True, both endpoint and endpoint configuration will be deleted. If False, only endpoint will be deleted.

delete_model()

Deletes the Amazon SageMaker models backing this predictor.

enable_data_capture()

Updates the DataCaptureConfig for the Predictor’s associated Amazon SageMaker Endpoint to enable data capture. For a more customized experience, refer to update_data_capture_config, instead.

disable_data_capture()

Updates the DataCaptureConfig for the Predictor’s associated Amazon SageMaker Endpoint to disable data capture. For a more customized experience, refer to update_data_capture_config, instead.

update_data_capture_config(data_capture_config)

Updates the DataCaptureConfig for the Predictor’s associated Amazon SageMaker Endpoint with the provided DataCaptureConfig.

Parameters

data_capture_config (sagemaker.model_monitor.DataCaptureConfig) – The DataCaptureConfig to update the predictor’s endpoint to use.

list_monitors()

Generates ModelMonitor objects (or DefaultModelMonitors) based on the schedule(s) associated with the endpoint that this predictor refers to.

Returns

A list of

ModelMonitor (or DefaultModelMonitor) objects.

Return type

[sagemaker.model_monitor.model_monitoring.ModelMonitor]