scalebox-sdk 0.1.4__py3-none-any.whl → 0.1.25__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 (68) hide show
  1. scalebox/__init__.py +1 -1
  2. scalebox/api/__init__.py +128 -128
  3. scalebox/api/client/__init__.py +8 -8
  4. scalebox/api/client/api/sandboxes/get_sandboxes.py +5 -3
  5. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +2 -2
  6. scalebox/api/client/api/sandboxes/post_sandboxes.py +2 -2
  7. scalebox/api/client/client.py +288 -288
  8. scalebox/api/client/models/listed_sandbox.py +11 -9
  9. scalebox/api/client/models/new_sandbox.py +1 -1
  10. scalebox/api/client/models/sandbox.py +125 -125
  11. scalebox/api/client/models/sandbox_state.py +1 -0
  12. scalebox/api/client/types.py +46 -46
  13. scalebox/code_interpreter/code_interpreter_async.py +370 -369
  14. scalebox/code_interpreter/code_interpreter_sync.py +318 -317
  15. scalebox/connection_config.py +92 -92
  16. scalebox/csx_desktop/main.py +12 -12
  17. scalebox/generated/api_pb2_connect.py +17 -66
  18. scalebox/sandbox_async/commands/command.py +307 -307
  19. scalebox/sandbox_async/commands/command_handle.py +187 -187
  20. scalebox/sandbox_async/commands/pty.py +187 -187
  21. scalebox/sandbox_async/filesystem/filesystem.py +557 -557
  22. scalebox/sandbox_async/filesystem/watch_handle.py +61 -61
  23. scalebox/sandbox_async/main.py +647 -646
  24. scalebox/sandbox_async/sandbox_api.py +365 -365
  25. scalebox/sandbox_async/utils.py +7 -7
  26. scalebox/sandbox_sync/__init__.py +2 -2
  27. scalebox/sandbox_sync/commands/command.py +300 -300
  28. scalebox/sandbox_sync/commands/command_handle.py +150 -150
  29. scalebox/sandbox_sync/commands/pty.py +181 -181
  30. scalebox/sandbox_sync/filesystem/filesystem.py +543 -543
  31. scalebox/sandbox_sync/filesystem/watch_handle.py +66 -66
  32. scalebox/sandbox_sync/main.py +789 -790
  33. scalebox/sandbox_sync/sandbox_api.py +356 -356
  34. scalebox/test/CODE_INTERPRETER_TESTS_READY.md +256 -256
  35. scalebox/test/README.md +164 -164
  36. scalebox/test/aclient.py +72 -72
  37. scalebox/test/code_interpreter_centext.py +21 -21
  38. scalebox/test/code_interpreter_centext_sync.py +21 -21
  39. scalebox/test/code_interpreter_test.py +1 -1
  40. scalebox/test/code_interpreter_test_sync.py +1 -1
  41. scalebox/test/run_all_validation_tests.py +334 -334
  42. scalebox/test/test_basic.py +78 -78
  43. scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -2653
  44. scalebox/test/{test_code_interpreter_e2bsync_comprehensive.py → test_code_interpreter_execcode.py} +328 -392
  45. scalebox/test/test_code_interpreter_sync_comprehensive.py +3416 -3412
  46. scalebox/test/test_csx_desktop_examples.py +130 -0
  47. scalebox/test/test_sandbox_async_comprehensive.py +736 -738
  48. scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -778
  49. scalebox/test/test_sandbox_sync_comprehensive.py +779 -770
  50. scalebox/test/test_sandbox_usage_examples.py +987 -987
  51. scalebox/test/testacreate.py +24 -24
  52. scalebox/test/testagetinfo.py +18 -18
  53. scalebox/test/testcodeinterpreter_async.py +508 -508
  54. scalebox/test/testcodeinterpreter_sync.py +239 -239
  55. scalebox/test/testcomputeuse.py +2 -2
  56. scalebox/test/testnovnc.py +12 -12
  57. scalebox/test/testsandbox_api.py +15 -0
  58. scalebox/test/testsandbox_async.py +202 -118
  59. scalebox/test/testsandbox_sync.py +71 -38
  60. scalebox/version.py +2 -2
  61. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/METADATA +104 -103
  62. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/RECORD +66 -66
  63. scalebox/test/test_code_interpreter_e2basync_comprehensive.py +0 -2655
  64. scalebox/test/test_e2b_first.py +0 -11
  65. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/WHEEL +0 -0
  66. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/entry_points.txt +0 -0
  67. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/licenses/LICENSE +0 -0
  68. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.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)
@@ -85,25 +85,27 @@ class ListedSandbox:
85
85
  @classmethod
86
86
  def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
87
87
  d = dict(src_dict)
88
- client_id = d.pop("clientID")
88
+ client_id = d.pop("clientID","")
89
89
 
90
- cpu_count = d.pop("cpuCount")
90
+ cpu_count = d.pop("cpu_count")
91
91
 
92
- end_at = isoparse(d.pop("endAt"))
92
+ # end_at = isoparse(d.pop("end_at",""))
93
93
 
94
- memory_mb = d.pop("memoryMB")
95
94
 
96
- sandbox_id = d.pop("sandboxID")
95
+ memory_mb = d.pop("memory_mb")
97
96
 
98
- started_at = isoparse(d.pop("startedAt"))
97
+ sandbox_id = d.pop("sandbox_id")
99
98
 
100
- state = SandboxState(d.pop("state"))
99
+ started_at = isoparse(d.pop("started_at"))
101
100
 
102
- template_id = d.pop("templateID")
101
+ state = SandboxState(d.pop("status"))
103
102
 
104
- alias = d.pop("alias", UNSET)
103
+ template_id = d.pop("template_id")
104
+
105
+ alias = d.pop("name", UNSET)
105
106
 
106
107
  metadata = d.pop("metadata", UNSET)
108
+ end_at = (started_at + datetime.timedelta(seconds=float(timeout))) if (timeout := d.pop("timeout", "0")) is not UNSET and timeout is not None else None
107
109
 
108
110
  listed_sandbox = cls(
109
111
  client_id=client_id,
@@ -31,7 +31,7 @@ class NewSandbox:
31
31
  timeout: Union[Unset, int] = 15
32
32
  additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
33
33
  is_async: Union[Unset, bool] = False
34
- storage_gb: Union[Unset, int] = 10
34
+ storage_gb: Union[Unset, int] = UNSET
35
35
 
36
36
  def to_dict(self) -> dict[str, Any]:
37
37
  template_id = self.template_id