DataRobot Predict
raw JSON → 1.13.5 verified Fri May 01 auth: no python
A lightweight Python library for scoring predictions with DataRobot models. It provides a simple API to interact with DataRobot's prediction server, supporting both REST and batch predictions. Current version: 1.13.5, maintained by DataRobot. Release cadence is irregular.
pip install datarobot-predict Common errors
error datarobot_predict.exceptions.PredictionError: 401 Client Error: Unauthorized for url: https://... ↓
cause Invalid or missing API key, or incorrect endpoint URL.
fix
Verify your API key and endpoint URL. Ensure the API key is set correctly, e.g., export DATAROBOT_API_KEY='your_key'
error TypeError: __init__() got an unexpected keyword argument 'deployment_id' ↓
cause Using deployment_id parameter that was removed in v1.12+.
fix
Include deployment ID directly in the endpoint URL, not as a separate parameter.
error ModuleNotFoundError: No module named 'datarobot_predict' ↓
cause Installed the wrong package (e.g., 'datarobot' instead of 'datarobot-predict').
fix
Run: pip install datarobot-predict
error datarobot_predict.exceptions.PredictionError: 422 Client Error: Unprocessable Entity ↓
cause The input data format is incorrect. DataRobot expects a JSON object with keys matching model features.
fix
Ensure your data is a dict with feature names as keys, values should be proper types (strings, numbers).
Warnings
breaking In v1.12+, the 'ScoreClient' no longer accepts 'deployment_id' as a separate argument; you must include the full endpoint URL with deployment ID. Old code that passed deployment_id separately will break. ↓
fix Construct endpoint URL as 'https://app.datarobot.com/predApi/v1.0/deployments/{deployment_id}/predictions' and pass it as 'endpoint' parameter.
breaking In v1.10+, the default authentication method changed to use 'api_key' parameter. The old 'username' and 'password' parameters are deprecated and will raise an error if used. ↓
fix Use 'api_key' parameter instead of 'username' and 'password'.
gotcha The 'predict' method returns a 'PredictionResponse' object, not a dict. Access fields like 'response.predictions' or convert with 'response.json()'. ↓
fix Use 'response.json()' to get a dict or access attributes directly.
gotcha If you pass a single row as a list, the library might misinterpret it as multiple rows. Always wrap a single row in a list or use 'predict' for a single dict. ↓
fix For single prediction: client.predict(data={'feature1': 'value'}). For multiple: client.predict_batch([{'feature1': 'value1'}, ...])
Install
pip install datarobot-predict[examples] Imports
- ScoreClient wrong
from datarobot import ScoreClientcorrectfrom datarobot_predict import ScoreClient
Quickstart
from datarobot_predict import ScoreClient
client = ScoreClient(
endpoint='https://example.datarobot.com/predApi/v1.0/deployments/<deployment_id>/predictions',
api_key=os.environ.get('DATAROBOT_API_KEY', ''),
max_prediction_time=30
)
# Single prediction
response = client.predict(data={'feature1': 'value1', 'feature2': 123})
print(response)
# Batch predictions
batch_data = [{'feature1': 'a', 'feature2': 1}, {'feature1': 'b', 'feature2': 2}]
batch_response = client.predict_batch(batch_data)
print(batch_response)