diff --git a/pydomo/Transport.py b/pydomo/Transport.py index 7aa06b2..8418070 100644 --- a/pydomo/Transport.py +++ b/pydomo/Transport.py @@ -13,12 +13,13 @@ class DomoAPITransport: serialization and deserialization of objects. """ - def __init__(self, client_id, client_secret, api_host, use_https, logger): + def __init__(self, client_id, client_secret, api_host, use_https, logger, request_timeout): self.apiHost = self._build_apihost(api_host, use_https) self.clientId = client_id self.clientSecret = client_secret self.logger = logger self._renew_access_token() + self.request_timeout = request_timeout @staticmethod def _build_apihost(host, use_https): @@ -68,7 +69,8 @@ def request(self, url, method, headers, params=None, body=None): self.logger.debug('{} {} {}'.format(method, url, body)) request_args = {'method': method, 'url': url, 'headers': headers, 'params': params, 'data': body, 'stream': True} - + if self.request_timeout: + request_args['timeout'] = self.request_timeout response = requests.request(**request_args) if response.status_code == requests.codes.UNAUTHORIZED: self._renew_access_token() diff --git a/pydomo/__init__.py b/pydomo/__init__.py index 17ce197..1c34644 100644 --- a/pydomo/__init__.py +++ b/pydomo/__init__.py @@ -81,11 +81,13 @@ def __init__(self, client_id, client_secret, api_host='api.domo.com', **kwargs): else: self.logger = parent_logger + timeout = kwargs.get('request_timeout', None) + if kwargs.get('log_level'): self.logger.setLevel(kwargs['log_level']) self.logger.debug("\n" + DOMO + "\n") - self.transport = DomoAPITransport(client_id, client_secret, api_host, kwargs.get('use_https', True), self.logger) + self.transport = DomoAPITransport(client_id, client_secret, api_host, kwargs.get('use_https', True), self.logger, request_timeout = timeout) self.datasets = DataSetClient(self.transport, self.logger) self.groups = GroupClient(self.transport, self.logger) self.pages = PageClient(self.transport, self.logger) @@ -137,7 +139,7 @@ def ds_list(self, df_output = True, per_page=50, offset=0, limit=0): - `per_page`: results per page. Default 50 (int) - `offset`: offset if you need to paginate results. Default 0 (int) - `limit`: max ouput to return. If 0 then return all results on page. Default 0 (int) - + :Returns: list or pandas dataframe depending on parameters @@ -148,7 +150,7 @@ def ds_list(self, df_output = True, per_page=50, offset=0, limit=0): else: out = DataFrame(list(l)) return out - + def ds_query(self, dataset_id, query, return_data=True): """ Evaluate query and return dataset in a dataframe @@ -161,7 +163,7 @@ def ds_query(self, dataset_id, query, return_data=True): - `dataset_id`: id of a dataset (str) - `query`: query object (dict) - `return_data`: should the result be a dataframe. Default True (Boolean) - + :Returns: dict or pandas dataframe depending on parameters """ @@ -180,10 +182,10 @@ def ds_get(self, dataset_id): :Parameters: - `dataset_id`: id of a dataset (str) - + :Returns: pandas dataframe - """ + """ csv_download = self.datasets.data_export(dataset_id, include_csv_header=True) content = StringIO(csv_download) @@ -232,14 +234,14 @@ def pdp_create(self, dataset_id, pdp_request): , "not": false } ], "users": [ 27 ],"groups": [ ]} :Parameters: - - `dataset_id`: id of the dataset PDP will be applied to (String) Required + - `dataset_id`: id of the dataset PDP will be applied to (String) Required Policy Object: - `name`: Name of the Policy (String) Required - - `filters[].column`: Name of the column to filter on (String) Required + - `filters[].column`: Name of the column to filter on (String) Required - `filters[].not`: Determines if NOT is applied to the filter operation (Boolean) Required - - `filters[].operator`: Matching operator (EQUALS) (String) Required - - `filters[].values[]`: Values to filter on (String) Required - - `type`: Type of policy (user or system) (String) Required + - `filters[].operator`: Matching operator (EQUALS) (String) Required + - `filters[].values[]`: Values to filter on (String) Required + - `type`: Type of policy (user or system) (String) Required - `users`: List of user IDs the policy applies to (array) Required - `groups`: List of group IDs the policy applies to (array) Required """ @@ -252,7 +254,7 @@ def pdp_delete(self, dataset_id, policy_id): >>> domo.pdp_delete('4405ff58-1957-45f0-82bd-914d989a3ea3', 35) :Parameters: - - `dataset_id`: id of the dataset PDP will be applied to (String) Required + - `dataset_id`: id of the dataset PDP will be applied to (String) Required - `policy_id`: id of the policy to delete (String) Required """ return self.datasets.delete_pdp(dataset_id, policy_id) @@ -267,7 +269,7 @@ def pdp_list(self, dataset_id, df_output = True): :Parameters: - `dataset_id`: id of dataset with PDP policies (str) Required - `df_output`: should the result be a dataframe. Default True (Boolean) - + :Returns: list or pandas dataframe depending on parameters @@ -297,15 +299,15 @@ def pdp_update(self, dataset_id, policy_id, policy_update): , "not": false } ], "users": [ 27 ],"groups": [ ]} :Parameters: - - `dataset_id`: id of the dataset PDP will be applied to (String) Required - - `policy_id`: id of the PDP pollicy that will be updated (String) Required + - `dataset_id`: id of the dataset PDP will be applied to (String) Required + - `policy_id`: id of the PDP pollicy that will be updated (String) Required Policy Object: - `name`: Name of the Policy (String) Required - - `filters[].column`: Name of the column to filter on (String) Required + - `filters[].column`: Name of the column to filter on (String) Required - `filters[].not`: Determines if NOT is applied to the filter operation (Boolean) Required - - `filters[].operator`: Matching operator (EQUALS) (String) Required - - `filters[].values[]`: Values to filter on (String) Required - - `type`: Type of policy (user or system) (String) Required + - `filters[].operator`: Matching operator (EQUALS) (String) Required + - `filters[].values[]`: Values to filter on (String) Required + - `type`: Type of policy (user or system) (String) Required - `users`: List of user IDs the policy applies to (array) Required - `groups`: List of group IDs the policy applies to (array) Required """ @@ -600,7 +602,7 @@ def accounts_list(self): - `per_page`: results per page. Default 50 (int) - `offset`: offset if you need to paginate results. Default 0 (int) - `limit`: max ouput to return. If 0 then return all results on page. Default 0 (int) - + :returns: - A list of dicts (with nesting possible)