Path: blob/master/cpd5.1/notebooks/python_sdk/deployments/py-script/Use watsonx to deploy python script.ipynb
6405 views
Use ibm-watsonx-ai
to deploy Python script
This notebook contains steps and code to demonstrate how to deploy a Python script with the ibm-watsonx-ai library available in the PyPI repository. This notebook consists of steps to create a pPthon script, create a deployment, create and run a job.
Some familiarity with Python is helpful. This notebook uses Python 3.11.
Learning goals
The learning goals of this notebook are:
Create and save a python script.
Deploy the script using the client library.
Create and Run a job which utilises the created deployment.
Contents
This notebook contains the following parts:
Install and import the ibm-watsonx-ai
and dependecies
Note: ibm-watsonx-ai
documentation can be found here.
Connection to WML
Authenticate the Watson Machine Learning service on IBM Cloud Pak for Data. You need to provide platform url
, your username
and api_key
.
Alternatively you can use username
and password
to authenticate WML services.
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 Watson Machine Learning, you need to set space which you will be using.
Software specification
You can use popular tools, libraries, and frameworks to train and deploy machine learning models and functions.
The following list shows the predefined (base) model types and software specifications.
You can select the software specification using the function below.
Save Python Script
This file will be saved locally so you can deploy and run it later.
The file should be successfully created. To check its content, you can use the command below.
Deployment of Python Script
You can store and deploy a Python script and get its details by running the code in following cells.
To download the asset run the code below. It will be downloaded as a zip archive.
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 create and deploy a python script, and create and run a job using Watson Machine Learning.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Author
Jakub Żywiecki, Software Engineer
Copyright © 2024-2025 IBM. This notebook and its source code are released under the terms of the MIT License.