DataRobot Python Client

3.13.0 · active · verified Thu Apr 16

The DataRobot Python Client Library (v3.13.0) provides a programmatic interface for interacting with the DataRobot AI Platform, enabling users to manage projects, create models, perform predictions, and automate MLOps workflows. It follows a regular release cadence, typically monthly or bi-monthly, aligning with platform updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the DataRobot client, which by default reads configuration from environment variables (DATAROBOT_ENDPOINT, DATAROBOT_API_TOKEN). It then lists the first five projects accessible to the authenticated user. Ensure your environment variables are set for successful execution.

import datarobot as dr
import os

# Configure client using environment variables
# DATAROBOT_ENDPOINT e.g., 'https://app.datarobot.com/api/v2'
# DATAROBOT_API_TOKEN
# DATAROBOT_USERNAME (optional, for specific auth methods)
# DATAROBOT_PASSWORD (optional, for specific auth methods)

# For testing, ensure these are set in your environment or provide defaults.
endpoint = os.environ.get('DATAROBOT_ENDPOINT', 'YOUR_DATAROBOT_ENDPOINT')
token = os.environ.get('DATAROBOT_API_TOKEN', 'YOUR_DATAROBOT_API_TOKEN')

if 'YOUR_DATAROBOT_ENDPOINT' in endpoint or 'YOUR_DATAROBOT_API_TOKEN' in token:
    print("Please set DATAROBOT_ENDPOINT and DATAROBOT_API_TOKEN environment variables or replace placeholders.")
else:
    try:
        # Client auto-discovers config from environment variables by default.
        # Explicit config can be passed via dr.Client(token='...', endpoint='...').
        dr.Client()
        print("Successfully connected to DataRobot.")

        # List first 5 projects
        projects = dr.Project.list(max_projects=5)
        if projects:
            print("\nFirst 5 projects:")
            for p in projects:
                print(f" - {p.name} (ID: {p.id})")
        else:
            print("No projects found in your account.")

    except dr.errors.ClientInitializationError as e:
        print(f"Error initializing DataRobot client: {e}")
        print("Ensure DATAROBOT_ENDPOINT and DATAROBOT_API_TOKEN environment variables are correctly set.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →