Gradient Docs
Gradient HomeHelp DeskCommunitySign up free
Gradient Next
Gradient Next
  • About Gradient
  • Get Started
    • Quick Start
      • Install the Gradient CLI
    • Core Concepts
    • Organizing Projects
      • Secrets
      • Storing an API key as a Secret
    • Tutorials
      • Gradient Notebooks Tutorial
      • Gradient Workflows Tutorial
      • Gradient Deployments Tutorial
    • FAQ
    • Common Errors
  • Gradient Platform
    • Gradient Notebooks
      • Runtimes
      • Files and storage
      • Machines
      • Terminal
      • Shortcuts
      • Sharing
      • TensorBoard
      • Run on Gradient
    • Gradient Workflows
      • Basic operations
      • Understanding Inputs & Outputs
      • Workflow Spec
      • Gradient Actions
      • Environment Variables
      • Using YAML for Data Science
    • Gradient Deployments
      • Basic operations
      • Deployment Spec
  • Artifacts
    • Container Management
      • Custom Containers
    • Data
      • Versioned Data
        • Public Datasets Repository
        • Storage Providers
      • Persistent Storage
    • Models
      • Managing Models
        • Model Types & Metadata
        • Public Models
    • Code
    • Metrics
      • Push Metrics
      • View & Query Metrics
  • Gradient Cluster
    • Overview
      • Setup
        • Managed Private Clusters
        • Self-Hosted Clusters
          • Pre-installation steps
          • Gradient Installer CLI
          • Terraform
            • Pre-installation steps
            • Install on AWS
            • Install on bare metal / VMs
            • Install on NVIDIA DGX
          • Let's Encrypt DNS Providers
          • Updating your cluster
      • Usage
  • More
    • SDK
      • Projects Client
      • Models Client
      • Deployments Client
      • Workflows Client
      • SDK Examples
      • Full SDK Reference
    • Machine Types
      • Machine Tiers
      • Free Machines (Free Tier)
    • Your Account
      • Teams
        • Creating a Team
        • Upgrading to a Team Plan
      • Hotkeys
      • Billing & Subscriptions
        • Storage Billing
      • Public Profiles
    • Release notes
    • Roadmap
Powered by GitBook
On this page
  • Getting Started
  • Print list of projects
  • Create project
  • Launch a Workflow
  1. More
  2. SDK

SDK Examples

PreviousWorkflows ClientNextMachine Types

Last updated 3 years ago

In this example, we'll run through a few basic commands using the SDK. We'll import the SDK, create a , and launch a .

The SDK is bundled with the .

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 . If you are using an interactive environment use the gradient apiKey command to securely configure your api key.

#Import the SDK Client from the gradient package
from gradient import sdk_client
#Set some variables
project = "prkr4412y" # Set your project
cluster = "cl8pwu9qn" # Set your cluster
#Set your SDK client 
deployment_client = sdk_client.DeploymentsClient()
models_client = sdk_client.ModelsClient()
jobs_client = sdk_client.JobsClient()
projects_client = ProjectsClient()
experiment_client = sdk_client.ExperimentsClient()
workflows_client = sdk_client.WorkflowsClient()

#or access them all from a single client
#client = sdk_client.SdkClient()

Print list of projects

projects_list = projects_client.list()
for project in projects_list:
       print("project_id: "+project.id +" project_name: "+ project.name)

Create project

#create a new project
project_id = projects_client.create("sample_tutorials")
print("project_id: "+proj_id)

Launch a Workflow

Grab your Workflow ID

workflows = workflows_client.list( project_id=project)

Run the Workflow

spec_path = "./sample.yaml"

yaml_spec = open(spec_path, 'r')
spec = yaml.safe_load(yaml_spec)


workflow_param = {
    "workflow_id" : "08676d5c-9873-4d24-a5d4-1fcc92218379",
    "spec": spec,
    "cluster_id" : cluster,
    "inputs": None
}

run_id = workflows_client.run_workflow(**workflow_param)
Project
Workflow
Gradient CLI
use a secret to pass it to your workload