Client configuration
- datarobot.client.Client(token=None, endpoint=None, config_path=None, connect_timeout=None, ssl_verify=None, max_retries=None, token_type=None, default_use_case=None, enable_api_consumer_tracking=None, trace_context=None)
Configures the global API client for the Python SDK. The client will be configured in one of the following ways, in order of priority.
Notes
Token and endpoint must be specified from one source only. This is a restriction to prevent token leakage if environment variables or config file are used.
The DataRobotClientConfig params will be looking up to find the configuration parameters in one of the following ways,
From call kwargs if specified;
From a YAML file at the path specified in the
config_path
kwarg;From a YAML file at the path specified in the environment variables
DATAROBOT_CONFIG_FILE
;From environment variables;
From the default values in the default YAML file at the path $HOME/.config/datarobot/drconfig.yaml.
This can also have the side effect of setting a default Use Case for client API requests.
- Parameters:
token (
Optional[str]
) – API token.endpoint (
Optional[str]
) – Base URL of API.config_path (
Optional[str]
) – An alternate location of the config file.connect_timeout (
Optional[int]
) – How long the client should be willing to wait before giving up on establishing a connection with the server.ssl_verify (
bool
orOptional[str]
) – Whether to check SSL certificate. Could be set to path with certificates of trusted certification authorities. Default: True.max_retries (
int
orurllib3.util.retry.Retry
, optional) – Either an integer number of times to retry connection errors, or a urllib3.util.retry.Retry object to configure retries.token_type (
Optional[str]
) – Authentication token type: Token, Bearer. “Bearer” is for DataRobot OAuth2 token, “Token” for token generated in Developer Tools. Default: “Token”.default_use_case (
Optional[str]
) – The entity ID of the default Use Case to use with any requests made by the client.enable_api_consumer_tracking (
Optional[bool]
) – Enable and disable user metrics tracking within the datarobot module. Default: False.trace_context (
Optional[str]
) – An ID or other string for identifying which code template or AI Accelerator was used to make a request.
- Return type:
- Returns:
The
RESTClientObject
instance created.
- datarobot.client.get_client()
Returns the global HTTP client for the Python SDK, instantiating it if necessary.
- Return type:
- datarobot.client.set_client(client)
Configure the global HTTP client for the Python SDK. Returns previous instance.
- Return type:
Optional
[RESTClientObject
]
- datarobot.client.client_configuration(*args, **kwargs)
This context manager can be used to temporarily change the global HTTP client.
In multithreaded scenarios, it is highly recommended to use a fresh manager object per thread.
DataRobot does not recommend nesting these contexts.
- Parameters:
args (
Parameters passed
todatarobot.client.Client()
)kwargs (
Keyword arguments passed
todatarobot.client.Client()
)
Examples
from datarobot.client import client_configuration from datarobot.models import Project with client_configuration(default_use_case=[]): # Interact with all accessible projects, not just those associated # with the current use case. Project.list() with client_configuration(token="api-key-here", endpoint="https://host-name.com"): # Interact with projects on a different DataRobot instance. Project.list()
from datarobot.client import Client, client_configuration from datarobot.models import Project Client() # Interact with DataRobot using the default configuration. Project.list() with client_configuration(config_path="/path/to/a/drconfig.yaml"): # Interact with DataRobot using a different configuration. Project.list()