scalebox-sdk 0.1.24__py3-none-any.whl → 1.0.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.
Files changed (87) hide show
  1. scalebox/__init__.py +2 -2
  2. scalebox/api/__init__.py +130 -128
  3. scalebox/api/client/__init__.py +8 -8
  4. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +2 -2
  5. scalebox/api/client/api/sandboxes/post_sandboxes.py +2 -2
  6. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_connect.py +193 -0
  7. scalebox/api/client/client.py +288 -288
  8. scalebox/api/client/models/connect_sandbox.py +59 -0
  9. scalebox/api/client/models/error.py +2 -2
  10. scalebox/api/client/models/listed_sandbox.py +19 -1
  11. scalebox/api/client/models/new_sandbox.py +10 -0
  12. scalebox/api/client/models/sandbox.py +138 -125
  13. scalebox/api/client/models/sandbox_detail.py +24 -0
  14. scalebox/api/client/types.py +46 -46
  15. scalebox/cli.py +125 -125
  16. scalebox/client/aclient.py +57 -57
  17. scalebox/client/client.py +102 -102
  18. scalebox/code_interpreter/__init__.py +12 -12
  19. scalebox/code_interpreter/charts.py +230 -230
  20. scalebox/code_interpreter/constants.py +3 -3
  21. scalebox/code_interpreter/exceptions.py +13 -13
  22. scalebox/code_interpreter/models.py +485 -485
  23. scalebox/connection_config.py +34 -1
  24. scalebox/csx_connect/__init__.py +1 -1
  25. scalebox/csx_connect/client.py +485 -485
  26. scalebox/csx_desktop/main.py +651 -651
  27. scalebox/exceptions.py +83 -83
  28. scalebox/generated/api.py +61 -61
  29. scalebox/generated/api_pb2.py +203 -203
  30. scalebox/generated/api_pb2.pyi +956 -956
  31. scalebox/generated/api_pb2_connect.py +1407 -1407
  32. scalebox/generated/rpc.py +50 -50
  33. scalebox/sandbox/main.py +146 -139
  34. scalebox/sandbox/sandbox_api.py +105 -91
  35. scalebox/sandbox/signature.py +40 -40
  36. scalebox/sandbox/utils.py +34 -34
  37. scalebox/sandbox_async/commands/command.py +307 -307
  38. scalebox/sandbox_async/commands/command_handle.py +187 -187
  39. scalebox/sandbox_async/commands/pty.py +187 -187
  40. scalebox/sandbox_async/filesystem/filesystem.py +557 -557
  41. scalebox/sandbox_async/filesystem/watch_handle.py +61 -61
  42. scalebox/sandbox_async/main.py +228 -46
  43. scalebox/sandbox_async/sandbox_api.py +124 -3
  44. scalebox/sandbox_async/utils.py +7 -7
  45. scalebox/sandbox_sync/__init__.py +2 -2
  46. scalebox/sandbox_sync/commands/command.py +300 -300
  47. scalebox/sandbox_sync/commands/command_handle.py +150 -150
  48. scalebox/sandbox_sync/commands/pty.py +181 -181
  49. scalebox/sandbox_sync/filesystem/filesystem.py +3 -3
  50. scalebox/sandbox_sync/filesystem/watch_handle.py +66 -66
  51. scalebox/sandbox_sync/main.py +208 -133
  52. scalebox/sandbox_sync/sandbox_api.py +119 -3
  53. scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -323
  54. scalebox/test/README.md +329 -329
  55. scalebox/test/bedrock_openai_adapter.py +67 -0
  56. scalebox/test/code_interpreter_test.py +34 -34
  57. scalebox/test/code_interpreter_test_sync.py +34 -34
  58. scalebox/test/run_stress_code_interpreter_sync.py +166 -0
  59. scalebox/test/simple_upload_example.py +123 -0
  60. scalebox/test/stabitiy_test.py +310 -0
  61. scalebox/test/test_browser_use.py +25 -0
  62. scalebox/test/test_browser_use_scalebox.py +61 -0
  63. scalebox/test/test_code_interpreter_sync_comprehensive.py +115 -65
  64. scalebox/test/test_connect_pause_async.py +277 -0
  65. scalebox/test/test_connect_pause_sync.py +267 -0
  66. scalebox/test/test_desktop_sandbox_sf.py +117 -0
  67. scalebox/test/test_download_url.py +49 -0
  68. scalebox/test/test_sandbox_async_comprehensive.py +1 -1
  69. scalebox/test/test_sandbox_object_storage_example.py +146 -0
  70. scalebox/test/test_sandbox_object_storage_example_async.py +156 -0
  71. scalebox/test/test_sf.py +137 -0
  72. scalebox/test/test_watch_dir_async.py +56 -0
  73. scalebox/test/testacreate.py +1 -1
  74. scalebox/test/testagetinfo.py +1 -1
  75. scalebox/test/testcomputeuse.py +243 -243
  76. scalebox/test/testsandbox_api.py +13 -0
  77. scalebox/test/testsandbox_sync.py +1 -1
  78. scalebox/test/upload_100mb_example.py +355 -0
  79. scalebox/utils/httpcoreclient.py +297 -297
  80. scalebox/utils/httpxclient.py +403 -403
  81. scalebox/version.py +2 -2
  82. {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/METADATA +1 -1
  83. {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/RECORD +87 -69
  84. {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/WHEEL +1 -1
  85. {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/entry_points.txt +0 -0
  86. {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/licenses/LICENSE +0 -0
  87. {scalebox_sdk-0.1.24.dist-info → scalebox_sdk-1.0.1.dist-info}/top_level.txt +0 -0
@@ -1,288 +1,288 @@
1
- from __future__ import annotations
2
-
3
- import ssl
4
- from typing import Any, Dict, Optional, Union
5
-
6
- import httpx
7
- from attrs import define, evolve, field
8
-
9
-
10
- @define
11
- class Client:
12
- """A class for keeping track of data related to the API
13
-
14
- The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
15
-
16
- ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
17
-
18
- ``cookies``: A dictionary of cookies to be sent with every request
19
-
20
- ``headers``: A dictionary of headers to be sent with every request
21
-
22
- ``timeout``: The maximum amount of a time a request can take. API functions will raise
23
- httpx.TimeoutException if this is exceeded.
24
-
25
- ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
26
- but can be set to False for testing purposes.
27
-
28
- ``follow_redirects``: Whether or not to follow redirects. Default value is False.
29
-
30
- ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
31
-
32
-
33
- Attributes:
34
- raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
35
- status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
36
- argument to the constructor.
37
- """
38
-
39
- raise_on_unexpected_status: bool = field(default=False, kw_only=True)
40
- _base_url: str = field(alias="base_url")
41
- _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
42
- _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
43
- _timeout: Optional[httpx.Timeout] = field(
44
- default=None, kw_only=True, alias="timeout"
45
- )
46
- _verify_ssl: Union[str, bool, ssl.SSLContext] = field(
47
- default=True, kw_only=True, alias="verify_ssl"
48
- )
49
- _follow_redirects: bool = field(
50
- default=False, kw_only=True, alias="follow_redirects"
51
- )
52
- _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
53
- _client: Optional[httpx.Client] = field(default=None, init=False)
54
- _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
55
-
56
- def with_headers(self, headers: Dict[str, str]) -> "Client":
57
- """Get a new client matching this one with additional headers"""
58
- if self._client is not None:
59
- self._client.headers.update(headers)
60
- if self._async_client is not None:
61
- self._async_client.headers.update(headers)
62
- return evolve(self, headers={**self._headers, **headers})
63
-
64
- def with_cookies(self, cookies: Dict[str, str]) -> "Client":
65
- """Get a new client matching this one with additional cookies"""
66
- if self._client is not None:
67
- self._client.cookies.update(cookies)
68
- if self._async_client is not None:
69
- self._async_client.cookies.update(cookies)
70
- return evolve(self, cookies={**self._cookies, **cookies})
71
-
72
- def with_timeout(self, timeout: httpx.Timeout) -> "Client":
73
- """Get a new client matching this one with a new timeout (in seconds)"""
74
- if self._client is not None:
75
- self._client.timeout = timeout
76
- if self._async_client is not None:
77
- self._async_client.timeout = timeout
78
- return evolve(self, timeout=timeout)
79
-
80
- def set_httpx_client(self, client: httpx.Client) -> "Client":
81
- """Manually set the underlying httpx.Client
82
-
83
- **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
84
- """
85
- self._client = client
86
- return self
87
-
88
- def get_httpx_client(self) -> httpx.Client:
89
- """Get the underlying httpx.Client, constructing a new one if not previously set"""
90
- if self._client is None:
91
- self._client = httpx.Client(
92
- base_url=self._base_url,
93
- cookies=self._cookies,
94
- headers=self._headers,
95
- timeout=self._timeout,
96
- verify=self._verify_ssl,
97
- follow_redirects=self._follow_redirects,
98
- **self._httpx_args,
99
- )
100
- return self._client
101
-
102
- def __enter__(self) -> "Client":
103
- """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
104
- self.get_httpx_client().__enter__()
105
- return self
106
-
107
- def __exit__(self, *args: Any, **kwargs: Any) -> None:
108
- """Exit a context manager for internal httpx.Client (see httpx docs)"""
109
- self.get_httpx_client().__exit__(*args, **kwargs)
110
-
111
- def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
112
- """Manually the underlying httpx.AsyncClient
113
-
114
- **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
115
- """
116
- self._async_client = async_client
117
- return self
118
-
119
- def get_async_httpx_client(self) -> httpx.AsyncClient:
120
- """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
121
- if self._async_client is None:
122
- self._async_client = httpx.AsyncClient(
123
- base_url=self._base_url,
124
- cookies=self._cookies,
125
- headers=self._headers,
126
- timeout=self._timeout,
127
- verify=self._verify_ssl,
128
- follow_redirects=self._follow_redirects,
129
- **self._httpx_args,
130
- )
131
- return self._async_client
132
-
133
- async def __aenter__(self) -> "Client":
134
- """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
135
- await self.get_async_httpx_client().__aenter__()
136
- return self
137
-
138
- async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
139
- """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
140
- await self.get_async_httpx_client().__aexit__(*args, **kwargs)
141
-
142
-
143
- @define
144
- class AuthenticatedClient:
145
- """A Client which has been authenticated for use on secured endpoints
146
-
147
- The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
148
-
149
- ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
150
-
151
- ``cookies``: A dictionary of cookies to be sent with every request
152
-
153
- ``headers``: A dictionary of headers to be sent with every request
154
-
155
- ``timeout``: The maximum amount of a time a request can take. API functions will raise
156
- httpx.TimeoutException if this is exceeded.
157
-
158
- ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
159
- but can be set to False for testing purposes.
160
-
161
- ``follow_redirects``: Whether or not to follow redirects. Default value is False.
162
-
163
- ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
164
-
165
-
166
- Attributes:
167
- raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
168
- status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
169
- argument to the constructor.
170
- token: The token to use for authentication
171
- prefix: The prefix to use for the Authorization header
172
- auth_header_name: The name of the Authorization header
173
- """
174
-
175
- raise_on_unexpected_status: bool = field(default=False, kw_only=True)
176
- _base_url: str = field(alias="base_url")
177
- _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
178
- _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
179
- _timeout: Optional[httpx.Timeout] = field(
180
- default=None, kw_only=True, alias="timeout"
181
- )
182
- _verify_ssl: Union[str, bool, ssl.SSLContext] = field(
183
- default=True, kw_only=True, alias="verify_ssl"
184
- )
185
- _follow_redirects: bool = field(
186
- default=False, kw_only=True, alias="follow_redirects"
187
- )
188
- _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
189
- _client: Optional[httpx.Client] = field(default=None, init=False)
190
- _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
191
-
192
- token: str
193
- prefix: str = "Bearer"
194
- auth_header_name: str = "Authorization"
195
-
196
- def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient":
197
- """Get a new client matching this one with additional headers"""
198
- if self._client is not None:
199
- self._client.headers.update(headers)
200
- if self._async_client is not None:
201
- self._async_client.headers.update(headers)
202
- return evolve(self, headers={**self._headers, **headers})
203
-
204
- def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient":
205
- """Get a new client matching this one with additional cookies"""
206
- if self._client is not None:
207
- self._client.cookies.update(cookies)
208
- if self._async_client is not None:
209
- self._async_client.cookies.update(cookies)
210
- return evolve(self, cookies={**self._cookies, **cookies})
211
-
212
- def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
213
- """Get a new client matching this one with a new timeout (in seconds)"""
214
- if self._client is not None:
215
- self._client.timeout = timeout
216
- if self._async_client is not None:
217
- self._async_client.timeout = timeout
218
- return evolve(self, timeout=timeout)
219
-
220
- def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
221
- """Manually set the underlying httpx.Client
222
-
223
- **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
224
- """
225
- self._client = client
226
- return self
227
-
228
- def get_httpx_client(self) -> httpx.Client:
229
- """Get the underlying httpx.Client, constructing a new one if not previously set"""
230
- if self._client is None:
231
- self._headers[self.auth_header_name] = (
232
- f"{self.prefix} {self.token}" if self.prefix else self.token
233
- )
234
- self._client = httpx.Client(
235
- base_url=self._base_url,
236
- cookies=self._cookies,
237
- headers=self._headers,
238
- timeout=self._timeout,
239
- verify=self._verify_ssl,
240
- follow_redirects=self._follow_redirects,
241
- **self._httpx_args,
242
- )
243
- return self._client
244
-
245
- def __enter__(self) -> "AuthenticatedClient":
246
- """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
247
- self.get_httpx_client().__enter__()
248
- return self
249
-
250
- def __exit__(self, *args: Any, **kwargs: Any) -> None:
251
- """Exit a context manager for internal httpx.Client (see httpx docs)"""
252
- self.get_httpx_client().__exit__(*args, **kwargs)
253
-
254
- def set_async_httpx_client(
255
- self, async_client: httpx.AsyncClient
256
- ) -> "AuthenticatedClient":
257
- """Manually the underlying httpx.AsyncClient
258
-
259
- **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
260
- """
261
- self._async_client = async_client
262
- return self
263
-
264
- def get_async_httpx_client(self) -> httpx.AsyncClient:
265
- """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
266
- if self._async_client is None:
267
- self._headers[self.auth_header_name] = (
268
- f"{self.prefix} {self.token}" if self.prefix else self.token
269
- )
270
- self._async_client = httpx.AsyncClient(
271
- base_url=self._base_url,
272
- cookies=self._cookies,
273
- headers=self._headers,
274
- timeout=self._timeout,
275
- verify=self._verify_ssl,
276
- follow_redirects=self._follow_redirects,
277
- **self._httpx_args,
278
- )
279
- return self._async_client
280
-
281
- async def __aenter__(self) -> "AuthenticatedClient":
282
- """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
283
- await self.get_async_httpx_client().__aenter__()
284
- return self
285
-
286
- async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
287
- """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
288
- await self.get_async_httpx_client().__aexit__(*args, **kwargs)
1
+ from __future__ import annotations
2
+
3
+ import ssl
4
+ from typing import Any, Dict, Optional, Union
5
+
6
+ import httpx
7
+ from attrs import define, evolve, field
8
+
9
+
10
+ @define
11
+ class Client:
12
+ """A class for keeping track of data related to the API
13
+
14
+ The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
15
+
16
+ ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
17
+
18
+ ``cookies``: A dictionary of cookies to be sent with every request
19
+
20
+ ``headers``: A dictionary of headers to be sent with every request
21
+
22
+ ``timeout``: The maximum amount of a time a request can take. API functions will raise
23
+ httpx.TimeoutException if this is exceeded.
24
+
25
+ ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
26
+ but can be set to False for testing purposes.
27
+
28
+ ``follow_redirects``: Whether or not to follow redirects. Default value is False.
29
+
30
+ ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
31
+
32
+
33
+ Attributes:
34
+ raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
35
+ status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
36
+ argument to the constructor.
37
+ """
38
+
39
+ raise_on_unexpected_status: bool = field(default=False, kw_only=True)
40
+ _base_url: str = field(alias="base_url")
41
+ _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
42
+ _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
43
+ _timeout: Optional[httpx.Timeout] = field(
44
+ default=None, kw_only=True, alias="timeout"
45
+ )
46
+ _verify_ssl: Union[str, bool, ssl.SSLContext] = field(
47
+ default=True, kw_only=True, alias="verify_ssl"
48
+ )
49
+ _follow_redirects: bool = field(
50
+ default=False, kw_only=True, alias="follow_redirects"
51
+ )
52
+ _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
53
+ _client: Optional[httpx.Client] = field(default=None, init=False)
54
+ _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
55
+
56
+ def with_headers(self, headers: Dict[str, str]) -> "Client":
57
+ """Get a new client matching this one with additional headers"""
58
+ if self._client is not None:
59
+ self._client.headers.update(headers)
60
+ if self._async_client is not None:
61
+ self._async_client.headers.update(headers)
62
+ return evolve(self, headers={**self._headers, **headers})
63
+
64
+ def with_cookies(self, cookies: Dict[str, str]) -> "Client":
65
+ """Get a new client matching this one with additional cookies"""
66
+ if self._client is not None:
67
+ self._client.cookies.update(cookies)
68
+ if self._async_client is not None:
69
+ self._async_client.cookies.update(cookies)
70
+ return evolve(self, cookies={**self._cookies, **cookies})
71
+
72
+ def with_timeout(self, timeout: httpx.Timeout) -> "Client":
73
+ """Get a new client matching this one with a new timeout (in seconds)"""
74
+ if self._client is not None:
75
+ self._client.timeout = timeout
76
+ if self._async_client is not None:
77
+ self._async_client.timeout = timeout
78
+ return evolve(self, timeout=timeout)
79
+
80
+ def set_httpx_client(self, client: httpx.Client) -> "Client":
81
+ """Manually set the underlying httpx.Client
82
+
83
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
84
+ """
85
+ self._client = client
86
+ return self
87
+
88
+ def get_httpx_client(self) -> httpx.Client:
89
+ """Get the underlying httpx.Client, constructing a new one if not previously set"""
90
+ if self._client is None:
91
+ self._client = httpx.Client(
92
+ base_url=self._base_url,
93
+ cookies=self._cookies,
94
+ headers=self._headers,
95
+ timeout=self._timeout,
96
+ verify=self._verify_ssl,
97
+ follow_redirects=self._follow_redirects,
98
+ **self._httpx_args,
99
+ )
100
+ return self._client
101
+
102
+ def __enter__(self) -> "Client":
103
+ """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
104
+ self.get_httpx_client().__enter__()
105
+ return self
106
+
107
+ def __exit__(self, *args: Any, **kwargs: Any) -> None:
108
+ """Exit a context manager for internal httpx.Client (see httpx docs)"""
109
+ self.get_httpx_client().__exit__(*args, **kwargs)
110
+
111
+ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
112
+ """Manually the underlying httpx.AsyncClient
113
+
114
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
115
+ """
116
+ self._async_client = async_client
117
+ return self
118
+
119
+ def get_async_httpx_client(self) -> httpx.AsyncClient:
120
+ """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
121
+ if self._async_client is None:
122
+ self._async_client = httpx.AsyncClient(
123
+ base_url=self._base_url,
124
+ cookies=self._cookies,
125
+ headers=self._headers,
126
+ timeout=self._timeout,
127
+ verify=self._verify_ssl,
128
+ follow_redirects=self._follow_redirects,
129
+ **self._httpx_args,
130
+ )
131
+ return self._async_client
132
+
133
+ async def __aenter__(self) -> "Client":
134
+ """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
135
+ await self.get_async_httpx_client().__aenter__()
136
+ return self
137
+
138
+ async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
139
+ """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
140
+ await self.get_async_httpx_client().__aexit__(*args, **kwargs)
141
+
142
+
143
+ @define
144
+ class AuthenticatedClient:
145
+ """A Client which has been authenticated for use on secured endpoints
146
+
147
+ The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
148
+
149
+ ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
150
+
151
+ ``cookies``: A dictionary of cookies to be sent with every request
152
+
153
+ ``headers``: A dictionary of headers to be sent with every request
154
+
155
+ ``timeout``: The maximum amount of a time a request can take. API functions will raise
156
+ httpx.TimeoutException if this is exceeded.
157
+
158
+ ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
159
+ but can be set to False for testing purposes.
160
+
161
+ ``follow_redirects``: Whether or not to follow redirects. Default value is False.
162
+
163
+ ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
164
+
165
+
166
+ Attributes:
167
+ raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
168
+ status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
169
+ argument to the constructor.
170
+ token: The token to use for authentication
171
+ prefix: The prefix to use for the Authorization header
172
+ auth_header_name: The name of the Authorization header
173
+ """
174
+
175
+ raise_on_unexpected_status: bool = field(default=False, kw_only=True)
176
+ _base_url: str = field(alias="base_url")
177
+ _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
178
+ _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
179
+ _timeout: Optional[httpx.Timeout] = field(
180
+ default=None, kw_only=True, alias="timeout"
181
+ )
182
+ _verify_ssl: Union[str, bool, ssl.SSLContext] = field(
183
+ default=True, kw_only=True, alias="verify_ssl"
184
+ )
185
+ _follow_redirects: bool = field(
186
+ default=False, kw_only=True, alias="follow_redirects"
187
+ )
188
+ _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
189
+ _client: Optional[httpx.Client] = field(default=None, init=False)
190
+ _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
191
+
192
+ token: str
193
+ prefix: str = "Bearer"
194
+ auth_header_name: str = "Authorization"
195
+
196
+ def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient":
197
+ """Get a new client matching this one with additional headers"""
198
+ if self._client is not None:
199
+ self._client.headers.update(headers)
200
+ if self._async_client is not None:
201
+ self._async_client.headers.update(headers)
202
+ return evolve(self, headers={**self._headers, **headers})
203
+
204
+ def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient":
205
+ """Get a new client matching this one with additional cookies"""
206
+ if self._client is not None:
207
+ self._client.cookies.update(cookies)
208
+ if self._async_client is not None:
209
+ self._async_client.cookies.update(cookies)
210
+ return evolve(self, cookies={**self._cookies, **cookies})
211
+
212
+ def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
213
+ """Get a new client matching this one with a new timeout (in seconds)"""
214
+ if self._client is not None:
215
+ self._client.timeout = timeout
216
+ if self._async_client is not None:
217
+ self._async_client.timeout = timeout
218
+ return evolve(self, timeout=timeout)
219
+
220
+ def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
221
+ """Manually set the underlying httpx.Client
222
+
223
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
224
+ """
225
+ self._client = client
226
+ return self
227
+
228
+ def get_httpx_client(self) -> httpx.Client:
229
+ """Get the underlying httpx.Client, constructing a new one if not previously set"""
230
+ if self._client is None:
231
+ self._headers[self.auth_header_name] = (
232
+ f"{self.prefix} {self.token}" if self.prefix else self.token
233
+ )
234
+ self._client = httpx.Client(
235
+ base_url=self._base_url,
236
+ cookies=self._cookies,
237
+ headers=self._headers,
238
+ timeout=self._timeout,
239
+ verify=self._verify_ssl,
240
+ follow_redirects=self._follow_redirects,
241
+ **self._httpx_args,
242
+ )
243
+ return self._client
244
+
245
+ def __enter__(self) -> "AuthenticatedClient":
246
+ """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
247
+ self.get_httpx_client().__enter__()
248
+ return self
249
+
250
+ def __exit__(self, *args: Any, **kwargs: Any) -> None:
251
+ """Exit a context manager for internal httpx.Client (see httpx docs)"""
252
+ self.get_httpx_client().__exit__(*args, **kwargs)
253
+
254
+ def set_async_httpx_client(
255
+ self, async_client: httpx.AsyncClient
256
+ ) -> "AuthenticatedClient":
257
+ """Manually the underlying httpx.AsyncClient
258
+
259
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
260
+ """
261
+ self._async_client = async_client
262
+ return self
263
+
264
+ def get_async_httpx_client(self) -> httpx.AsyncClient:
265
+ """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
266
+ if self._async_client is None:
267
+ self._headers[self.auth_header_name] = (
268
+ f"{self.prefix} {self.token}" if self.prefix else self.token
269
+ )
270
+ self._async_client = httpx.AsyncClient(
271
+ base_url=self._base_url,
272
+ cookies=self._cookies,
273
+ headers=self._headers,
274
+ timeout=self._timeout,
275
+ verify=self._verify_ssl,
276
+ follow_redirects=self._follow_redirects,
277
+ **self._httpx_args,
278
+ )
279
+ return self._async_client
280
+
281
+ async def __aenter__(self) -> "AuthenticatedClient":
282
+ """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
283
+ await self.get_async_httpx_client().__aenter__()
284
+ return self
285
+
286
+ async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
287
+ """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
288
+ await self.get_async_httpx_client().__aexit__(*args, **kwargs)
@@ -0,0 +1,59 @@
1
+ from collections.abc import Mapping
2
+ from typing import Any, TypeVar
3
+
4
+ from attrs import define as _attrs_define
5
+ from attrs import field as _attrs_field
6
+
7
+ T = TypeVar("T", bound="ConnectSandbox")
8
+
9
+
10
+ @_attrs_define
11
+ class ConnectSandbox:
12
+ """
13
+ Attributes:
14
+ timeout (int): Timeout in seconds from the current time after which the sandbox should expire
15
+ """
16
+
17
+ timeout: int
18
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
19
+
20
+ def to_dict(self) -> dict[str, Any]:
21
+ timeout = self.timeout
22
+
23
+ field_dict: dict[str, Any] = {}
24
+ field_dict.update(self.additional_properties)
25
+ field_dict.update(
26
+ {
27
+ "timeout": timeout,
28
+ }
29
+ )
30
+
31
+ return field_dict
32
+
33
+ @classmethod
34
+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
35
+ d = dict(src_dict)
36
+ timeout = d.pop("timeout")
37
+
38
+ connect_sandbox = cls(
39
+ timeout=timeout,
40
+ )
41
+
42
+ connect_sandbox.additional_properties = d
43
+ return connect_sandbox
44
+
45
+ @property
46
+ def additional_keys(self) -> list[str]:
47
+ return list(self.additional_properties.keys())
48
+
49
+ def __getitem__(self, key: str) -> Any:
50
+ return self.additional_properties[key]
51
+
52
+ def __setitem__(self, key: str, value: Any) -> None:
53
+ self.additional_properties[key] = value
54
+
55
+ def __delitem__(self, key: str) -> None:
56
+ del self.additional_properties[key]
57
+
58
+ def __contains__(self, key: str) -> bool:
59
+ return key in self.additional_properties
@@ -38,9 +38,9 @@ class Error:
38
38
  @classmethod
39
39
  def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
40
40
  d = dict(src_dict)
41
- code = d.pop("code")
41
+ code = d.pop("code",0)
42
42
 
43
- message = d.pop("message")
43
+ message = d.pop("error")
44
44
 
45
45
  error = cls(
46
46
  code=code,