wherobots-python-sdk 0.2.1__py3-none-any.whl → 0.4.0__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.
- wherobots/__init__.py +4 -0
- wherobots/__version__.py +1 -1
- wherobots/api/base.py +17 -10
- wherobots/api/files.py +438 -244
- wherobots/api/runs.py +8 -8
- wherobots/client.py +121 -38
- wherobots/config.py +15 -4
- wherobots/exceptions.py +3 -3
- wherobots/models.py +149 -18
- wherobots/utils/client_header.py +205 -0
- wherobots/utils/validation.py +1 -1
- {wherobots_python_sdk-0.2.1.dist-info → wherobots_python_sdk-0.4.0.dist-info}/METADATA +132 -18
- wherobots_python_sdk-0.4.0.dist-info/RECORD +21 -0
- {wherobots_python_sdk-0.2.1.dist-info → wherobots_python_sdk-0.4.0.dist-info}/WHEEL +1 -1
- wherobots_python_sdk-0.2.1.dist-info/RECORD +0 -20
- {wherobots_python_sdk-0.2.1.dist-info → wherobots_python_sdk-0.4.0.dist-info}/licenses/LICENSE +0 -0
- {wherobots_python_sdk-0.2.1.dist-info → wherobots_python_sdk-0.4.0.dist-info}/top_level.txt +0 -0
wherobots/__init__.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Wherobots Python SDK (Jobs API surface)."""
|
|
2
2
|
|
|
3
3
|
from wherobots.__version__ import __version__
|
|
4
|
+
from wherobots.api.files import FilesAPI
|
|
4
5
|
from wherobots.client import WherobotsJob
|
|
5
6
|
from wherobots.config import WherobotsConfig
|
|
6
7
|
from wherobots.enums import (
|
|
@@ -39,6 +40,7 @@ from wherobots.models import (
|
|
|
39
40
|
RunPythonPayload,
|
|
40
41
|
RunView,
|
|
41
42
|
StorageIntegration,
|
|
43
|
+
TemporaryAwsCredentials,
|
|
42
44
|
UtilizationStats,
|
|
43
45
|
)
|
|
44
46
|
|
|
@@ -50,6 +52,7 @@ __all__ = [
|
|
|
50
52
|
# Client
|
|
51
53
|
"WherobotsJob",
|
|
52
54
|
"Job",
|
|
55
|
+
"FilesAPI",
|
|
53
56
|
"WherobotsConfig",
|
|
54
57
|
# Enums
|
|
55
58
|
"Runtime",
|
|
@@ -85,5 +88,6 @@ __all__ = [
|
|
|
85
88
|
"PyPiDependency",
|
|
86
89
|
"FileDependency",
|
|
87
90
|
"StorageIntegration",
|
|
91
|
+
"TemporaryAwsCredentials",
|
|
88
92
|
"UtilizationStats",
|
|
89
93
|
]
|
wherobots/__version__.py
CHANGED
wherobots/api/base.py
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
``BaseClient`` wraps a ``requests.Session`` with:
|
|
4
4
|
* Auth header construction (``X-API-Key``).
|
|
5
|
+
* Client attribution via the advisory ``X-Wherobots-Client`` header,
|
|
6
|
+
set once on the session so every outgoing request carries it.
|
|
5
7
|
* Automatic retry with exponential back-off for transient errors
|
|
6
8
|
(429 Too Many Requests, 503 Service Unavailable, connection errors).
|
|
7
9
|
* Unified error handling that maps HTTP failures into
|
|
@@ -11,15 +13,16 @@
|
|
|
11
13
|
from __future__ import annotations
|
|
12
14
|
|
|
13
15
|
import warnings
|
|
14
|
-
from typing import Any
|
|
16
|
+
from typing import Any # noqa: TID251
|
|
15
17
|
|
|
16
18
|
import requests
|
|
17
19
|
from requests.adapters import HTTPAdapter
|
|
18
20
|
from urllib3.util.retry import Retry
|
|
19
21
|
|
|
20
22
|
from wherobots.__version__ import __version__
|
|
21
|
-
from wherobots.config import WherobotsConfig
|
|
23
|
+
from wherobots.config import WherobotsConfig # noqa: TC001
|
|
22
24
|
from wherobots.exceptions import WherobotsAPIError, WherobotsConfigError
|
|
25
|
+
from wherobots.utils.client_header import CLIENT_HEADER, client_header_value
|
|
23
26
|
from wherobots.utils.logger import get_logger
|
|
24
27
|
|
|
25
28
|
logger = get_logger("api")
|
|
@@ -45,7 +48,7 @@ class BaseClient:
|
|
|
45
48
|
retries.
|
|
46
49
|
"""
|
|
47
50
|
|
|
48
|
-
def __init__(
|
|
51
|
+
def __init__( # noqa: D107
|
|
49
52
|
self,
|
|
50
53
|
config: WherobotsConfig,
|
|
51
54
|
max_retries: int = _DEFAULT_RETRIES,
|
|
@@ -94,11 +97,15 @@ class BaseClient:
|
|
|
94
97
|
# Intentionally not mounting on http:// — API keys must never
|
|
95
98
|
# be transmitted over plaintext HTTP.
|
|
96
99
|
|
|
97
|
-
# Common headers
|
|
100
|
+
# Common headers. ``X-Wherobots-Client`` is set here, on the
|
|
101
|
+
# session, so it rides along with every request this client makes
|
|
102
|
+
# instead of having to be threaded through each call site. Auth
|
|
103
|
+
# headers are merged last so nothing can displace them.
|
|
98
104
|
self._session.headers.update(
|
|
99
105
|
{
|
|
100
106
|
"Content-Type": "application/json",
|
|
101
107
|
"User-Agent": f"wherobots-python-sdk/{__version__}",
|
|
108
|
+
CLIENT_HEADER: client_header_value(config.client_chain),
|
|
102
109
|
**self._auth_headers(config.api_key),
|
|
103
110
|
}
|
|
104
111
|
)
|
|
@@ -154,7 +161,7 @@ class BaseClient:
|
|
|
154
161
|
timeout=self._timeout,
|
|
155
162
|
)
|
|
156
163
|
response.raise_for_status()
|
|
157
|
-
return response
|
|
164
|
+
return response # noqa: TRY300
|
|
158
165
|
except requests.HTTPError as exc:
|
|
159
166
|
response = exc.response
|
|
160
167
|
status_code = response.status_code if response is not None else None
|
|
@@ -224,15 +231,15 @@ class BaseClient:
|
|
|
224
231
|
self._session.close()
|
|
225
232
|
self._closed = True
|
|
226
233
|
|
|
227
|
-
def __enter__(self) -> BaseClient:
|
|
234
|
+
def __enter__(self) -> BaseClient: # noqa: PYI034
|
|
228
235
|
"""Enter the runtime context (context-manager protocol)."""
|
|
229
236
|
return self
|
|
230
237
|
|
|
231
|
-
def __exit__(self, *exc:
|
|
238
|
+
def __exit__(self, *exc: object) -> None:
|
|
232
239
|
"""Exit the runtime context, closing the session."""
|
|
233
240
|
self.close()
|
|
234
241
|
|
|
235
|
-
def __del__(self) -> None:
|
|
242
|
+
def __del__(self) -> None: # noqa: D105
|
|
236
243
|
# Mirror ``open()``/``socket``: warn callers who let the client
|
|
237
244
|
# get GC'd without closing it, so connection pools don't leak
|
|
238
245
|
# silently. Guarded against partial __init__ failure and
|
|
@@ -242,7 +249,7 @@ class BaseClient:
|
|
|
242
249
|
return
|
|
243
250
|
if getattr(self, "_session", None) is None:
|
|
244
251
|
return
|
|
245
|
-
except Exception:
|
|
252
|
+
except Exception: # noqa: BLE001
|
|
246
253
|
return
|
|
247
254
|
try:
|
|
248
255
|
warnings.warn(
|
|
@@ -252,5 +259,5 @@ class BaseClient:
|
|
|
252
259
|
stacklevel=2,
|
|
253
260
|
)
|
|
254
261
|
self._session.close()
|
|
255
|
-
except Exception:
|
|
262
|
+
except Exception: # noqa: BLE001, S110
|
|
256
263
|
pass
|