SDK Examples
In this example, we'll run through a few basic commands using the SDK. We'll import the SDK, create a Project, and launch a Workflow.
The SDK is bundled with the Gradient CLI.
NOTE: We'll be adding a Jupyter Notebook template that you can run on your own.

Getting Started

This assumes that you have the environment variable PAPERSPACE_API_KEY set to your api key. If you are using a Paperspace environment it is recommend to use a secret to pass it to your workload. If you are using an interactive environment use the gradient apiKey command to securely configure your api key.
1
#Import the SDK Client from the gradient package
2
from gradient import sdk_client
Copied!
1
#Set some variables
2
project = "prkr4412y" # Set your project
3
cluster = "cl8pwu9qn" # Set your cluster
Copied!
1
#Set your SDK client
2
deployment_client = sdk_client.DeploymentsClient()
3
models_client = sdk_client.ModelsClient()
4
jobs_client = sdk_client.JobsClient()
5
projects_client = ProjectsClient()
6
experiment_client = sdk_client.ExperimentsClient()
7
workflows_client = sdk_client.WorkflowsClient()
8
9
#or access them all from a single client
10
#client = sdk_client.SdkClient()
Copied!

Print list of projects

1
projects_list = projects_client.list()
2
for project in projects_list:
3
print("project_id: "+project.id +" project_name: "+ project.name)
Copied!

Create project

1
#create a new project
2
project_id = projects_client.create("sample_tutorials")
3
print("project_id: "+proj_id)
Copied!

Launch a Workflow

Grab your Workflow ID
1
workflows = workflows_client.list( project_id=project)
Copied!
Run the Workflow
1
spec_path = "./sample.yaml"
2
3
yaml_spec = open(spec_path, 'r')
4
spec = yaml.safe_load(yaml_spec)
5
6
7
workflow_param = {
8
"workflow_id" : "08676d5c-9873-4d24-a5d4-1fcc92218379",
9
"spec": spec,
10
"cluster_id" : cluster,
11
"inputs": None
12
}
13
14
run_id = workflows_client.run_workflow(**workflow_param)
Copied!
Last modified 4mo ago