DataRobot Python Client
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
-
datarobot.errors.ClientInitializationError: API token or endpoint not provided
cause The DataRobot client could not find the necessary API token or endpoint to establish a connection. This often happens if environment variables (`DATAROBOT_API_TOKEN`, `DATAROBOT_ENDPOINT`) are not set, or if they are not passed explicitly to `dr.Client()`.fixSet the `DATAROBOT_API_TOKEN` and `DATAROBOT_ENDPOINT` environment variables. For example: `export DATAROBOT_API_TOKEN='your_token'` and `export DATAROBOT_ENDPOINT='https://app.datarobot.com/api/v2'`. Alternatively, initialize the client with `dr.Client(token='your_token', endpoint='your_endpoint')`. -
requests.exceptions.SSLError: HTTPSConnectionPool(...) Max retries exceeded with url: (...) Caused by SSLError(CertificateError(...))
cause SSL certificate verification failed, typically due to a corporate proxy or firewall interfering with the TLS handshake. Python's `requests` library does not trust the custom certificates presented by the proxy.fixConfigure the `REQUESTS_CA_BUNDLE` environment variable to point to your corporate CA certificate bundle. For example: `export REQUESTS_CA_BUNDLE='/etc/ssl/certs/ca-certificates.crt'`. You may also need to set proxy environment variables (`HTTP_PROXY`, `HTTPS_PROXY`). -
AttributeError: module 'datarobot' has no attribute 'Client'
cause This error usually indicates an outdated version of the `datarobot` library, a conflict with a local file named `datarobot.py`, or an incorrect import pattern.fixEnsure you have the latest version of the `datarobot` library by running `pip install --upgrade datarobot`. Check your project directory for any files named `datarobot.py` that might shadow the installed package. Confirm you are using `import datarobot as dr` and then `dr.Client()`. -
datarobot.errors.NotFound: No such project found with ID '...'
cause The specified project ID does not exist, is incorrect, or the authenticated user does not have permission to access it.fixVerify the project ID is correct. Ensure the API token belongs to a user with appropriate permissions to view or interact with the project. You can list all projects to which you have access using `dr.Project.list()` to find correct IDs.
Warnings
- breaking The `datarobot.Client` initialization changed significantly in version 3.0. Prior versions often required explicitly passing `endpoint` and `token` arguments to the `Client` constructor. Version 3.0+ defaults to auto-discovery from environment variables (DATAROBOT_ENDPOINT, DATAROBOT_API_TOKEN) or a configuration file.
- breaking Methods for interacting with the prediction API (e.g., `predict_raw`) may have changed signatures or availability across major versions, particularly regarding how data is passed and results are retrieved.
- gotcha Connecting from corporate networks can often lead to `SSLError` due to proxy configurations or custom CA certificates. The Python `requests` library (used by DataRobot client) might not trust these certificates by default.
- gotcha When working with large datasets, uploading or downloading them directly through the client can be slow or hit memory limits. DataRobot provides specific methods for large data handling.
Install
-
pip install datarobot
Imports
- Client
from datarobot import Client
import datarobot as dr dr.Client()
- Project
import datarobot as dr dr.Project
- Deployment
import datarobot as dr dr.Deployment
Quickstart
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}")