Client Configuration
- datarobot.client.Client(token=None, endpoint=None, config_path=None, connect_timeout=None, user_agent_suffix=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.
- Parameters:
- tokenstr, optional
API token.
- endpointstr, optional
Base URL of API.
- config_pathstr, optional
An alternate location of the config file.
- connect_timeoutint, optional
How long the client should be willing to wait before giving up on establishing a connection with the server.
- user_agent_suffixstr, optional
Additional text that is appended to the User-Agent HTTP header when communicating with the DataRobot REST API. This can be useful for identifying different applications that are built on top of the DataRobot Python Client, which can aid debugging and help track usage.
- ssl_verifybool or str, optional
Whether to check SSL certificate. Could be set to path with certificates of trusted certification authorities. Default: True.
- max_retriesint or urllib3.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: str, optional
Authentication token type: Token, Bearer. “Bearer” is for DataRobot OAuth2 token, “Token” for token generated in Developer Tools. Default: “Token”.
- default_use_case: str, optional
The entity ID of the default Use Case to use with any requests made by the client.
- enable_api_consumer_tracking: bool, optional
Enable and disable user metrics tracking within the datarobot module. Default: False.
- trace_context: str, optional
An ID or other string for identifying which code template or AI Accelerator was used to make a request.
- Returns:
- The
RESTClientObject
instance created.
- The
- Return type:
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.
- 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:
- argsParameters passed to
datarobot.client.Client()
- kwargsKeyword arguments passed to
datarobot.client.Client()
- argsParameters passed to
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()
- class datarobot.rest.RESTClientObject(auth, endpoint, connect_timeout=6.05, verify=True, user_agent_suffix=None, max_retries=None, authentication_type=None)
- Parameters
- connect_timeout
timeout for http request and connection
- headers
headers for outgoing requests
- open_in_browser()
Opens the DataRobot app in a web browser, or logs the URL if a browser is not available.
- Return type:
None