Path: blob/master/cpd5.2/notebooks/python_sdk/instance-management/Machine Learning artifacts management.ipynb
6402 views
Machine Learning artifacts management
This notebook contains steps and code to demonstrate how to manage and clean up watsonx.ai instance. This notebook contains steps and code to work with ibm-watsonx-ai library available in PyPI repository. This notebook introduces commands for listing artifacts, getting artifacts details and deleting them.
Some familiarity with Python is helpful. This notebook uses Python 3.12.
Learning goals
The learning goals of this notebook are:
List watsonx.ai artifacts.
Get artifacts details.
Delete artifacts.
Contents
This notebook contains the following parts:
Install dependencies
Note: ibm-watsonx-ai
documentation can be found here.
Successfully installed anyio-4.9.0 certifi-2025.4.26 charset-normalizer-3.4.2 h11-0.16.0 httpcore-1.0.9 httpx-0.28.1 ibm-cos-sdk-2.14.1 ibm-cos-sdk-core-2.14.1 ibm-cos-sdk-s3transfer-2.14.1 ibm-watsonx-ai-1.3.20 idna-3.10 jmespath-1.0.1 lomond-0.3.3 numpy-2.2.6 pandas-2.2.3 pytz-2025.2 requests-2.32.2 sniffio-1.3.1 tabulate-0.9.0 typing_extensions-4.13.2 tzdata-2025.2 urllib3-2.4.0
Define credentials
Authenticate the watsonx.ai Runtime service on IBM Cloud Pak for Data. You need to provide the admin's username
and the platform url
.
Use the admin's api_key
to authenticate watsonx.ai Runtime services:
Alternatively you can use the admin's password
:
Create APIClient
instance
Working with spaces
First of all, you need to create a space that will be used for your work. If you do not have space already created, you can use {PLATFORM_URL}/ml-runtime/spaces?context=icp4data
to create one.
Click New Deployment Space
Create an empty space
Go to space
Settings
tabCopy
space_id
and paste it below
Tip: You can also use SDK to prepare the space for your work. More information can be found here.
Action: Assign space ID below
You can use list
method to print all existing spaces.
To be able to interact with all resources available in watsonx.ai, you need to set space which you will be using.
List existing pipelines. If you want to list only part of pipelines use client.pipelines.list(limit=n_pipelines)
.
Get pipelines details. If you want to get only part of pipelines details use client.pipelines.get_details(limit=n_pipelines)
.
You can get each pipeline details by calling client.pipelines.get_details()
and providing pipeline id from listed pipelines.
Delete all pipelines. You can delete one pipeline by calling client.pipelines.delete()
and providing pipeline id from listed pipelines.
List existing model definitions. If you want to list only part of model definitions use client.model_definitions.list(limit=n_model_definitions)
.
Get model definiton details by copying model definition id from above cell and running client.model_definitions.get_details(model_definition_id)
.
Delete model definitions by calling client.model_definitions.delete(model_definition_id)
.
List existing models. If you want to list only part of models use client.repository.list_models(limit=n_models)
.
Get model details by copying model id from above cell and running client.repository.get_details(model_id)
.
To download selected model from repository use:
Instead of downloading model can be also loaded directly to runtime using:
Delete model from repository by calling client.repository.delete(model_id)
.
List existing functions. If you want to list only part of functions use client.repository.list_functions(limit=n_functions)
.
Get function details by copying function id from above cell and running client.repository.get_details(function_id)
.
Delete function from repository by calling client.repository.delete(function_id)
.
List existing experiments. If you want to list only part of experiments use client.pipelines.list(limit=n_experiments)
.
Get experiments details. If you want to get only part of experiments details use client.experiments.get_details(limit=n_experiments)
.
You can get each experiment details by calling client.experiments.get_details()
and providing experiment id from listed experiments.
Delete all experiments. You can delete one experiment by calling client.experiments.delete()
and providing experiment id from listed experiments.
List existing trainings. If you want to list only part of trainings use client.training.list(limit=n_trainings)
.
Get trainings details. If you want to get only part of trainings details use client.training.get_details(limit=n_trainings)
.
You can get each training details by calling client.training.get_details()
and providing training id from listed trainings.
Delete all trainings. You can delete one training by calling client.training.cancel()
and providing training id from listed trainings.
Note The client.training.cancel()
method has hard_delete
parameter. Please change it to:
True - to delete the completed or canceled training runs.
False - to cancel the currently running training run.
Default value is False
.
List existing deployments. If you want to list only part of deployments use client.deployments.list(limit=n_deployments)
.
Get deployments details. If you want to get only part of deployments details use client.deployments.get_details(limit=n_deployments)
.
You can get each deployment details by calling client.deployments.get_details()
and providing deployment id from listed deployments.
Delete all deployments. You can delete one deployment by calling client.deployments.delete()
and providing deployment id from listed deployments.
You successfully completed this notebook! You learned how to use ibm-watsonx-ai
client for watsonx.ai instance management and clean up.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Szymon Kucharczyk, Software Engineer at IBM.
Rafał Chrzanowski, Software Engineer Intern at watsonx.ai.
Copyright © 2020-2025 IBM. This notebook and its source code are released under the terms of the MIT License.