Path: blob/master/cpd5.1/notebooks/python_sdk/deployments/python_function/Use Vault and Secret REST API to store secret in vault to utilize it inside Python function.ipynb
6405 views
Use Vault and Secret REST API to store secret in vault and utilize it inside Python function with ibm-watsonx-ai
This notebook demonstrates an example for using Vault and Secret REST API services to store secrets in order to utilize it inside Python function. It contains steps and code to work with ibm-watsonx-ai library available in PyPI repository.
Learning goals
The learning goals of this notebook are:
Store secret in Vault using Secret REST API.
Utilize secret inside Python function.
Contents
This notebook contains the following parts:
Install ibm-watsonx-ai
Note: ibm-watsonx-ai
documentation can be found here.
Define credentials
Authenticate the watsonx.ai Runtime on IBM Cloud Pak for Data. You need to provide the admin's username
and the platform url
.
Use the admin's password to authenticate watsonx.ai Runtime:
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 Runtime, you need to set space which you will be using.
Define the secret
Create a secret utilizing the credentials defined above.
Note: Vault and Secret REST API documentation is available here.
Fetch Vault URN
In order to use the Secret REST API, you need to retrieve the Vault URN, which points to the vault where your secret will be stored.
Define the Cloud Pak for Data host
Define request parameters
List available vaults
Specify Vault URN
Store secret in Vault
In order to utilize your secret inside the Python function, it needs to be stored in the Vault.
Define request parameters
Store the secret
Store and deploy the function
Before you can deploy the function, you must store it in your watsonx.ai Runtime.
Store the function
In order to deploy the function, you need to specify your software specification.
Get software specification ID
Store the function in watsonx.ai Runtime
Get ID of deployed function
Deploy the function
After storing the function in your watsonx.ai Runtime, you can deploy it to your deployment space.
Test using ibm-watsonx-ai
Python SDK
Get deployment endpoint URL for REST API testing
If you want to clean up all created assets:
experiments
trainings
pipelines
model definitions
models
functions
deployments
please follow up this sample notebook.
Summary and next steps
In this notebook, you created a Python function that receives HTML canvas image data and then processes and sends that data to a model trained to recognize handwritten digits.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Rafał Chrzanowski, Software Engineer Intern at watsonx.ai.
Copyright © 2025 IBM. This notebook and its source code are released under the terms of the MIT License.