rapidata 2.19.0__py3-none-any.whl → 2.19.1__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.
Potentially problematic release.
This version of rapidata might be problematic. Click here for more details.
- rapidata/api_client/rest.py +94 -72
- {rapidata-2.19.0.dist-info → rapidata-2.19.1.dist-info}/METADATA +1 -1
- {rapidata-2.19.0.dist-info → rapidata-2.19.1.dist-info}/RECORD +5 -5
- {rapidata-2.19.0.dist-info → rapidata-2.19.1.dist-info}/LICENSE +0 -0
- {rapidata-2.19.0.dist-info → rapidata-2.19.1.dist-info}/WHEEL +0 -0
rapidata/api_client/rest.py
CHANGED
|
@@ -16,20 +16,19 @@ import json
|
|
|
16
16
|
import re
|
|
17
17
|
from typing import Dict, Optional
|
|
18
18
|
|
|
19
|
-
import
|
|
20
|
-
from authlib.integrations.
|
|
21
|
-
from
|
|
22
|
-
from urllib3 import Retry
|
|
19
|
+
import httpx
|
|
20
|
+
from authlib.integrations.httpx_client import OAuth2Client
|
|
21
|
+
from httpx import Timeout
|
|
23
22
|
|
|
24
23
|
from rapidata.api_client.exceptions import ApiException, ApiValueError
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
class RESTResponse(io.IOBase):
|
|
28
27
|
|
|
29
|
-
def __init__(self, resp:
|
|
28
|
+
def __init__(self, resp: httpx.Response) -> None:
|
|
30
29
|
self.response = resp
|
|
31
30
|
self.status = resp.status_code
|
|
32
|
-
self.reason = resp.
|
|
31
|
+
self.reason = resp.reason_phrase
|
|
33
32
|
self.data = None
|
|
34
33
|
|
|
35
34
|
def read(self):
|
|
@@ -54,43 +53,48 @@ class RESTClientObject:
|
|
|
54
53
|
def __init__(self, configuration) -> None:
|
|
55
54
|
self.configuration = configuration
|
|
56
55
|
|
|
57
|
-
self.session: Optional[
|
|
56
|
+
self.session: Optional[OAuth2Client] = None
|
|
58
57
|
|
|
59
58
|
def setup_oauth_client_credentials(
|
|
60
|
-
|
|
59
|
+
self, client_id: str, client_secret: str, token_endpoint: str, scope: str
|
|
61
60
|
):
|
|
62
|
-
|
|
61
|
+
client_args = self._get_session_defaults()
|
|
62
|
+
self.session = OAuth2Client(
|
|
63
63
|
client_id=client_id,
|
|
64
64
|
client_secret=client_secret,
|
|
65
65
|
token_endpoint=token_endpoint,
|
|
66
66
|
scope=scope,
|
|
67
|
+
**client_args,
|
|
67
68
|
)
|
|
68
|
-
|
|
69
|
+
|
|
69
70
|
self.session.fetch_token()
|
|
70
71
|
|
|
71
|
-
def setup_oauth_with_token(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
def setup_oauth_with_token(
|
|
73
|
+
self,
|
|
74
|
+
client_id: str | None,
|
|
75
|
+
client_secret: str | None,
|
|
76
|
+
token: dict,
|
|
77
|
+
token_endpoint: str,
|
|
78
|
+
leeway: int = 60,
|
|
79
|
+
):
|
|
80
|
+
client_args = self._get_session_defaults()
|
|
81
|
+
self.session = OAuth2Client(
|
|
78
82
|
token=token,
|
|
79
83
|
token_endpoint=token_endpoint,
|
|
80
84
|
client_id=client_id,
|
|
81
85
|
client_secret=client_secret,
|
|
82
86
|
leeway=leeway,
|
|
87
|
+
**client_args,
|
|
83
88
|
)
|
|
84
|
-
self._configure_session_defaults()
|
|
85
89
|
|
|
86
90
|
def request(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
self,
|
|
92
|
+
method,
|
|
93
|
+
url,
|
|
94
|
+
headers=None,
|
|
95
|
+
body=None,
|
|
96
|
+
post_params=None,
|
|
97
|
+
_request_timeout=None,
|
|
94
98
|
):
|
|
95
99
|
"""Perform requests.
|
|
96
100
|
|
|
@@ -127,9 +131,10 @@ class RESTClientObject:
|
|
|
127
131
|
timeout = None
|
|
128
132
|
if _request_timeout:
|
|
129
133
|
if isinstance(_request_timeout, (int, float)):
|
|
130
|
-
timeout = _request_timeout
|
|
134
|
+
timeout = Timeout(timeout=_request_timeout)
|
|
131
135
|
elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
|
|
132
|
-
|
|
136
|
+
connect_timeout, read_timeout = _request_timeout
|
|
137
|
+
timeout = Timeout(timeout=connect_timeout, read=read_timeout)
|
|
133
138
|
|
|
134
139
|
try:
|
|
135
140
|
if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
|
|
@@ -139,13 +144,21 @@ class RESTClientObject:
|
|
|
139
144
|
request_body = None
|
|
140
145
|
if body is not None:
|
|
141
146
|
request_body = json.dumps(body)
|
|
142
|
-
r = session.request(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
r = session.request(
|
|
148
|
+
method,
|
|
149
|
+
url,
|
|
150
|
+
content=request_body,
|
|
151
|
+
timeout=timeout,
|
|
152
|
+
headers=headers,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
elif content_type == "application/x-www-form-urlencoded":
|
|
156
|
+
r = session.request(
|
|
157
|
+
method, url, data=post_params, timeout=timeout, headers=headers
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
elif content_type == "multipart/form-data":
|
|
161
|
+
del headers["Content-Type"]
|
|
149
162
|
files = []
|
|
150
163
|
data = {}
|
|
151
164
|
|
|
@@ -173,59 +186,68 @@ class RESTClientObject:
|
|
|
173
186
|
data[key].append(value)
|
|
174
187
|
else:
|
|
175
188
|
data[key] = value
|
|
176
|
-
r = session.request(
|
|
189
|
+
r = session.request(
|
|
190
|
+
method,
|
|
191
|
+
url,
|
|
192
|
+
files=files,
|
|
193
|
+
data=data,
|
|
194
|
+
timeout=timeout,
|
|
195
|
+
headers=headers,
|
|
196
|
+
)
|
|
177
197
|
|
|
178
198
|
elif isinstance(body, str) or isinstance(body, bytes):
|
|
179
|
-
r = session.request(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
199
|
+
r = session.request(
|
|
200
|
+
method, url, content=body, timeout=timeout, headers=headers
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
elif headers["Content-Type"].startswith("text/") and isinstance(
|
|
204
|
+
body, bool
|
|
205
|
+
):
|
|
206
|
+
request_body = "true" if body else "false"
|
|
207
|
+
r = session.request(
|
|
208
|
+
method,
|
|
209
|
+
url,
|
|
210
|
+
content=request_body,
|
|
211
|
+
timeout=timeout,
|
|
212
|
+
headers=headers,
|
|
213
|
+
)
|
|
184
214
|
|
|
185
215
|
else:
|
|
186
|
-
msg =
|
|
187
|
-
Please check that your arguments match declared content type.
|
|
216
|
+
msg = """Cannot prepare a request message for provided arguments.
|
|
217
|
+
Please check that your arguments match declared content type."""
|
|
188
218
|
raise ApiException(status=0, reason=msg)
|
|
189
219
|
|
|
190
220
|
else:
|
|
191
|
-
r = session.request(
|
|
221
|
+
r = session.request(
|
|
222
|
+
method, url, params={}, timeout=timeout, headers=headers
|
|
223
|
+
)
|
|
192
224
|
|
|
193
|
-
except
|
|
194
|
-
msg =
|
|
225
|
+
except httpx.HTTPError as e:
|
|
226
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
|
195
227
|
raise ApiException(status=0, reason=msg)
|
|
196
228
|
|
|
197
229
|
return RESTResponse(r)
|
|
198
230
|
|
|
199
|
-
def
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if self.configuration.cert_file and self.configuration.key_file:
|
|
207
|
-
self.session.cert = (
|
|
208
|
-
self.configuration.cert_file,
|
|
209
|
-
self.configuration.key_file,
|
|
231
|
+
def _get_session_defaults(self):
|
|
232
|
+
client_kwargs = {
|
|
233
|
+
"verify": (
|
|
234
|
+
self.configuration.ssl_ca_cert
|
|
235
|
+
if self.configuration.ssl_ca_cert
|
|
236
|
+
else self.configuration.verify_ssl
|
|
210
237
|
)
|
|
211
|
-
|
|
212
|
-
if self.configuration.retries is not None:
|
|
213
|
-
retry = Retry(
|
|
214
|
-
total=self.configuration.retries,
|
|
215
|
-
backoff_factor=0.3,
|
|
216
|
-
status_forcelist=[429, 500, 502, 503, 504],
|
|
217
|
-
)
|
|
218
|
-
adapter = HTTPAdapter(max_retries=retry)
|
|
219
|
-
self.session.mount("https://", adapter)
|
|
220
|
-
# noinspection HttpUrlsUsage
|
|
221
|
-
self.session.mount("http://", adapter)
|
|
238
|
+
}
|
|
222
239
|
|
|
223
240
|
if self.configuration.proxy:
|
|
224
|
-
self.
|
|
225
|
-
"http": self.configuration.proxy,
|
|
226
|
-
"https": self.configuration.proxy,
|
|
227
|
-
}
|
|
241
|
+
client_kwargs["proxy"] = self.configuration.proxy
|
|
228
242
|
|
|
243
|
+
existing_headers = client_kwargs.pop("headers")
|
|
229
244
|
if self.configuration.proxy_headers:
|
|
230
245
|
for key, value in self.configuration.proxy_headers.items():
|
|
231
|
-
|
|
246
|
+
existing_headers[key] = value
|
|
247
|
+
client_kwargs["headers"] = existing_headers
|
|
248
|
+
|
|
249
|
+
if self.configuration.retries is not None:
|
|
250
|
+
transport = httpx.HTTPTransport(retries=self.configuration.retries)
|
|
251
|
+
client_kwargs["transport"] = transport
|
|
252
|
+
|
|
253
|
+
return client_kwargs
|
|
@@ -410,7 +410,7 @@ rapidata/api_client/models/workflow_labeling_step_model.py,sha256=iXeIb78bdMhGFj
|
|
|
410
410
|
rapidata/api_client/models/workflow_split_model.py,sha256=zthOSaUl8dbLhLymLK_lrPTBpeV1a4cODLxnHmNCAZw,4474
|
|
411
411
|
rapidata/api_client/models/workflow_split_model_filter_configs_inner.py,sha256=1Fx9uZtztiiAdMXkj7YeCqt7o6VkG9lKf7D7UP_h088,7447
|
|
412
412
|
rapidata/api_client/models/workflow_state.py,sha256=5LAK1se76RCoozeVB6oxMPb8p_5bhLZJqn7q5fFQWis,850
|
|
413
|
-
rapidata/api_client/rest.py,sha256=
|
|
413
|
+
rapidata/api_client/rest.py,sha256=VstzpXs6yvgJmgUL7pYlUDmSo_0W2krV5TiUqpSG_LI,9024
|
|
414
414
|
rapidata/api_client_README.md,sha256=WMuo7wBjQ5nVhYAt9kFrpdqa0Y7QU4rb5u3525g0dXU,54350
|
|
415
415
|
rapidata/rapidata_client/__init__.py,sha256=4Yg_2NvWhKusvcosuWzyrlJdjRnxXqNQUXDgyQrcNPQ,949
|
|
416
416
|
rapidata/rapidata_client/assets/__init__.py,sha256=hKgrOSn8gJcBSULaf4auYhH1S1N5AfcwIhBSq1BOKwQ,323
|
|
@@ -499,7 +499,7 @@ rapidata/service/__init__.py,sha256=s9bS1AJZaWIhLtJX_ZA40_CK39rAAkwdAmymTMbeWl4,
|
|
|
499
499
|
rapidata/service/credential_manager.py,sha256=3x-Fb6tyqmgtpjI1MSOtXWW_SkzTK8Lo7I0SSL2YD7E,8602
|
|
500
500
|
rapidata/service/local_file_service.py,sha256=pgorvlWcx52Uh3cEG6VrdMK_t__7dacQ_5AnfY14BW8,877
|
|
501
501
|
rapidata/service/openapi_service.py,sha256=ORFPfHlb41zOUP5nDjYWZwO-ZcqNF_Mw2r71RitFtS0,4042
|
|
502
|
-
rapidata-2.19.
|
|
503
|
-
rapidata-2.19.
|
|
504
|
-
rapidata-2.19.
|
|
505
|
-
rapidata-2.19.
|
|
502
|
+
rapidata-2.19.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
503
|
+
rapidata-2.19.1.dist-info/METADATA,sha256=5G2VtmFWXfQ9pFbaHJeElX_VxYVLrkaYmc3xB-gNwyc,1187
|
|
504
|
+
rapidata-2.19.1.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
505
|
+
rapidata-2.19.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|