Path: blob/master/cpd5.2/notebooks/python_sdk/instance-management/Machine Learning artifacts export and import.ipynb
6402 views
Export/Import assets with ibm-watsonx-ai
This notebook demonstrates an example for exporting/importing assets using watsonx.ai service. It contains steps and code to work with ibm-watsonx-ai library available in PyPI repository.
Some familiarity with Python is helpful. This notebook uses Python 3.12.
Learning goals
The learning goals of this notebook are:
Download an externally trained Keras model.
Persist an external model in watsonx.ai repository.
Export the model from the space
Import the model to another space (for Cloud Pak for Data 5.2, the space/project where assets are imported has to be empty) and deploy
Contents
This notebook contains the following parts:
Install dependencies
Note: ibm-watsonx-ai
documentation can be found here.
Successfully installed wget-3.2
Successfully installed contourpy-1.3.2 cycler-0.12.1 fonttools-4.58.4 kiwisolver-1.4.8 matplotlib-3.10.3 numpy-2.3.1 pillow-11.2.1 pyparsing-3.2.3
Successfully installed anyio-4.9.0 certifi-2025.6.15 charset_normalizer-3.4.2 h11-0.16.0 httpcore-1.0.9 httpx-0.28.1 ibm-cos-sdk-2.14.2 ibm-cos-sdk-core-2.14.2 ibm-cos-sdk-s3transfer-2.14.2 ibm-watsonx-ai-1.3.26 idna-3.10 jmespath-1.0.1 lomond-0.3.3 pandas-2.2.3 pytz-2025.2 requests-2.32.4 sniffio-1.3.1 tabulate-0.9.0 typing_extensions-4.14.0 tzdata-2025.2 urllib3-2.5.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
Create two spaces. One for export and one for import
Tip: You can refer to example for space management APIs here.
Create export space
Create import space
Download data used for training the Keras model
In this section, you will learn how to store your model in watsonx.ai repository by using the ibm-watsonx-ai
client.
3.1: Publish model
Define model name, type and software specification needed to deploy model later.
3.2: Get model details
3.3 Get all models in the space
The space_id
is automatically picked up from client.set.default_space()
API call before
client.export_assets
has these APIs. For any help on these apis, type help(api_name)
in your notebook Example: help(client.export_assets.start)
, help(client.export_assets.get_details)
client.export_assets.start
: This starts the export job. Export job is asynchronously executedclient.export_assets.get_details
: Givenexport_id
and correspondingspace_id
/project_id
, this gives the export job details. Usually used for monitoring the export job submitted with start APIclient.export_assets.list
: Prints summary of all the export jobsclient.export_assets.get_exported_content
: Downloads the exported content. This information will be used by the import processclient.export_assets.delete
: Deletes the given export jobclient.export_assets.cancel
: Cancels the given export job if running
4.1: Start the export process
Start the export process for the model created. Either ASSET_IDS or ASSET_TYPES or ALL_ASSETS can be provided. If you have more than one model ids, you need to provide them as array like client.export_assets.ConfigurationMetaNames.ASSET_IDS: [model_id1, model_id2] Refer to the help api above to see different usages and details
4.2: Monitor the export process
4.3: Get the exported content
client.import_assets
has these APIs. For any help on these APIs, type help(api_name)
in your notebook. Example: help(client.import_assets.start)
, help(client.import_assets.get_details)
client.import_assets.start
: This starts the import job. Import job is asynchronously executedclient.import_assets.get_details
: Givenimport_id
and correspondingspace_id
/project_id
, this gives the import job details. Usually used for monitoring the import job submitted with start APIclient.import_assets.list
: Prints summary of all the import jobsclient.import_assets.delete
: Deletes the given import jobclient.import_assets.cancel
: Cancels the given import job if running
5.1: Start the import process
5.2: Monitor the import process
Display the list of models in the import space
List the import jobs
List the export jobs
6.1: Create model deployment
Create online deployment for published model
Now you can print an online scoring endpoint.
You can also list existing deployments.
6.2: Get deployment details
6.3: Score
You can use below method to do test scoring request against deployed model.
Let's first visualize two samples from dataset, we'll use for scoring. You must have matplotlib package installed
Prepare scoring payload with records to score.
Use client.deployments.score()
method to run scoring.
As you can see, predicted values are the same one as displayed above from test dataset.
If you want to clean up all created assets:
experiments
trainings
pipelines
model definitions
models
functions
deployments
please follow up this sample notebook.
You successfully completed this notebook! You learned how to use export/import assets client apis.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Mithun - [email protected], Software Engineer
Copyright © 2020-2025 IBM. This notebook and its source code are released under the terms of the MIT License.