Python client

The Watson Machine Learning Python client is a library that allows you to work with Watson Machine Learning service. Train, test and deploy your models as APIs for application development, then share with colleagues using this python library in a notebook.

Currently, in addition to the fully supported Python client library, based on Watson Machine Learning version 3 APIs, there is a preview of the next generation of Python client library, based on Watson Machine Learning version 4 APIs. This preview is available specifically to support AutoAI Experiments and Decision Optimization models. Functions that are not yet fully supported are marked as not implemented.

Important You cannot load both Python client libraries into a notebook. You must use one or the other.

Python client based on v3 of Watson Machine Learning APIs

Most of the Watson Machine Learning models use a Python client based on Watson Machine Learning Python client library, version 3. Use this library for working with all Watson Machine Learning assets with the exception of AutoAI Experiments and Decision Optimization models. For details on the this library, refer to Watson Machine Learning Python client external link.

For an example of deploying a model using the Python client with v3 APIs, see Watson Machine Learning Python client tutorial.

Preview: Python client based on v4 of Watson Machine Learning APIs

AutoAI and Decision Optimization are built using the new Watson Machine Learning Python client library, version 4, specifically designed to support new machine learning assets and features. To interact programmatically with an AutoAI or Decision Optimization deployment, refer to the syntax in Watson Machine Learning Python client library external link.

For an example of deploying a model using the v4 Python client, see Python Client Example

Installing the Watson Machine Learning Python client:

  1. Click Add to project, and then choose “NOTEBOOK”.
  2. Specify a name for the notebook.
  3. Accept the default language, Python, and accept the default runtime.
  4. Click Create Notebook.
  5. Install the Python client library.

Installing the default Python client

To install the fully supported Python client, enter the installation command in a notebook cell:

!pip install watson-machine-learning-client 

Installing the v4 Python client

To install the preview Python client, first, uninstall the existing Python client:

!pip uninstall watson-machine-learning-client -y

Then, install the preview client.

!pip install watson-machine-learning-client-V4

Finally, import the Watson Machine Learning APIs:

from watson_machine_learning_client import WatsonMachineLearningAPIClient

Troubleshooting the preview client

Note: If your notebook environment becomes unstable while you are running the preview version of the Python client, stopping and restarting the kernel from the notebook will not be sufficient. Restart the environment to reset the Python client to the default version.

  1. Open the Environments tab for the project containing the notebook.
  2. Choose Stop from the action menu for the active runtime.
  3. Return to the notebook. This will instantiate a new runtime.
  4. Re-run the commands to uninstall the default Python client and install the preview client.