ga-api-client 0.2.13__tar.gz → 0.2.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ga-api-client
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: License :: OSI Approved :: MIT License
6
6
  Classifier: Operating System :: OS Independent
7
7
  Requires-Python: >=3.9
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
+ Requires-Dist: pandas>=1.4
11
+ Requires-Dist: aiohttp>=3.8
12
+ Requires-Dist: cryptography>=36.0
10
13
 
11
14
  # GenieAnalytics Python Client
12
15
 
@@ -8,11 +8,12 @@ import getpass
8
8
  import json
9
9
  import logging
10
10
  import math
11
+ import http
11
12
  from async_timeout import timeout
12
13
  from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes # 36.0.0
13
14
  import aiohttp # 3.8.1
14
15
  import pandas as pd # 1.4.2
15
- from .hyper_log_log import HyperLogLog
16
+ from hyper_log_log import HyperLogLog
16
17
 
17
18
  def _logtime(ts):
18
19
  return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(ts))
@@ -80,7 +81,7 @@ class UnexpectedStatus(Exception):
80
81
  ACCESS_TOKEN_TIMEOUT = 86400 / 2
81
82
 
82
83
  class Client:
83
- def __init__(self, url, user, tenant, password, ssl=True, burst=1, retry=0):
84
+ def __init__(self, url, user, tenant, password, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300):
84
85
  self.url = url # base url
85
86
  self.user = user # user name
86
87
  self.tenant = tenant # tenant name
@@ -93,8 +94,8 @@ class Client:
93
94
  }
94
95
  self._last_auth = 0 # timestamp of last authenticate in seconds since Eopch
95
96
  self._session = aiohttp.ClientSession(trust_env=True)
96
- # timetout
97
- self.timeout = aiohttp.ClientTimeout(total=None, connect=None, sock_connect=30, sock_read=120)
97
+ # self._session = aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(force_close=True))
98
+ self.timeout = aiohttp.ClientTimeout(total=None, connect=None, sock_connect=conn_timeout, sock_read=read_timeout)
98
99
 
99
100
  async def _authenticate(self):
100
101
  authData = {
@@ -161,11 +162,12 @@ class Client:
161
162
  retry_count += 1
162
163
  logging.warning(f'retry {retry_count}-th time')
163
164
  else:
164
- logging.error(f'authentication fail {e.message}')
165
+ logging.error(f'authentication fail {e}')
165
166
  raise e
166
167
  # send the request
167
168
  retry_count = 0
168
169
  async with self._sem:
170
+ ts_req = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
169
171
  while True:
170
172
  try:
171
173
  # logging.debug(f'{method} {path}')
@@ -173,36 +175,39 @@ class Client:
173
175
  if resp.status in code: # expected status code
174
176
  rlt = None
175
177
  if resp.content_type == 'application/json':
178
+ ts_head = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
176
179
  data = await resp.json()
180
+ ts_done = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
177
181
  if 'rlt' in data:
178
182
  rlt = data['rlt']
183
+ logging.debug(f'transfer req={ts_req} head={ts_head} data={ts_done}')
179
184
  return resp.status, rlt
180
185
  elif resp.status == 202: # API server asks for retry
181
186
  text = await resp.text()
182
- logging.debug(f'status={resp.status} message={text}')
187
+ logging.debug(f'status={resp.status} message={text} path={path}')
183
188
  continue
184
189
  elif resp.status == 500: # General error contain retry information
185
190
  text = await resp.text()
186
191
  if 'Warning' in text or 'Please try again' in text:
187
- logging.debug(f'status={resp.status} message={text}')
192
+ logging.debug(f'status={resp.status} message={text} path={path}')
188
193
  continue
189
194
  else:
190
- logging.error(f'unexpected status={resp.status} message={text}')
195
+ logging.error(f'unexpected status={resp.status} message={text} path={path}')
191
196
  raise UnexpectedStatus(resp.status, text)
192
197
  else:
193
198
  text = await resp.text()
194
- logging.error(f'unexpected status={resp.status} message={text}')
199
+ logging.error(f'unexpected status={resp.status} message={text} path={path}')
195
200
  raise UnexpectedStatus(resp.status, text)
196
201
  except aiohttp.ClientError as e:
197
202
  if retry_count < self.retry: # user asks for retry
198
203
  retry_count += 1
199
- logging.warning(f'{method} {path}, retry {retry_count}')
204
+ logging.error(f'{method} {path} - {e}, retry {retry_count}')
200
205
  else:
201
- logging.error(f'{method} {path} fail {e.message}')
206
+ logging.error(f'{method} {path} - {e}, fail')
202
207
  raise e
203
208
 
204
209
  class System(Client):
205
- def __init__(self, url, user=None, password=None, ssl=True, retry=0):
210
+ def __init__(self, url, user=None, password=None, ssl=True, retry=0, conn_timeout=30, read_timeout=300):
206
211
  """Construct object to send system requests.
207
212
 
208
213
  Args:
@@ -216,7 +221,7 @@ class System(Client):
216
221
  user = input('User:')
217
222
  if password is None:
218
223
  password = getpass.getpass('Password:')
219
- super().__init__(url, user, 'system', password, ssl=ssl, retry=retry)
224
+ super().__init__(url, user, 'system', password, ssl=ssl, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout)
220
225
 
221
226
  async def close(self):
222
227
  """Close the underlying connections gracefully. If the event loop is stopped before
@@ -351,14 +356,14 @@ def desc_dataframe(desc_list):
351
356
  return pd.DataFrame.from_dict(desc_dict, orient='index')
352
357
 
353
358
  class Tenant(Client):
354
- def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0):
359
+ def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300):
355
360
  if user is None:
356
361
  user = input('User:')
357
362
  if tenant is None:
358
363
  tenant = input('Tenant:')
359
364
  if password is None:
360
365
  password = getpass.getpass('Password:')
361
- super().__init__(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry)
366
+ super().__init__(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout)
362
367
 
363
368
  async def close(self):
364
369
  """Close the underlying connections gracefully. If the event loop is stopped before
@@ -832,7 +837,7 @@ class Dataset:
832
837
  next_ts += delta
833
838
 
834
839
  class Repository:
835
- def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0):
840
+ def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300):
836
841
  """Construct repository object to send tenant requests to API server
837
842
 
838
843
  Args:
@@ -844,7 +849,7 @@ class Repository:
844
849
  burst: Maximum concurrent requests to the API server.
845
850
  retry: Number of retry at fail of sending request.
846
851
  """
847
- self._tenant = Tenant(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry)
852
+ self._tenant = Tenant(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout)
848
853
 
849
854
  async def close(self):
850
855
  """Close the underlying connections gracefully. If the event loop is stopped before
@@ -1,12 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ga-api-client
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: License :: OSI Approved :: MIT License
6
6
  Classifier: Operating System :: OS Independent
7
7
  Requires-Python: >=3.9
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
+ Requires-Dist: pandas>=1.4
11
+ Requires-Dist: aiohttp>=3.8
12
+ Requires-Dist: cryptography>=36.0
10
13
 
11
14
  # GenieAnalytics Python Client
12
15
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = ga-api-client
3
- version = 0.2.13
3
+ version = 0.2.15
4
4
  long_description = file: README.md
5
5
  long_description_content_type = text/markdown
6
6
  classifiers =
File without changes
File without changes
File without changes