Welcome to watson-machine-learning-client’s documentation!

watson-machine-learning-client is a python library that allows to work with Watson Machine Learning service on IBM Cloud. Test and deploy your models as APIs for application development, share with colleagues using this python library.

NOTE!! DEPRECATED!! This Watson Machine Learning client version is deprecated starting Sep 1st, 2020 and will be discontinued at the end of the migration period. Refer to the documentation at https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/wml-ai.html for the migration process to be able to access new features

NOTE: DEPRECATED!! Python 3.6 framework is deprecated and will be removed on Jan 20th, 2021. It will be read-only mode starting Nov 20th, 2020. i.e you won’t be able to create new assets using this client. For cloud, switch to using IBM Watson Machine Learning Python client with python 3.7

NOTE: DEPRECATED!! Spark 2.3 framework is deprecated and will be removed on Dec 1st, 2020. For cloud, switch to using IBM Watson Machine Learning Python client with Spark 2.4

Installation

The package is available on pypi. Please use below command to install it.

$pip install watson-machine-learning-client

Note

This package is being replaced in favor of the new package “ibm-watson-machine-learning” in V4 released version of WML python client.

Requirements

Watson Machine Learning service instance, you can create instance using this link. Only Python 3.5 or newer is supported.

Supported machine learning frameworks

For the list of supported machine learning frameworks (models) please refer to Watson Machine Learning Documentation.

Sample notebooks

Sample notebooks created using watson machine learning python client are available here.

API

Authorization can be done by IAM token.

IAM token

from watson_machine_learning_client import WatsonMachineLearningAPIClient

wml_credentials = {
                   "url": "https://us-south.ml.cloud.ibm.com",
                   "apikey":"***********",
                   "instance_id": "*****"
                  }

client = WatsonMachineLearningAPIClient(wml_credentials)

service_instance

class client.ServiceInstance(client)[source]

Connect, get details and check usage of your Watson Machine Learning service instance.

get_api_key()[source]

Get api_key of Watson Machine Learning service.

Returns

api_key

Return type

str

Example:

>>> instance_details = client.service_instance.get_api_key()
get_details()[source]

Get information about our instance of Watson Machine Learning service.

Returns

metadata of service instance

Return type

dict

Example:

>>> instance_details = client.service_instance.get_details()
get_instance_id()[source]

Get instance id of Watson Machine Learning service.

Returns

instance id

Return type

str

Example:

>>> instance_details = client.service_instance.get_instance_id()
get_password()[source]

Get password for Watson Machine Learning service.

Returns

password

Return type

str

Example:

>>> instance_details = client.service_instance.get_password()
get_url()[source]

Get instance url of Watson Machine Learning service.

Returns

instance url

Return type

str

Example:

>>> instance_details = client.service_instance.get_url()
get_username()[source]

Get username for Watson Machine Learning service.

Returns

username

Return type

str

Example:

>>> instance_details = client.service_instance.get_username()

repository

class client.Repository(client)[source]

Store and manage your models, definitions and experiments using Watson Machine Learning Repository.

DefinitionMetaNames = <watson_machine_learning_client.metanames.ModelDefinitionMetaNames object>

MetaNames for definitions creation.

ExperimentMetaNames = <watson_machine_learning_client.metanames.ExperimentMetaNames object>

MetaNames for experiments creation.

FunctionMetaNames = <watson_machine_learning_client.metanames.FunctionMetaNames object>

MetaNames for python functions creation.

ModelMetaNames = <watson_machine_learning_client.metanames.ModelMetaNames object>

MetaNames for models creation.

create_version(model, model_uid, meta_props=None)[source]

Create a new version for a model.

Note

Model version creation is not allowed for spark models

Parameters
  • model (str) –

    Can be one of following: - path to saved model in format:

    • keras (.tgz)

    • pmml (.xml)

    • scikit-learn (.tar.gz)

    • xgboost (.tar.gz)

    • tensorflow (.tar.gz)

    • spss (.str)

    • trained model guid

  • meta_props (dict/str) –

    meta data of the model. To see available meta names use:

    >>> client.repository.ModelMetaNames.get()
    

  • model_uid (str) – model ID

Returns

model version details

Return type

dict

Example:

>>> metadata = {
>>>        client.repository.ModelMetaNames.NAME: 'SAMPLE NAME',
>>>        client.repository.ModelMetaNames.DESCRIPTION: 'SAMPLE DESCRIPTION',
>>>        client.repository.ModelMetaNames.AUTHOR_NAME: 'AUTHOR',
>>>        client.repository.ModelMetaNames.FRAMEWORK_NAME: 'pmml',
>>>        client.repository.ModelMetaNames.FRAMEWORK_VERSION: '4.3'
>>>}

Example with local tar.gz containing model:

>>> stored_model_details = client.repository.create_version(path_to_tar_gz, model_uid="MODELID" ,meta_props=metadata)

Example with trained model guid:

>>> stored_model_details = client.repository.create_version(trained_model_guid, model_uid="MODELID" ,meta_props=metadata)
delete(artifact_uid)[source]

Delete model, definition, experiment or function from repository.

Parameters

artifact_uid (str) – stored model, definition, experiment or function UID

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.repository.delete(artifact_uid)
delete_definition(artifact_uid)[source]

Delete definition from repository.

Parameters

artifact_uid (str) – stored definition UID

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.repository.delete_definition(artifact_uid)
delete_experiment(artifact_uid)[source]

Delete experiment definition from repository.

Parameters

artifact_uid (str) – stored experiment UID

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.repository.delete_experiment(artifact_uid)
delete_function(artifact_uid)[source]

Delete function from repository.

Parameters

artifact_uid (str) – stored function UID

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.repository.delete_function(artifact_uid)
download(artifact_uid, filename='downloaded_artifact.tar.gz')[source]

Download artifact (model or function content) from repository to local file.

Parameters
  • artifact_uid (str) – stored artifact UID

  • filename (str) – name of local file to create (optional)

Returns

path to the downloaded file

Return type

str

Note

If filename is not specified, the default filename is “downloaded_artifact.tar.gz”.

Side effect:

save artifact to file.

Example:

>>> client.repository.download(model_uid, 'my_model.tar.gz')
get_definition_details(definition_uid=None, limit=None)[source]

Get metadata of stored definitions. If definition uid is not specified returns all model definitions metadata.

Parameters
  • definition_uid (str) – stored model definition UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

stored definition(s) metadata

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> definition_details = client.repository.get_definition_details(definition_uid)
>>> definition_details = client.repository.get_definition_details()
static get_definition_uid(definition_details)[source]

Get uid of stored definition.

Parameters

definition_details (dict) – stored definition details

Returns

uid of stored model

Return type

str

Example:

>>> definition_uid = client.repository.get_definition_uid(definition_details)
static get_definition_url(definition_details)[source]

Get url of stored definition.

Parameters

definition_details (dict) – stored definition details

Returns

url of stored definition

Return type

str

Example:

>>> definition_url = client.repository.get_definition_url(definition_details)
get_details(artifact_uid=None)[source]

Get metadata of stored artifacts. If uid is not specified returns all models, definitions, experiment, functions, libraries and runtimes metadata.

Parameters

artifact_uid (str) – stored model, definition, experiment, function, library or runtime UID (optional)

Returns

stored artifacts metadata

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> details = client.repository.get_details(artifact_uid)
>>> details = client.repository.get_details()
get_experiment_details(experiment_uid=None, limit=None)[source]

Get metadata of stored experiments. If no experiment uid is specified all experiments metadata is returned.

Parameters
  • experiment_uid (str) – stored experiment UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

stored experiment(s) metadata

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> experiment_details = client.repository.get_experiment_details(experiment_uid)
>>> experiment_details = client.repository.get_experiment_details()
static get_experiment_uid(experiment_details)[source]

Get uid of stored experiment.

Parameters

experiment_details (dict) – stored experiment details

Returns

uid of stored experiment

Return type

str

Example:

>>> experiment_uid = client.repository.get_experiment_uid(experiment_details)
static get_experiment_url(experiment_details)[source]

Get url of stored experiment.

Parameters

experiment_details (dict) – stored experiment details

Returns

url of stored experiment

Return type

str

Example:

>>> experiment_url = client.repository.get_experiment_url(experiment_details)
get_function_details(function_uid=None, limit=None)[source]

Get metadata of function. If no function uid is specified all functions metadata is returned.

Parameters
  • function_uid (str) – stored function UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

stored function(s) metadata

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> function_details = client.repository.get_function_details(function_uid)
>>> function_details = client.repository.get_function_details()
static get_function_uid(function_details)[source]

Get uid of stored function.

Parameters

function_details (dict) – stored function details

Returns

uid of stored function

Return type

str

Example:

>>> function_uid = client.repository.get_function_uid(function_details)
static get_function_url(function_details)[source]

Get url of stored function.

Parameters

function_details (dict) – stored function details

Returns

url of stored function

Return type

str

Example:

>>> function_url = client.repository.get_function_url(function_details)
get_model_details(model_uid=None, limit=None)[source]

Get metadata of stored models. If model uid is not specified returns all models metadata.

Parameters
  • model_uid (str) – stored model, definition or pipeline UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

stored model(s) metadata

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> model_details = client.repository.get_model_details(model_uid)
>>> models_details = client.repository.get_model_details()
static get_model_uid(model_details)[source]

Get uid of stored model.

Parameters

model_details (dict) – stored model details

Returns

uid of stored model

Return type

str

Example:

>>> model_uid = client.repository.get_model_uid(model_details)
static get_model_url(model_details)[source]

Get url of stored model.

Parameters

model_details (dict) – stored model details

Returns

url to stored model

Return type

str

Example:

>>> model_url = client.repository.get_model_url(model_details)
list()[source]

List stored models, definitions and experiments. Only first 50 records is shown. For more result use specific list functions.

Returns

None

Return type

None

Note

This function only prints the list of stored models, definitions and experiments

Example:

>>> client.repository.list()
list_definitions(limit=None)[source]

List stored definitions. If limit is set to None there will be only first 50 records shown.

Parameters

limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of stored training-definitions

Example:

>>> client.repository.list_definitions()
list_experiments(limit=None)[source]

List stored experiments. If limit is set to None there will be only first 50 records shown.

Parameters

limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of stored experiments

Example:

>>> client.repository.list_experiments()
list_functions(limit=None)[source]

List stored functions. If limit is set to None there will be only first 50 records shown.

Parameters

limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of stored functions

Example:

>>> client.repository.list_functions()
list_models(limit=None)[source]

List stored models. If limit is set to None there will be only first 50 records shown.

Parameters

limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of stored models

Example:

>>> client.repository.list_models()
load(artifact_uid)[source]

Load model from repository to object in local environment.

Parameters

artifact_uid (str) – stored model UID

Returns

trained model

Return type

object

Example:

>>> model = client.repository.load(model_uid)
store_definition(training_definition, meta_props)[source]

Store training definition into Watson Machine Learning repository on IBM Cloud.

Parameters
  • training_definition (str) – path to zipped model_definition

  • meta_props (dict) –

    meta data of the training definition. To see available meta names use:

    >>> client.repository.DefinitionMetaNames.get()
    

Returns

stored training definition details

Return type

dict

Example:

>>> metadata = {
>>>  client.repository.DefinitionMetaNames.NAME: 'my_training_definition',
>>>  client.repository.DefinitionMetaNames.FRAMEWORK_NAME: 'tensorflow',
>>>  client.repository.DefinitionMetaNames.FRAMEWORK_VERSION: '1.5',
>>>  client.repository.DefinitionMetaNames.RUNTIME_NAME: 'python',
>>>  client.repository.DefinitionMetaNames.RUNTIME_VERSION: '3.5',
>>>  client.repository.DefinitionMetaNames.EXECUTION_COMMAND: 'python3 tensorflow_mnist_softmax.py --trainingIters 20'
>>> }
>>> definition_details = client.repository.store_definition(training_definition_filepath, meta_props=metadata)
>>> definition_url = client.repository.get_definition_url(definition_details)
store_experiment(meta_props)[source]

Store experiment into Watson Machine Learning repository on IBM Cloud.

param meta_props

meta data of the experiment configuration. To see available meta names use:

>>> client.repository.ExperimentMetaNames.get()
type meta_props

dict

returns

stored experiment details

rtype

dict

Example:

>>> metadata = {
>>>  client.repository.ExperimentMetaNames.NAME: 'my_experiment',
>>>  client.repository.ExperimentMetaNames.EVALUATION_METRICS: ['accuracy'],
>>>  client.repository.ExperimentMetaNames.TRAINING_DATA_REFERENCE: {'connection': {'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net', 'access_key_id': '***', 'secret_access_key': '***'}, 'source': {'bucket': 'train-data'}, 'type': 's3'},
>>>  client.repository.ExperimentMetaNames.TRAINING_RESULTS_REFERENCE: {'connection': {'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net', 'access_key_id': '***', 'secret_access_key': '***'}, 'target': {'bucket': 'result-data'}, 'type': 's3'},
>>>  client.repository.ExperimentMetaNames.TRAINING_REFERENCES: [
>>>      {
>>>        'training_definition_url': definition_url_1
>>>      },
>>>      {
>>>        'training_definition_url': definition_url_2
>>>      },
>>>   ],
>>> }
>>> experiment_details = client.repository.store_experiment(meta_props=metadata)
>>> experiment_url = client.repository.get_experiment_url(experiment_details)
store_function(function, meta_props)[source]

Store function into Watson Machine Learning repository on Cloud.

As a ‘function’ may be used one of the following:
  • filepath to gz file

  • ‘score’ function reference, where the function is the function which will be deployed

  • generator function, which takes no argument or arguments which all have primitive python default values and as result return ‘score’ function

Parameters
  • meta_props (dict/str) –

    meta data or name of the function. To see available meta names use:

    >>> client.repository.FunctionMetaNames.get()
    

  • function (str or function) – path to file with archived function content or function (as described above)

Returns

stored function details

Return type

dict

Example: (using score function):

>>> def score(payload):
        values = [[row[0]*row[1]] for row in payload['values']]
        return {'fields': ['multiplication'], 'values': values}
>>> stored_function_details = client.repository.store_function(score, name)

Other, more interesting example is using generator function. In this situation it is possible to pass some variables:

>>> wml_creds = {...}
>>> def gen_function(wml_credentials=wml_creds, x=2):
        def f(payload):
            values = [[row[0]*row[1]*x] for row in payload['values']]
            return {'fields': ['multiplication'], 'values': values}
        return f
>>> stored_function_details = client.repository.store_function(gen_function, name)

In more complicated cases you should create proper metadata, similar to this one:

>>> metadata = {
>>>    client.repository.FunctionMetaNames.NAME: "function",
>>>    client.repository.FunctionMetaNames.DESCRIPTION: "This is ai function",
>>>    client.repository.FunctionMetaNames.RUNTIME_UID: "53dc4cf1-252f-424b-b52d-5cdd9814987f",
>>>    client.repository.FunctionMetaNames.INPUT_DATA_SCHEMA: {"fields": [{"metadata": {}, "type": "string", "name": "GENDER", "nullable": True}]},
>>>    client.repository.FunctionMetaNames.OUTPUT_DATA_SCHEMA: {"fields": [{"metadata": {}, "type": "string", "name": "GENDER", "nullable": True}]},
>>>    client.repository.FunctionMetaNames.TAGS: [{"value": "ProjectA", "description": "Functions created for ProjectA"}]
>>> }
>>> stored_function_details = client.repository.store_function(score, metadata)
store_model(model, meta_props=None, training_data=None, training_target=None, pipeline=None, feature_names=None, label_column_names=None)[source]

Store trained model into Watson Machine Learning repository on Cloud.

Parameters
  • model (object/str) –

    Can be one of following:

    • The train model object:
      • scikit-learn

      • xgboost

      • spark (PipelineModel)

    • path to saved model in format:
      • keras (.tgz)

      • pmml (.xml)

      • scikit-learn (.tar.gz)

      • xgboost (.tar.gz)

      • tensorflow (.tar.gz)

      • spss (.str)

    • directory containing model file(s):
      • scikit-learn

      • xgboost

      • tensorflow

    • trained model guid

  • meta_props (dict/str) –

    meta data of the training definition. To see available meta names use:

    >>> client.repository.ModelMetaNames.get()
    

  • training_data (spark dataframe, pandas dataframe, numpy.ndarray or array) – Spark DataFrame supported for spark models. Pandas dataframe, numpy.ndarray or array supported for scikit-learn models

  • training_target (array) – array with labels required for scikit-learn models

  • pipeline (object) – pipeline required for spark mllib models

  • feature_names (numpy.ndarray or list) – Feature names for the training data in case of Scikit-Learn/XGBoost models. This is applicable only in the case where the training data is not of type - pandas.DataFrame.

  • label_column_names (numpy.ndarray or list) – Label column names of the trained Scikit-Learn/XGBoost models.

Returns

stored model details

Return type

dict

Note

  • Keras model content is expected to be an archived vesion of a .h5 file

  • For deploying a keras model, it is mandatory to pass the FRAMEWORK_LIBRARIES along with other metaprops.

    >>> client.repository.ModelMetaNames.FRAMEWORK_LIBRARIES: [{'name':'keras', 'version': '2.1.3'}]
    
  • feature_names is an optional argument containing the feature names for the training data in case of Scikit-Learn/XGBoost models. Valid types are numpy.ndarray and list. This is applicable only in the case where the training data is not of type - pandas.DataFrame.

    If the training data is of type pandas.DataFrame and feature_names are provided, feature_names are ignored.

Example:

>>> stored_model_details = client.repository.store_model(model, name)

In more complicated cases you should create proper metadata, similar to this one:

>>> metadata = {
>>>        client.repository.ModelMetaNames.NAME: 'customer satisfaction prediction model',
>>>        client.repository.ModelMetaNames.FRAMEWORK_NAME: 'tensorflow',
>>>        client.repository.ModelMetaNames.FRAMEWORK_VERSION: '1.5',
>>>        client.repository.ModelMetaNames.RUNTIME_NAME: 'python',
>>>        client.repository.ModelMetaNames.RUNTIME_VERSION: '3.5'
>>>}

where FRAMEWORK_NAME may be one of following: “spss-modeler”, “tensorflow”, “xgboost”, “scikit-learn”, “pmml”.

Example with local tar.gz containing model:

>>> stored_model_details = client.repository.store_model(path_to_tar_gz, meta_props=metadata, training_data=None)

Example with local directory containing model file(s):

>>> stored_model_details = client.repository.store_model(path_to_model_directory, meta_props=metadata, training_data=None)

Example with trained model guid:

>>> stored_model_details = client.repository.store_model(trained_model_guid, meta_props=metadata, training_data=None)
update_experiment(experiment_uid, changes)[source]

Updates existing experiment metadata.

Parameters
  • experiment_uid (str) – UID of experiment which definition should be updated

  • changes (dict) – elements which should be changed, where keys are ExperimentMetaNames

Returns

metadata of updated experiment

Return type

dict

Example
>>> metadata = {
>>> client.repository.ExperimentMetaNames.NAME:"updated_exp"
>>> }
>>> exp_details = client.repository.update_experiment(experiment_uid, changes=metadata)
update_function(function_uid, changes)[source]

Updates existing function metadata.

Parameters
  • function_uid (str) – UID of function which definition should be updated

  • changes (dict) – elements which should be changed, where keys are FunctionMetaNames

Returns

metadata of updated function

Return type

dict

Example
>>> metadata = {
>>> client.repository.FunctionMetaNames.NAME:"updated_function"
>>> }
>>> function_details = client.repository.update_function(function_uid, changes=metadata)
update_model(model_uid, content_path=None, meta_props=None)[source]

Update content of model with new one.

Parameters
  • model_uid (str) – Model UID

  • content_path (str) – path to tar.gz with new content of model

Returns

updated metadata of model

Return type

dict

Example
>>> metadata = {
>>> client.repository.ModelMetaNames.NAME:"updated_model"
>>> }
>>> model_details = client.repository.update_model(model_uid, changes=metadata)
class metanames.ModelMetaNames[source]

Set of MetaNames for models.

Available MetaNames:

MetaName

Type

Required

Example value

NAME

str

Y

my_model

DESCRIPTION

str

N

my_description

AUTHOR_NAME

str

N

John Smith

FRAMEWORK_NAME

str

N

tensorflow

FRAMEWORK_VERSION

str

N

1.5

FRAMEWORK_LIBRARIES

list

N

[{'name': 'keras', 'version': '2.1.3'}]

RUNTIME_NAME

str

N

python

RUNTIME_VERSION

str

N

3.5

TRAINING_DATA_SCHEMA

dict

N

{}

INPUT_DATA_SCHEMA

dict

N

{}

TRAINING_DATA_REFERENCE

dict

N

{}

EVALUATION_METHOD

str

N

multiclass

EVALUATION_METRICS

list

N

[{'name': 'accuracy', 'value': 0.64, 'threshold': 0.8}]

OUTPUT_DATA_SCHEMA

dict

N

{'fields': [{'name': 'ID', 'metadata': {}, 'nullable': True, 'type': 'integer'}, {'name': 'Gender', 'metadata': {}, 'nullable': True, 'type': 'string'}, {'name': 'Status', 'metadata': {}, 'nullable': True, 'type': 'string'}, {'name': 'Children', 'metadata': {}, 'nullable': True, 'type': 'integer'}, {'name': 'Age', 'metadata': {}, 'nullable': True, 'type': 'decimal(14,6)'}, {'name': 'Customer_Status', 'metadata': {}, 'nullable': True, 'type': 'string'}, {'name': 'Car_Owner', 'metadata': {}, 'nullable': True, 'type': 'string'}, {'name': 'Customer_Service', 'metadata': {}, 'nullable': True, 'type': 'string'}, {'name': 'Satisfaction', 'metadata': {}, 'nullable': True, 'type': 'integer'}, {'name': 'Business_Area', 'metadata': {}, 'nullable': True, 'type': 'string'}, {'name': 'prediction', 'metadata': {'modeling_role': 'prediction'}, 'nullable': True, 'type': 'double'}, {'name': 'predictedLabel', 'metadata': {'modeling_role': 'decoded-target', 'values': ['NA', 'Free Upgrade', 'On-demand pickup location', 'Voucher', 'Premium features']}, 'nullable': True, 'type': 'string'}, {'name': 'probability', 'metadata': {'modeling_role': 'probability'}, 'nullable': True, 'type': {'containsNull': True, 'type': 'array', 'elementType': 'double'}}], 'type': 'struct'}

LABEL_FIELD

str

N

PRODUCT_LINE

TRANSFORMED_LABEL_FIELD

str

N

PRODUCT_LINE_IX

RUNTIME_UID

str

N

53628d69-ced9-4f43-a8cd-9954344039a8

TRAINING_DEFINITION_URL

str

N

https://us-south.ml.cloud.ibm.com/v3/ml_assets/training_definitions/ff24ebec-86af-4f2d-ab4c-2fc9e2a3efbc

class metanames.ModelDefinitionMetaNames[source]

Set of MetaNames for definitions.

Available MetaNames:

MetaName

Type

Required

Example value

NAME

str

Y

my_training_definition

DESCRIPTION

str

N

my_description

TRAINING_DATA_REFERENCES

list

N

{}

AUTHOR_NAME

str

N

John Smith

FRAMEWORK_NAME

str

Y

tensorflow

FRAMEWORK_VERSION

str

Y

1.5

RUNTIME_NAME

str

Y

python

RUNTIME_VERSION

str

Y

3.5

EXECUTION_COMMAND

str

N

python3 tensorflow_mnist_softmax.py --trainingIters 20

class metanames.ExperimentMetaNames[source]

Set of MetaNames for experiments.

Available MetaNames:

MetaName

Type

Required

Example value

NAME

str

Y

Hand-written Digit Recognitionu

DESCRIPTION

str

N

Hand-written Digit Recognition training

TAGS

list

N

[{'value': 'dsx-project.<project-guid>', 'description': 'DSX project guid'}]

AUTHOR_NAME

str

N

John Smith

EVALUATION_METHOD

str

N

multiclass

EVALUATION_METRICS

list

N

['accuracy']

TRAINING_REFERENCES

list

Y

[{'training_definition_url': 'https://ibm-watson-ml.mybluemix.net/v3/ml_assets/training_definitions/12345', 'compute_configuration': {'name': 'k80'}}, {'training_definition_url': 'https://ibm-watson-ml.mybluemix.net/v3/ml_assets/training_definitions/67890'}]

TRAINING_DATA_REFERENCE

dict

Y

{'connection': {'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net', 'access_key_id': '***', 'secret_access_key': '***'}, 'source': {'bucket': 'train-data'}, 'type': 's3'}

TRAINING_RESULTS_REFERENCE

dict

Y

{'connection': {'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net', 'access_key_id': '***', 'secret_access_key': '***'}, 'target': {'bucket': 'result-data'}, 'type': 's3'}

class metanames.FunctionMetaNames[source]

Set of MetaNames for AI functions.

Available MetaNames:

MetaName

Type

Required

Example value

NAME

str

Y

ai_function

DESCRIPTION

str

N

This is ai function

RUNTIME_UID

str

N

53628d69-ced9-4f43-a8cd-9954344039a8

INPUT_DATA_SCHEMA

dict

N

{'type': 'struct', 'fields': [{'name': 'x', 'type': 'double', 'nullable': False, 'metadata': {}}, {'name': 'y', 'type': 'double', 'nullable': False, 'metadata': {}}]}

OUTPUT_DATA_SCHEMA

dict

N

{'type': 'struct', 'fields': [{'name': 'multiplication', 'type': 'double', 'nullable': False, 'metadata': {}}]}

TAGS

list

N

[{'value': 'ProjectA', 'description': 'Functions created for ProjectA'}]

deployments

class client.Deployments(client)[source]

Deploy and score published artifacts (models and functions).

create(artifact_uid=None, name='Artifact deployment', description='Description of deployment', asynchronous=False, deployment_type='online', deployment_format='Core ML', meta_props=None, **kwargs)[source]

Create deployment (online) from artifact. As artifact we understand model or function which may be deployed.

Parameters
  • artifact_uid (str) – Published artifact UID (model or function UID)

  • name (str) – Deployment name

  • description (str) – Deployment description

  • asynchronous (bool) – if False then will wait until deployment will be fully created before returning

  • deployment_type (str) – type of deployment (‘online’, ‘virtual’). Default one is ‘online’

  • deployment_format (str) – file format of virtual deployment. Currently supported is ‘Core ML’ only (default value)

  • meta_props (dict) – dictionary with parameters used for virtual deployment (Core ML format)

Returns

details of created deployment

Return type

dict

Example

>>> online_deployment = client.deployments.create(model_uid, 'Deployment X', 'Online deployment of XYZ model.')
>>> virtual_deployment = client.deployments.create(model_uid, 'Deployment A', 'Virtual deployment of XYZ model.', deployment_type='virtual')
delete(deployment_uid)[source]

Delete deployment.

Parameters

deployment_uid (str) – Deployment UID

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.deployments.delete(deployment_uid)
download(virtual_deployment_uid, filename=None)[source]

Downloads file deployment of specified UID. Currently supported format is Core ML.

Parameters
  • virtual_deployment_uid (str) – UID of virtual deployment

  • filename (str) – filename of downloaded archive (optional)

Returns

path to downloaded file

Return type

str

get_details(deployment_uid=None, limit=None)[source]

Get information about your deployment(s).

Parameters
  • deployment_uid (str) – Deployment UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

metadata of deployment(s)

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example

>>> deployment_details = client.deployments.get_details(deployment_uid)
>>> deployment_details = client.deployments.get_details(deployment_uid=deployment_uid)
>>> deployments_details = client.deployments.get_details()
static get_download_url(deployment_details)[source]

Get deployment_download_url from deployment details.

Parameters

deployment_details (dict) – Created deployment details

Returns

deployment download URL that is used to get file deployment (for example: Core ML)

Return type

str

Example

>>> deployment_url = client.deployments.get_download_url(deployment)
static get_scoring_url(deployment)[source]

Get scoring_url from deployment details.

Parameters

deployment (dict) – Created deployment details

Returns

scoring endpoint URL that is used for making scoring requests

Return type

str

Example

>>> scoring_url = client.deployments.get_scoring_url(deployment)
get_status(deployment_uid)[source]

Get status of deployment creation.

Parameters

deployment_uid (str) – Guid of deployment

Returns

status of deployment creation

Return type

str

Example

>>> status = client.deployments.get_status(deployment_uid)
static get_uid(deployment_details)[source]

Get deployment_uid from deployment details.

Parameters

deployment_details (dict) – Created deployment details

Returns

deployment UID that is used to manage the deployment

Return type

str

Example

>>> deployment_uid = client.deployments.get_uid(deployment)
get_uids()[source]

Get all deployments uids.

Returns

list of uids

Return type

list of strings

Example:

>>> deployments_uids = client.deployments.get_uids()
static get_url(deployment_details)[source]

Get deployment_url from deployment details.

Parameters

deployment_details (dict) – Created deployment details

Returns

deployment URL that is used to manage the deployment

Return type

str

Example

>>> deployment_url = client.deployments.get_url(deployment)
list(limit=None)[source]

List deployments. If limit is set to None there will be only first 50 records shown.

Parameters

limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of deployments

Example:

>>> client.deployments.list()
score(scoring_url, payload, transaction_id=None)[source]

Make scoring requests against deployed artifact.

Parameters
  • scoring_url (str) – scoring endpoint URL

  • payload (dict) – records to score

  • transaction_id (str) – transaction id to be passed with records during payload logging (optional)

Returns

scoring result containing prediction and probability

Return type

dict

Example:

>>> scoring_payload = {'fields': ['GENDER','AGE','MARITAL_STATUS','PROFESSION'], 'values': [['M',23,'Single','Student'],['M',55,'Single','Executive']]}
>>> predictions = client.deployments.score(scoring_url, scoring_payload)
update(deployment_uid, name=None, description=None, asynchronous=False, meta_props=None)[source]

Update model used in deployment to the latest version. The scoring_url remains. Name and description change will not work for online deployment. For virtual deployments the file will be updated under the same download_url.

Parameters
  • deployment_uid (str) – Deployment UID

  • name (str) – new name for deployment

  • description (str) – new description for deployment

  • meta_props (dict) – dictionary with parameters used for virtual deployment (Core ML format)

Returns

updated metadata of deployment

Return type

dict

Example

>>> metadata = {
>>> client.deployments.ConfigurationMetaNames.NAME:"updated_Deployment"
>>> }
>>> deployment_details = client.deployments.update(deployment_uid, changes=metadata)

training

class client.Training(client)[source]

Train new models.

cancel(run_uid)[source]

Cancel model training.

Parameters

run_uid (str) – ID of trained model

Example

>>> client.training.cancel(run_uid)
delete(run_uid)[source]

Delete training run.

Parameters

run_uid (str) – ID of trained model

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example

>>> client.training.delete(run_uid)
get_definition_details(definition_uid=None, limit=None)[source]

Get metadata of stored definitions. If definition uid is not specified returns all model definitions metadata.

Parameters
  • definition_uid (str) – stored model definition UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

stored definition(s) metadata

Return type

dict

Example

>>> definition_details = client.training.get_definition_details(definition_uid)
>>> definition_details = client.training.get_definition_details()
get_definition_uid(definition_details)[source]

Get uid of stored definition.

Parameters

definition_details (dict) – stored definition details

Returns

uid of stored model

Return type

str

Example

>>> definition_uid = client.training.get_definition_uid(definition_details)
get_definition_url(definition_details)[source]

Get url of stored definition.

Parameters

definition_details (dict) – stored definition details

Returns

url of stored definition

Return type

str

Example

>>> definition_url = client.training.get_definition_url(definition_details)
get_details(run_uid=None, limit=None)[source]

Get training run details.

Parameters
  • run_uid (str) – ID of training run (optional, if not provided all runs details are returned)

  • limit (int) – limit number of fetched records (optional)

Returns

training run(s) details

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example

>>> training_run_details = client.training.get_details(run_uid)
>>> training_runs_details = client.training.get_details()
get_frameworks()[source]

Get list of supported frameworks.

Returns

supported frameworks for training

Return type

dict

Example

>>> model_details = client.training.get_frameworks()
get_latest_metrics(run_uid)[source]

Get latest metrics values.

Parameters

run_uid ({0}) – ID of trained model

Returns

metric values

Return type

list of dicts

Example

>>> client.training.get_latest_metrics(run_uid)
get_metrics(run_uid)[source]

Get metrics values.

Parameters

run_uid (str) – ID of trained model

Returns

metric values

Return type

list of dicts

Example

>>> client.training.get_metrics(run_uid)
static get_run_uid(run_details)[source]

Get uid of training run.

Parameters

run_details (dict) – training run details

Returns

uid of training run

Return type

str

Example

>>> model_uid = client.training.get_run_uid(run_details)
static get_run_url(run_details)[source]

Get training run url from training run details.

Parameters

run_details (dict) – Created training run details

Returns

training run URL that is used to manage the training

Return type

str

Example

>>> run_url = client.training.get_run_url(run_details)
get_status(run_uid)[source]

Get training status.

Parameters

run_uid (str) – ID of trained model

Returns

training run status

Return type

dict

Example

>>> training_status = client.training.get_status(run_uid)
list(limit=None)[source]

List training runs. If limit is set to None there will be only first 50 records shown.

Returns

None

Return type

None

Note

This function only prints the list of training runs

Example

>>> client.training.list()
list_definitions(limit=None)[source]

List stored definitions. If limit is set to None there will be only first 50 records shown.

Returns

None

Return type

None

Note

This function only prints the list of stored training-definitions

Example:

>>> client.training.list_definitions()
monitor_logs(run_uid)[source]

Monitor training log file (prints log content to console).

Parameters

run_uid (str) – ID of trained model

Example

>>> client.training.monitor_logs(run_uid)
monitor_metrics(run_uid)[source]

Monitor metrics log file (prints log content to console).

Parameters

run_uid (str) – ID of trained model

Example

>>> client.training.monitor_metrics(run_uid)
run(definition_uid, meta_props, asynchronous=True)[source]

Train new model.

Parameters
  • definition_uid (str) – uid to saved model_definition/pipeline

  • meta_props (dict) –

    meta data of the training configuration. To see available meta names use:

    >>> client.training.ConfigurationMetaNames.show()
    

  • asynchronous (bool) – Default True means that training job is submitted and progress can be checked later. False - method will wait till job completion and print training stats.

Returns

training run details

Return type

dict

Example

>>> metadata = {
>>>  client.training.ConfigurationMetaNames.NAME: u'Hand-written Digit Recognition',
>>>  client.training.ConfigurationMetaNames.TRAINING_DATA_REFERENCE: {
>>>          u'connection': {
>>>              u'endpoint_url': u'https://s3-api.us-geo.objectstorage.service.networklayer.com',
>>>              u'access_key_id': u'***',
>>>              u'secret_access_key': u'***'
>>>          },
>>>          u'source': {
>>>              u'bucket': u'wml-dev',
>>>          }
>>>          u'type': u's3'
>>>      }
>>> client.training.ConfigurationMetaNames.TRAINING_RESULTS_REFERENCE: {
>>>          u'connection': {
>>>              u'endpoint_url': u'https://s3-api.us-geo.objectstorage.service.networklayer.com',
>>>              u'access_key_id': u'***',
>>>              u'secret_access_key': u'***'
>>>          },
>>>          u'target': {
>>>              u'bucket': u'wml-dev-results',
>>>          }
>>>          u'type': u's3'
>>>      },
>>> client.training.ConfigurationMetaNames.COMPUTE_CONFIGURATION: {'name': 'p100'},
>>> client.training.ConfigurationMetaNames.EXECUTION_COMMAND: "python3 tensorflow_mnist_softmax.py --trainingIters 20",
>>> }
>>> run_details = client.training.run(definition_uid, meta_props=metadata)
>>> run_uid = client.training.get_run_uid(run_details)
class metanames.TrainingConfigurationMetaNames[source]

Set of MetaNames for trainings.

Available MetaNames:

MetaName

Type

Required

Default value

Example value

NAME

str

Y

Hand-written Digit Recognition

DESCRIPTION

str

N

Hand-written Digit Recognition training

AUTHOR_NAME

str

N

John Smith

TRAINING_DATA_REFERENCE

dict

Y

{'connection': {'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net', 'access_key_id': '***', 'secret_access_key': '***'}, 'source': {'bucket': 'train-data'}, 'type': 's3'}

TRAINING_RESULTS_REFERENCE

dict

Y

{'connection': {'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net', 'access_key_id': '***', 'secret_access_key': '***'}, 'target': {'bucket': 'train-data'}, 'type': 's3'}

EXECUTION_COMMAND

str

N

<value from model definition>

python3 tensorflow_mnist_softmax.py --trainingIters 20

COMPUTE_CONFIGURATION

dict

N

{'name': 'k80'}

{'name': 'k80'}

experiments

class client.Experiments(client)[source]

Run new experiment.

ConfigurationMetaNames = <watson_machine_learning_client.metanames.ExperimentMetaNames object>

MetaNames for experiments creation.

delete(experiment_run_uid)[source]

Delete experiment run.

Parameters

experiment_run_uid (str) – experiment run UID

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.experiments.delete(experiment_run_uid)

Hint

This function is only for deleting experiment runs. To delete whole experiment use:

>>> client.repository.delete(experiment_uid)
get_definition_details(experiment_uid=None, limit=None)[source]

Get metadata of stored experiments. If neither experiment uid nor url is specified all experiments metadata is returned.

Parameters
  • experiment_uid (str) – stored experiment UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

stored experiment(s) metadata

Return type

dict

Example

>>> experiment_details = client.experiments.get_definition_details(experiment_uid)
>>> experiment_details = client.experiments.get_definition_details()
get_definition_uid(experiment_details)[source]

Get uid of stored experiment.

Parameters

experiment_details (dict) – stored experiment details

Returns

uid of stored experiment

Return type

str

Example

>>> experiment_uid = client.experiments.get_definition_uid(experiment_details)
get_definition_url(experiment_details)[source]

Get url of stored experiment.

Parameters

experiment_details (dict) – stored experiment details

Returns

url of stored experiment

Return type

str

Example

>>> experiment_url = client.experiments.get_definition_url(experiment_details)
get_details(experiment_uid=None, limit=None)[source]

Get metadata of experiment(s) run(s). If no experiment_uid is provided, runs will be listed for all existing experiments.

Parameters
  • experiment_uid (str) – experiment UID (optional)

  • limit – limit number of fetched records (optional) :type limit: int

Returns

experiment(s) run(s) metadata

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> experiment_details = client.experiments.get_details(experiment_uid)
>>> experiment_details = client.experiments.get_details()
get_latest_metrics(experiment_run_uid)[source]

Get latest metrics values for experiment run.

Parameters

experiment_run_uid (str) – ID of training run

Returns

metric values

Return type

list of dicts

Example

>>> client.experiments.get_latest_metrics(experiment_run_uid)
get_metrics(experiment_run_uid)[source]

Get all metrics values for experiment run.

Parameters

experiment_run_uid (str) – ID of training run

Returns

metric values

Return type

list of dicts

Example

>>> client.experiments.get_metrics(experiment_run_uid)
get_run_details(experiment_run_uid)[source]

Get metadata of particular experiment run.

Parameters

experiment_run_uid (bool) – experiment run UID

Returns

experiment run metadata

Return type

dict

Example:

>>> experiment_run_details = client.experiments.get_run_details(experiment_run_uid)
static get_run_uid(experiment_run_details)[source]

Get experiment run uid.

Parameters

experiment_run_details (object) – details of experiment run

Returns

experiment run uid

Return type

str

Example:

>>> experiment_run_uid = client.experiments.get_run_uid(experiment_run_details)
static get_run_url(experiment_run_details)[source]

Get experiment run url.

Parameters

experiment_run_details (object) – details of experiment run

Returns

experiment run url

Return type

str

Example:

>>> experiment_run_url = client.experiments.get_run_url(experiment_run_details)
get_status(experiment_run_uid)[source]

Get experiment status.

Parameters

experiment_run_uid (bool) – ID of experiment run

Returns

experiment status

Return type

dict

Example:

>>> experiment_status = client.experiments.get_status(experiment_run_uid)
static get_training_runs(experiment_run_details)[source]

Get experiment training runs details.

Parameters

experiment_run_details – details of experiment run

Type

object

Returns

training runs

Return type

array

Example:

>>> training_runs = client.experiments.get_training_runs(experiment_run_details)
static get_training_uids(experiment_run_details)[source]

Get experiment training uids.

Parameters

experiment_run_details (object) – details of experiment run

Returns

training uids

Return type

array

Example:

>>> training_uids = client.experiments.get_training_uids(experiment_run_details)
list_definitions(limit=None)[source]

List stored experiments. If limit is set to None there will be only first 50 records shown.

Returns

None

Return type

None

Note

This function only prints the list of experiments

Example:

>>> client.experiments.list_definitions()
list_runs(experiment_uid=None, limit=None)[source]

List experiment runs. If experiment_uid set to None and limit set to None only 50 first records will be displayed.

Parameters
  • experiment_uid (str) – experiment UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of experiments-runs

Example:

>>> client.experiments.list_runs()
>>> client.experiments.list_runs(experiment_uid)
list_training_runs(experiment_run_uid)[source]

List training runs triggered by experiment run.

Parameters

experiment_run_uid (str) – experiment run UID

Returns

None

Return type

None

Note

This function only prints the list of training-runs associated with an experiment-run.

Example:

>>> client.experiments.list_training_runs(experiment_run_uid)
monitor_logs(experiment_run_uid)[source]

Monitor experiment run log files (prints log content to console).

Parameters

experiment_run_uid (str) – ID of experiment run

Example:

>>> client.experiments.monitor_logs(experiment_run_uid)
monitor_metrics(experiment_run_uid)[source]

Monitor metrics log file (prints metrics to console).

Parameters

experiment_run_uid – ID of experiment run

Example

>>> client.experiments.monitor_metrics(experiment_run_uid)
run(experiment_uid, asynchronous=True)[source]

Run experiment.

Parameters
  • experiment_uid (str) – ID of stored experiment

  • asynchronous (bool) – Default True means that experiment is started and progress can be checked later. False - method will wait till experiment end and print experiment stats.

Returns

experiment run details

Return type

dict

Example:

>>> experiment_run_status = client.experiments.run(experiment_uid)
>>> experiment_run_status = client.experiments.run(experiment_uid, asynchronous=False)

learning_system

class client.LearningSystem(client)[source]

Continuous Learning System.

get_details(model_uid)[source]

Get details of learning system.

Parameters

model_uid (str) – ID of model for this learning system

Returns

learning system details

Return type

dict

Example:

>>> learning_system_details = client.learning_system.get_details(model_uid)
get_metrics(model_uid)[source]

Get evaluation metrics.

Parameters

model_uid (str) – ID of stored model

Example:

>>> runs_details = client.learning_system.get_metrics(model_uid)
get_run_details(run_uid)[source]

Get run details.

Parameters

run_uid (str) – ID of learning iteration run

Example:

>>> run_details = client.learning_system.get_run_details(run_uid)
get_run_href(run_details)[source]

Get href of run (learning iteration).

Parameters

run_details (dict) – details of run

Returns

run href

Return type

str

Example:

>>> run_uid = client.learning_system.get_run_href(run_details)
get_run_uid(run_details)[source]

Get uid of run (learning iteration).

Parameters

run_details (dict) – details of run

Returns

run uid

Return type

str

Example:

>>> run_uid = client.learning_system.get_run_uid(run_details)
get_runs(model_uid)[source]

Get learning iterations (runs).

Parameters

model_uid (str) – ID of stored model

Returns

Learning Iterations

Return type

dict

Example:

>>> runs_details = client.learning_system.get_runs(model_uid)
list()[source]

List existing learning systems.

Returns

None

Return type

None

Note

This function only prints the list of existing learning_systems

Example:

>>> client.learning_system.list()
list_metrics(model_uid)[source]

Get evaluation metrics.

param model_uid

ID of stored model

type model_uid

str

Returns

None

Return type

None

Note

This function only prints the evaluation metrics

Example:

>>> runs_details = client.learning_system.get_metrics(model_uid)
list_runs(model_uid=None)[source]

List learning iterations.

Parameters

model_uid (str) – ID of stored model (optional)

Returns

None

Return type

None

Note

This function only prints the list of learning iterations

Example:

>>> client.learning_system.list_runs()
run(model_uid, asynchronous=True)[source]

Run learning iterations.

Parameters
  • model_uid (str) – ID of stored model

  • asynchronous (bool) – if the run should be asynchronous (optional)

Return type

dict

Example:

>>> client.learning_system.run(model_uid)
>>> client.learning_system.run(model_uid, asynchronous=False)
send_feedback(model_uid, feedback_data, fields=None)[source]

Send feedback data to learning system.

Parameters
  • model_uid (str) – ID of model

  • feedback_data (list of rows) – rows of feedback data to be send

  • fields (list of strings) – list of fields (optional)

Example:

>>> client.learning_system.send_feedback(model_uid, [["a1", 1, 1.0], ["a2", 2, 3.4]])
>>> client.learning_system.send_feedback(model_uid, [["a1", 1.0], ["a2", 3.4]], fields=["id", "value"])
setup(model_uid, meta_props)[source]

Setup continuous learning system for stored model.

Parameters
  • model_uid ({str_type}) – ID of stored model

  • meta_props (dict) – learning system configuration meta data

Returns

learning system configuration details

Return type

dict

Example:

>>> learning_system = client.learning_system.create(model_uid, meta_props=configuration)
update(model_uid, changes)[source]

Updates existing learning system metadata.

Parameters
  • model_uid (str) – UID of model which learning system should be updated

  • changes (dict) – elements which should be changed, where keys are LearningSystemMetaNames

Returns

metadata of updated learning system

Return type

dict

Example
>>> metadata = {
>>> client.learning_system.ConfigurationMetaNames.NAME:"updated_function"
>>> }
>>> learning_system_details = client.learning_system.update(model_uid, changes=metadata)
class metanames.LearningSystemMetaNames[source]

Set of MetaNames for learning system.

Available MetaNames:

MetaName

Type

Required

Example value

FEEDBACK_DATA_REFERENCE

dict

Y

{}

SPARK_REFERENCE

dict

N

{}

MIN_FEEDBACK_DATA_SIZE

int

Y

100

AUTO_RETRAIN

str

Y

conditionally

AUTO_REDEPLOY

str

Y

always

COMPUTE_CONFIGURATION

dict

N

{'name': 'k80'}

TRAINING_RESULTS_REFERENCE

dict

N

{'connection': {'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net', 'access_key_id': '***', 'secret_access_key': '***'}, 'target': {'bucket': 'train-data'}, 'type': 's3'}

runtimes

class client.Runtimes(client)[source]

Creates Runtime Specs and associated Custom Libraries.

delete(runtime_uid, with_libraries=False)[source]

Delete runtime.

Parameters
  • runtime_uid (str) – Runtime UID

  • autoremove (bool) – if set to False, only runtime will be removed, if set to True, all libraries belonging only to it will be removed

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.runtimes.delete(runtime_uid)
>>> client.runtimes.delete(runtime_uid, with_libraries=True)
delete_library(library_uid)[source]

Delete custom library from repository.

Parameters

library_uid (str) – stored custom library UID

Returns

returns the status message (“SUCCESS” or FAILED”)

Return type

str

Example:

>>> client.runtimes.delete_library(library_uid)
download_configuration(runtime_uid, filename=None)[source]

Downloads configuration file for runtime with specified UID.

Parameters
  • runtime_uid (str) – UID of runtime

  • filename (str) – filename of downloaded archive (optional)

Returns

path to the downloaded file

Return type

str

Note

If filename is not specified, the default filename is “runtime_configuration.yaml”.

Side effect:

save runtime configuration to file.

Example:

>>> filename = client.runtimes.download_configuration(runtime_uid)
>>> client.runtimes.download_configuration(runtime_uid, filename=filename)
download_library(library_uid, filename=None)[source]

Downloads custom library content with specified UID.

Parameters
  • library_uid (str) – UID of library

  • filename (str) – filename of downloaded archive (optional)

Returns

path to the downloaded file

Return type

str

Note

If filename is not specified, the default filename is “<LIBRARY-NAME>-<LIBRARY-VERSION>.zip”.

Side effect:

save library content to file.

Example:

>>> filename = client.runtimes.download_library(library_uid)
>>> client.runtimes.download_library(library_uid, filename=filename)
get_details(runtime_uid=None, limit=None)[source]

Get information about your runtime(s).

Parameters
  • runtime_uid (str) – Runtime UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

metadata of runtime(s)

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> runtime_details = client.runtimes.get_details(runtime_uid)
>>> runtime_details = client.runtimes.get_details(runtime_uid=runtime_uid)
>>> runtime_details = client.runtimes.get_details()
get_library_details(library_uid=None, limit=None)[source]

Get information about your custom libraries(s).

Parameters
  • library_uid (str) – Library UID (optional)

  • limit (int) – limit number of fetched records (optional)

Returns

metadata of libraries(s)

Return type

dict (if uid is not None) or {“resources”: [dict]} (if uid is None)

Example:

>>> library_details = client.runtimes.get_library_details(library_uid)
>>> library_details = client.runtimes.get_library_details(library_uid=library_uid)
>>> library_details = client.runtimes.get_library_details()
static get_library_uid(library_details)[source]

Get library uid from library details.

Parameters

library_details (dict) – Created library details

Returns

library uid

Return type

str

Example:

>>> library_uid = client.runtimes.get_library_uid(library_details)
static get_library_url(library_details)[source]

Get library url from library details.

Parameters

library_details (dict) – Created library details

Returns

library url

Return type

str

Example:

>>> library_url = client.runtimes.get_library_url(library_details)
static get_uid(details)[source]

Get runtime uid from runtime details, or runtime uid from model details.

Parameters

details (dict) – Created runtime or model details

Returns

runtime uid

Return type

str

Example:

>>> runtime_uid = client.runtimes.get_uid(runtime_details)
static get_url(details)[source]

Get runtime url from runtime details, or runtime url from model details.

Parameters

details (dict) – Created runtime or model details

Returns

runtime url

Return type

str

Example:

>>> runtime_url = client.runtimes.get_url(runtime_details)
list(limit=None)[source]

List runtimes. If limit is set to None there will be only first 50 records shown.

Parameters

limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of stored runtimes

Example:

>>> client.runtimes.list()
list_libraries(runtime_uid=None, limit=None)[source]

List custom libraries. If limit is set to None there will be only first 50 records shown.

Parameters
  • runtime_uid (str) – Runtime UID

  • limit (int) – limit number of fetched records (optional)

Returns

None

Return type

None

Note

This function only prints the list of stored libraries

Example:

>>> client.runtimes.list_libraries()
>>> client.runtimes.list_libraries(runtime_uid)
store(meta_props)[source]

Create runtime.

Parameters

meta_props (dict) –

dictionary with parameters describing runtime spec. To see available meta names use:

>>> client.runtimes.ConfigurationMetaNames.get()

Returns

details of created runtime

Return type

dict

The simplest way you might use me is:

>>> runtime_details = client.runtimes.store({
    client.runtimes.ConfigurationMetaNames.NAME: "test",
    client.runtimes.ConfigurationMetaNames.PLATFORM: {"name": "python", "version": "3.5"}
})

The most complex way to use me is:

>>>
    # here library is created
    lib_meta = {
        client.runtimes.LibraryMetaNames.NAME: "libraries_custom",
        client.runtimes.LibraryMetaNames.DESCRIPTION: "custom libraries for scoring",
        client.runtimes.LibraryMetaNames.FILEPATH: "/home/user/my_lib.zip",
        client.runtimes.LibraryMetaNames.VERSION: "1.0",
        client.runtimes.LibraryMetaNames.PLATFORM: {"name": "python", "versions": ["3.5"]}
    }
    custom_library_details = client.runtimes.store_library(lib_meta)
    custom_library_uid = client.runtimes.get_library_uid(custom_library_details)
    # now, metaprops for runtime spec are prepared
    meta = {
        client.runtimes.ConfigurationMetaNames.NAME: "runtime_spec_python_3.5",
        client.runtimes.ConfigurationMetaNames.DESCRIPTION: "test",
        client.runtimes.ConfigurationMetaNames.PLATFORM: {
            "name": "python",
            "version": "3.5"
        },
        client.runtimes.ConfigurationMetaNames.LIBRARIES_DEFINITIONS: [ # here in the background are created additional two libraries
            LibraryDefinition("my_lib_1", "1.0", "/home/user/my_lib_1.zip", description="t", platform={"name": "python", "versions": ["3.5"]}),
            LibraryDefinition("my_lib_2", "1.1", "/home/user/my_lib_2.zip")
        ],
        client.runtimes.ConfigurationMetaNames.LIBRARIES_UIDS: [custom_library_uid] # already existing lib is linked here
    }
    # Now runtime spec is created. Note that during runtime spec creation also "my_lib_1" and "my_lib_2" will be created and "libraries_custom" will be linked.
    runtime_details = client.runtimes.store(meta)
store_library(meta_props)[source]

Create custom library.

Parameters

meta_props (dict) –

dictionary with parameters describing custom library. To see available meta names use:

>>> client.runtimes.LibraryMetaNames.get()

Returns

details of created custom library

Return type

dict

Example:

>>> library_details = client.runtimes.store_library({
           client.runtimes.LibraryMetaNames.NAME: "libraries_custom",
           client.runtimes.LibraryMetaNames.DESCRIPTION: "custom libraries for scoring",
           client.runtimes.LibraryMetaNames.FILEPATH: custom_library_path,
           client.runtimes.LibraryMetaNames.VERSION: "1.0",
           client.runtimes.LibraryMetaNames.PLATFORM: {"name": "python", "versions": ["3.5"]}
       })
class metanames.RuntimeMetaNames[source]

Set of MetaNames for Runtime Specs.

Available MetaNames:

MetaName

Type

Required

Example value

NAME

str

Y

runtime_spec_python_3.5

DESCRIPTION

str

N

py35

PLATFORM

dict

Y

{'name': 'python', 'version': '3.5'}

LIBRARIES_UIDS

list

N

['46dc9cf1-252f-424b-b52d-5cdd9814987f']

LIBRARIES_DEFINITIONS

list

N

[{'name': 'libraries_custom', 'description': 'custom libraries for scoring', 'filepath': '/home/lib.gz', 'version': '1.0', 'platform': 'python', 'platform_versions': ['3.5']}]

CONFIGURATION_FILEPATH

str

N

/home/env_config.yaml

class metanames.LibraryMetaNames[source]

Set of MetaNames for Custom Libraries.

Available MetaNames:

MetaName

Type

Required

Example value

NAME

str

Y

my_lib

DESCRIPTION

str

N

my lib

PLATFORM

dict

Y

{'name': 'python', 'versions': ['3.5']}

VERSION

str

Y

1.0

FILEPATH

str

Y

/home/user/my_lib_1_0.zip