arkindex-client 1.0.15__py3-none-any.whl → 1.0.16__py3-none-any.whl
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.
- arkindex/client.py +40 -1
- arkindex/pagination.py +1 -1
- {arkindex_client-1.0.15.dist-info → arkindex_client-1.0.16.dist-info}/METADATA +2 -1
- {arkindex_client-1.0.15.dist-info → arkindex_client-1.0.16.dist-info}/RECORD +6 -6
- {arkindex_client-1.0.15.dist-info → arkindex_client-1.0.16.dist-info}/WHEEL +0 -0
- {arkindex_client-1.0.15.dist-info → arkindex_client-1.0.16.dist-info}/top_level.txt +0 -0
arkindex/client.py
CHANGED
|
@@ -11,6 +11,14 @@ from urllib.parse import urljoin, urlsplit, urlunsplit
|
|
|
11
11
|
import apistar
|
|
12
12
|
import requests
|
|
13
13
|
import yaml
|
|
14
|
+
from apistar.exceptions import ErrorResponse
|
|
15
|
+
from tenacity import (
|
|
16
|
+
before_sleep_log,
|
|
17
|
+
retry,
|
|
18
|
+
retry_if_exception,
|
|
19
|
+
stop_after_attempt,
|
|
20
|
+
wait_exponential,
|
|
21
|
+
)
|
|
14
22
|
|
|
15
23
|
from arkindex.auth import TokenSessionAuthentication
|
|
16
24
|
from arkindex.exceptions import SchemaError
|
|
@@ -27,6 +35,17 @@ SCHEMA_ENDPOINT = "/api/v1/openapi/?format=json"
|
|
|
27
35
|
logger = logging.getLogger(__name__)
|
|
28
36
|
|
|
29
37
|
|
|
38
|
+
def _is_500_error(exc: Exception) -> bool:
|
|
39
|
+
"""
|
|
40
|
+
Check if an Arkindex API error is a 50x
|
|
41
|
+
This is used to retry most API calls implemented here
|
|
42
|
+
"""
|
|
43
|
+
if not isinstance(exc, ErrorResponse):
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
return 500 <= exc.status_code < 600
|
|
47
|
+
|
|
48
|
+
|
|
30
49
|
def options_from_env():
|
|
31
50
|
"""
|
|
32
51
|
Get API client keyword arguments from environment variables.
|
|
@@ -245,7 +264,7 @@ class ArkindexClient(apistar.Client):
|
|
|
245
264
|
self.transport.session.auth.token = resp["auth_token"]
|
|
246
265
|
return resp
|
|
247
266
|
|
|
248
|
-
def
|
|
267
|
+
def single_request(self, operation_id, *args, **kwargs):
|
|
249
268
|
"""
|
|
250
269
|
Perform an API request.
|
|
251
270
|
:param args: Arguments passed to the APIStar client.
|
|
@@ -274,3 +293,23 @@ class ArkindexClient(apistar.Client):
|
|
|
274
293
|
)
|
|
275
294
|
sleep(self.sleep_duration)
|
|
276
295
|
return super().request(operation_id, *args, **kwargs)
|
|
296
|
+
|
|
297
|
+
@retry(
|
|
298
|
+
retry=retry_if_exception(_is_500_error),
|
|
299
|
+
wait=wait_exponential(multiplier=2, min=3),
|
|
300
|
+
reraise=True,
|
|
301
|
+
stop=stop_after_attempt(5),
|
|
302
|
+
before_sleep=before_sleep_log(logger, logging.INFO),
|
|
303
|
+
)
|
|
304
|
+
def request(self, operation_id, *args, **kwargs):
|
|
305
|
+
"""
|
|
306
|
+
Proxy all Arkindex API requests with a retry mechanism in case of 50X errors.
|
|
307
|
+
The same API call will be retried 5 times, with an exponential sleep time
|
|
308
|
+
going through 3, 4, 8 and 16 seconds of wait between call.
|
|
309
|
+
If the 5th call still gives a 50x, the exception is re-raised and the caller should catch it.
|
|
310
|
+
Log messages are displayed before sleeping (when at least one exception occurred).
|
|
311
|
+
|
|
312
|
+
:param args: Arguments passed to the APIStar client.
|
|
313
|
+
:param kwargs: Keyword arguments passed to the APIStar client.
|
|
314
|
+
"""
|
|
315
|
+
return self.single_request(operation_id, *args, **kwargs)
|
arkindex/pagination.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: arkindex-client
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.16
|
|
4
4
|
Summary: API client for the Arkindex project
|
|
5
5
|
Home-page: https://gitlab.teklia.com/arkindex/api-client
|
|
6
6
|
Author: Teklia <contact@teklia.com>
|
|
@@ -21,6 +21,7 @@ Requires-Python: >=3.7
|
|
|
21
21
|
Description-Content-Type: text/x-rst
|
|
22
22
|
Requires-Dist: apistar ==0.7.2
|
|
23
23
|
Requires-Dist: requests ~=2.28
|
|
24
|
+
Requires-Dist: tenacity ==8.2.3
|
|
24
25
|
Requires-Dist: typesystem ==0.2.5
|
|
25
26
|
|
|
26
27
|
Arkindex API Client
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
arkindex/__init__.py,sha256=OBw25Nwe6r1AN3a36-8lnUcDy3nkDIiebBgYNK2Zo9o,99
|
|
2
2
|
arkindex/auth.py,sha256=O45HgpsblBqNJr9nRALU14wZgCGcmCgcGjAoD0zAyrg,1073
|
|
3
|
-
arkindex/client.py,sha256=
|
|
3
|
+
arkindex/client.py,sha256=SLFJzZI31y3UAufyUBdDiUgh7_IwRK0ItRwOSgCZflU,11984
|
|
4
4
|
arkindex/exceptions.py,sha256=3jzuuXgsPA28qH7GMwPVQisWCvitAQtYiQ5uKxzFQ_M,155
|
|
5
5
|
arkindex/mock.py,sha256=hWU8EKfvVBAQ8VVI4Rgic809GLLDoh8Nvuvih54luKQ,2762
|
|
6
|
-
arkindex/pagination.py,sha256=
|
|
6
|
+
arkindex/pagination.py,sha256=tIt3ecD44UcuxT3mV7gtwvqoqdeAICaq5okr1z4_xgo,8954
|
|
7
7
|
arkindex/transports.py,sha256=RmQ9fXdnLd6PizifyVI5E7QTIj3MU6Xua76jp87TKpM,464
|
|
8
|
-
arkindex_client-1.0.
|
|
9
|
-
arkindex_client-1.0.
|
|
10
|
-
arkindex_client-1.0.
|
|
11
|
-
arkindex_client-1.0.
|
|
8
|
+
arkindex_client-1.0.16.dist-info/METADATA,sha256=noYxsy3dMHgo0Ob_bmU3qT0c_KBAap7hW6CDz-AuEIE,7059
|
|
9
|
+
arkindex_client-1.0.16.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
10
|
+
arkindex_client-1.0.16.dist-info/top_level.txt,sha256=iP1TxDW_jSDQA4FIcahBFXiDcZXqam2a_gFVnDbR3c4,9
|
|
11
|
+
arkindex_client-1.0.16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|