LocalWebservice Class

Represents a machine learning model deployed as a local web service endpoint.

Deploying web services locally is useful for debugging and testing scenarios.

Local webservice constructor.

LocalWebservice constructor is used to retrieve a local representation of a LocalWebservice object associated with the provided workspace.

Inheritance
LocalWebservice

Constructor

LocalWebservice(*args, **kwargs)

Parameters

Name Description
workspace
Required

The workspace object containing any Model objects that will be retrieved.

name
Required
str

The name of the Webservice object to retrieve.

must_exist
Required

Whether the webservice must already exist when creating the in-memory object.

workspace
Required

The workspace object containing any Model objects that will be retrieved.

name
Required
str

The name of the LocalWebservice object to retrieve.

must_exist
Required

Whether the webservice must already exist when creating the in-memory object.

Remarks

The following code samples shows how to create a local Docker web service. See the notebook link for more details.


   from azureml.core.webservice import LocalWebservice

   # This is optional, if not provided Docker will choose a random unused port.
   deployment_config = LocalWebservice.deploy_configuration(port=6789)

   local_service = Model.deploy(ws, "test", [model], inference_config, deployment_config)

   local_service.wait_for_deployment()

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local.ipynb

Methods

delete

Delete this LocalWebservice from the local machine.

This function call is not asynchronous; it runs until the service is deleted.

deploy_configuration

Create a configuration object for deploying a local Webservice.

deploy_to_cloud

Deploy a Webservice based on the LocalWebservice's configuration.

deserialize

Convert a Model Management Service response JSON object into a Webservice object.

Note

Not supported for LocalWebservice.

get_keys

Retrieve auth keys for this Webservice.

Note

Not supported for LocalWebservice.

get_logs

Retrieve logs for this LocalWebservice.

get_token

Retrieve auth token for this Webservice, scoped to the current user.

Note

Not supported for LocalWebservice.

list

List the LocalWebservices associated with the corresponding Workspace.

The results returned can be filtered using parameters.

regen_key

Regenerate one of the Webservice's keys.

Note

Not supported for LocalWebservice.

reload

Reload the LocalWebservice's execution script and dependencies.

This restarts the service's container with copies of updated assets, including the execution script and local dependencies, but it does not rebuild the underlying image. Accordingly, changes to Conda/pip dependencies or custom Docker steps will not be reflected in the reloaded LocalWebservice. To handle those changes call the update method instead.

run

Call this LocalWebservice with the provided input.

serialize

Convert this Webservice object into a JSON-serialized dictionary.

update

Update the LocalWebservice with provided properties.

Values left as None will remain unchanged in this LocalWebservice.

update_deployment_state

Refresh the current state of the in-memory object.

Perform an in-place update of the properties of the object based on the current state of the corresponding local Docker container.

wait_for_deployment

Poll the running LocalWebservice deployment.

delete

Delete this LocalWebservice from the local machine.

This function call is not asynchronous; it runs until the service is deleted.

delete(delete_cache=True, delete_image=False, delete_volume=True)

Parameters

Name Description
delete_cache
Required

Whether to delete temporary files cached for the service. (Default: True)

delete_image
Required

Whether to delete the service's Docker image. (Default: False)

delete_volume
Required

Whether to delete the service's Docker volume. (Default: True)

Exceptions

Type Description

deploy_configuration

Create a configuration object for deploying a local Webservice.

static deploy_configuration(port=None)

Parameters

Name Description
port
int

The local port on which to expose the service's HTTP endpoint.

default value: None

Returns

Type Description

A configuration object to use when deploying a Webservice object.

Exceptions

Type Description

deploy_to_cloud

Deploy a Webservice based on the LocalWebservice's configuration.

deploy_to_cloud(name=None, deployment_config=None, deployment_target=None)

Parameters

Name Description
name
str

The name to give the deployed service. Must be unique to the workspace.

default value: None
deployment_config

A WebserviceDeploymentConfiguration used to configure the webservice. If one is not provided, an empty configuration object will be used based on the desired target.

default value: None
deployment_target

A ComputeTarget to which to deploy the Webservice. As ACI has no associated ComputeTarget, leave this parameter as None to deploy to ACI.

default value: None

Returns

Type Description

A Webservice object corresponding to the deployed webservice.

Exceptions

Type Description

deserialize

Convert a Model Management Service response JSON object into a Webservice object.

Note

Not supported for LocalWebservice.

deserialize(workspace, webservice_payload)

Parameters

Name Description
cls
Required
workspace
Required

The workspace object the Webservice is registered under.

webservice_payload
Required

A JSON object to convert to a Webservice object.

Exceptions

Type Description
azureml.exceptions.NotImplementedError

get_keys

Retrieve auth keys for this Webservice.

Note

Not supported for LocalWebservice.

get_keys()

Returns

Type Description

The auth keys for this Webservice.

Exceptions

Type Description
azureml.exceptions.NotImplementedError

get_logs

Retrieve logs for this LocalWebservice.

get_logs(num_lines=5000, raw=False)

Parameters

Name Description
num_lines
Required
int

The maximum number of log lines to retrieve. (Default: 5000)

raw
Required

Return the raw Docker container output without attempting to format it. (Default: False)

Returns

Type Description
str

The logs for this LocalWebservice.

Exceptions

Type Description

get_token

Retrieve auth token for this Webservice, scoped to the current user.

Note

Not supported for LocalWebservice.

get_token()

Returns

Type Description

The auth token for this Webservice and when it should be refreshed after.

Exceptions

Type Description
azureml.exceptions.NotImplementedError

list

List the LocalWebservices associated with the corresponding Workspace.

The results returned can be filtered using parameters.

static list(workspace, model_name=None, model_id=None, all=None)

Parameters

Name Description
workspace
Required

The Workspace object associated with the LocalWebservices.

model_name
str

Filter list to only include LocalWebservices deployed with the specific model name.

default value: None
model_id
str

Filter list to only include LocalWebservices deployed with the specific model ID.

default value: None
all

Show all services. Only running services are shown by default.

default value: None

Returns

Type Description

A filtered list of LocalWebservices associated with the provided Workspace.

Exceptions

Type Description

regen_key

Regenerate one of the Webservice's keys.

Note

Not supported for LocalWebservice.

regen_key(key)

Parameters

Name Description
key
Required
str

Which key to regenerate. Options are 'Primary' or 'Secondary'

Exceptions

Type Description

reload

Reload the LocalWebservice's execution script and dependencies.

This restarts the service's container with copies of updated assets, including the execution script and local dependencies, but it does not rebuild the underlying image. Accordingly, changes to Conda/pip dependencies or custom Docker steps will not be reflected in the reloaded LocalWebservice. To handle those changes call the update method instead.

reload(wait=False)

Parameters

Name Description
wait
Required

Wait for the service's container to reach a healthy state. (Default: False)

Exceptions

Type Description

run

Call this LocalWebservice with the provided input.

run(input_data)

Parameters

Name Description
input_data
Required
<xref:varies>

The input with which to call the LocalWebservice.

Returns

Type Description
<xref:varies>

The result of calling the LocalWebservice.

Exceptions

Type Description

serialize

Convert this Webservice object into a JSON-serialized dictionary.

serialize()

Returns

Type Description

Serialized representation of the Webservice object.

Exceptions

Type Description

update

Update the LocalWebservice with provided properties.

Values left as None will remain unchanged in this LocalWebservice.

update(models=None, image_config=None, deployment_config=None, wait=False, inference_config=None)

Parameters

Name Description
models
Required

A new list of models contained in the LocalWebservice.

image_config
Required

Image configuration options to apply to the LocalWebservice.

deployment_config
Required

Deployment configuration options to apply to the LocalWebservice.

inference_config
Required

An InferenceConfig object used to provide the required model deployment properties.

wait
Required

Wait for the service's container to reach a healthy state. (Default: False)

Returns

Type Description

Exceptions

Type Description

update_deployment_state

Refresh the current state of the in-memory object.

Perform an in-place update of the properties of the object based on the current state of the corresponding local Docker container.

update_deployment_state(must_exist=False)

Parameters

Name Description
must_exist

Whether the webservice must already exist when creating the in-memory object.

default value: False

Exceptions

Type Description

wait_for_deployment

Poll the running LocalWebservice deployment.

wait_for_deployment(show_output=False)

Parameters

Name Description
show_output
Required

Option to print more verbose output. (Default: False)

Exceptions

Type Description

Attributes

port

Get the local webservice port.

Returns

Type Description
int

Port number.

scoring_uri

Get the local webservice scoring URI.

Returns

Type Description
str

Scoring URI.

swagger_uri

Get the local webservice Swagger URI.

Returns

Type Description
str

Swagger URI.

NETWORK_NAME

NETWORK_NAME = 'azureml-local'

STATE_DELETED

STATE_DELETED = 'deleted'

STATE_DEPLOYING

STATE_DEPLOYING = 'deploying'

STATE_FAILED

STATE_FAILED = 'failed'

STATE_RUNNING

STATE_RUNNING = 'running'

STATE_UNKNOWN

STATE_UNKNOWN = 'unknown'