scalebox-sdk 0.1.25__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 (70) hide show
  1. scalebox/__init__.py +2 -2
  2. scalebox/api/__init__.py +3 -1
  3. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_connect.py +193 -0
  4. scalebox/api/client/models/connect_sandbox.py +59 -0
  5. scalebox/api/client/models/error.py +2 -2
  6. scalebox/api/client/models/listed_sandbox.py +19 -1
  7. scalebox/api/client/models/new_sandbox.py +10 -0
  8. scalebox/api/client/models/sandbox.py +13 -0
  9. scalebox/api/client/models/sandbox_detail.py +24 -0
  10. scalebox/cli.py +125 -125
  11. scalebox/client/aclient.py +57 -57
  12. scalebox/client/client.py +102 -102
  13. scalebox/code_interpreter/__init__.py +12 -12
  14. scalebox/code_interpreter/charts.py +230 -230
  15. scalebox/code_interpreter/constants.py +3 -3
  16. scalebox/code_interpreter/exceptions.py +13 -13
  17. scalebox/code_interpreter/models.py +485 -485
  18. scalebox/connection_config.py +34 -1
  19. scalebox/csx_connect/__init__.py +1 -1
  20. scalebox/csx_connect/client.py +485 -485
  21. scalebox/csx_desktop/main.py +651 -651
  22. scalebox/exceptions.py +83 -83
  23. scalebox/generated/api.py +61 -61
  24. scalebox/generated/api_pb2.py +203 -203
  25. scalebox/generated/api_pb2.pyi +956 -956
  26. scalebox/generated/api_pb2_connect.py +1407 -1407
  27. scalebox/generated/rpc.py +50 -50
  28. scalebox/sandbox/main.py +146 -139
  29. scalebox/sandbox/sandbox_api.py +105 -91
  30. scalebox/sandbox/signature.py +40 -40
  31. scalebox/sandbox/utils.py +34 -34
  32. scalebox/sandbox_async/main.py +226 -44
  33. scalebox/sandbox_async/sandbox_api.py +124 -3
  34. scalebox/sandbox_sync/main.py +205 -130
  35. scalebox/sandbox_sync/sandbox_api.py +119 -3
  36. scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -323
  37. scalebox/test/README.md +329 -329
  38. scalebox/test/bedrock_openai_adapter.py +67 -0
  39. scalebox/test/code_interpreter_test.py +34 -34
  40. scalebox/test/code_interpreter_test_sync.py +34 -34
  41. scalebox/test/run_stress_code_interpreter_sync.py +166 -0
  42. scalebox/test/simple_upload_example.py +123 -0
  43. scalebox/test/stabitiy_test.py +310 -0
  44. scalebox/test/test_browser_use.py +25 -0
  45. scalebox/test/test_browser_use_scalebox.py +61 -0
  46. scalebox/test/test_code_interpreter_sync_comprehensive.py +115 -65
  47. scalebox/test/test_connect_pause_async.py +277 -0
  48. scalebox/test/test_connect_pause_sync.py +267 -0
  49. scalebox/test/test_desktop_sandbox_sf.py +117 -0
  50. scalebox/test/test_download_url.py +49 -0
  51. scalebox/test/test_sandbox_async_comprehensive.py +1 -1
  52. scalebox/test/test_sandbox_object_storage_example.py +146 -0
  53. scalebox/test/test_sandbox_object_storage_example_async.py +156 -0
  54. scalebox/test/test_sf.py +137 -0
  55. scalebox/test/test_watch_dir_async.py +56 -0
  56. scalebox/test/testacreate.py +1 -1
  57. scalebox/test/testagetinfo.py +1 -1
  58. scalebox/test/testcomputeuse.py +243 -243
  59. scalebox/test/testsandbox_api.py +1 -3
  60. scalebox/test/testsandbox_sync.py +1 -1
  61. scalebox/test/upload_100mb_example.py +355 -0
  62. scalebox/utils/httpcoreclient.py +297 -297
  63. scalebox/utils/httpxclient.py +403 -403
  64. scalebox/version.py +2 -2
  65. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/METADATA +1 -1
  66. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/RECORD +70 -53
  67. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/WHEEL +1 -1
  68. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/entry_points.txt +0 -0
  69. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/licenses/LICENSE +0 -0
  70. {scalebox_sdk-0.1.25.dist-info → scalebox_sdk-1.0.1.dist-info}/top_level.txt +0 -0
scalebox/__init__.py CHANGED
@@ -9,7 +9,7 @@ A multi-language code execution sandbox with support for:
9
9
  - Real-time callbacks and monitoring
10
10
  """
11
11
 
12
- __version__ = "0.1.25"
12
+ __version__ = "1.0.1"
13
13
  __author__ = "ScaleBox Team"
14
14
  __email__ = "dev@scalebox.dev"
15
15
 
@@ -74,7 +74,7 @@ __all__ = [
74
74
  "AuthenticationException",
75
75
  "TemplateException",
76
76
  "RateLimitException",
77
- "APIError",
77
+ # "APIError",
78
78
  # Configuration
79
79
  "ConnectionConfig",
80
80
  ]
scalebox/api/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  from dataclasses import dataclass
4
- from typing import Optional
4
+ from typing import Optional, Dict
5
5
 
6
6
  from httpx import Limits
7
7
 
@@ -20,6 +20,8 @@ class SandboxCreateResponse:
20
20
  sandbox_domain: Optional[str]
21
21
  envd_version: str
22
22
  envd_access_token: str
23
+ object_storage: Optional[Dict[str, str]]
24
+ network_proxy: Optional[Dict[str, any]]
23
25
 
24
26
 
25
27
  def handle_api_exception(e: Response):
@@ -0,0 +1,193 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.connect_sandbox import ConnectSandbox
9
+ from ...models.error import Error
10
+ from ...models.sandbox import Sandbox
11
+ from ...types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ sandbox_id: str,
16
+ *,
17
+ body: ConnectSandbox,
18
+ ) -> dict[str, Any]:
19
+ headers: dict[str, Any] = {}
20
+
21
+ _kwargs: dict[str, Any] = {
22
+ "method": "post",
23
+ "url": f"/sandboxes/{sandbox_id}/connect",
24
+ }
25
+
26
+ _kwargs["json"] = body.to_dict()
27
+
28
+ headers["Content-Type"] = "application/json"
29
+
30
+ _kwargs["headers"] = headers
31
+ return _kwargs
32
+
33
+
34
+ def _parse_response(
35
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
36
+ ) -> Optional[Union[Error, Sandbox]]:
37
+ if response.status_code == 200:
38
+ response_200 = Sandbox.from_dict(response.json())
39
+
40
+ return response_200
41
+ if response.status_code == 201:
42
+ response_201 = Sandbox.from_dict(response.json())
43
+
44
+ return response_201
45
+ if response.status_code == 400:
46
+ response_400 = Error.from_dict(response.json())
47
+
48
+ return response_400
49
+ if response.status_code == 401:
50
+ response_401 = Error.from_dict(response.json())
51
+
52
+ return response_401
53
+ if response.status_code == 404:
54
+ response_404 = Error.from_dict(response.json())
55
+
56
+ return response_404
57
+ if response.status_code == 500:
58
+ response_500 = Error.from_dict(response.json())
59
+
60
+ return response_500
61
+ if client.raise_on_unexpected_status:
62
+ raise errors.UnexpectedStatus(response.status_code, response.content)
63
+ else:
64
+ return None
65
+
66
+
67
+ def _build_response(
68
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
69
+ ) -> Response[Union[Error, Sandbox]]:
70
+ return Response(
71
+ status_code=HTTPStatus(response.status_code),
72
+ content=response.content,
73
+ headers=response.headers,
74
+ parsed=_parse_response(client=client, response=response),
75
+ )
76
+
77
+
78
+ def sync_detailed(
79
+ sandbox_id: str,
80
+ *,
81
+ client: AuthenticatedClient,
82
+ body: ConnectSandbox,
83
+ ) -> Response[Union[Error, Sandbox]]:
84
+ """Returns sandbox details. If the sandbox is paused, it will be resumed. TTL is only extended.
85
+
86
+ Args:
87
+ sandbox_id (str):
88
+ body (ConnectSandbox):
89
+
90
+ Raises:
91
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
92
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
93
+
94
+ Returns:
95
+ Response[Union[Error, Sandbox]]
96
+ """
97
+
98
+ kwargs = _get_kwargs(
99
+ sandbox_id=sandbox_id,
100
+ body=body,
101
+ )
102
+
103
+ response = client.get_httpx_client().request(
104
+ **kwargs,
105
+ )
106
+
107
+ return _build_response(client=client, response=response)
108
+
109
+
110
+ def sync(
111
+ sandbox_id: str,
112
+ *,
113
+ client: AuthenticatedClient,
114
+ body: ConnectSandbox,
115
+ ) -> Optional[Union[Error, Sandbox]]:
116
+ """Returns sandbox details. If the sandbox is paused, it will be resumed. TTL is only extended.
117
+
118
+ Args:
119
+ sandbox_id (str):
120
+ body (ConnectSandbox):
121
+
122
+ Raises:
123
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
124
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
125
+
126
+ Returns:
127
+ Union[Error, Sandbox]
128
+ """
129
+
130
+ return sync_detailed(
131
+ sandbox_id=sandbox_id,
132
+ client=client,
133
+ body=body,
134
+ ).parsed
135
+
136
+
137
+ async def asyncio_detailed(
138
+ sandbox_id: str,
139
+ *,
140
+ client: AuthenticatedClient,
141
+ body: ConnectSandbox,
142
+ ) -> Response[Union[Error, Sandbox]]:
143
+ """Returns sandbox details. If the sandbox is paused, it will be resumed. TTL is only extended.
144
+
145
+ Args:
146
+ sandbox_id (str):
147
+ body (ConnectSandbox):
148
+
149
+ Raises:
150
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
151
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
152
+
153
+ Returns:
154
+ Response[Union[Error, Sandbox]]
155
+ """
156
+
157
+ kwargs = _get_kwargs(
158
+ sandbox_id=sandbox_id,
159
+ body=body,
160
+ )
161
+
162
+ response = await client.get_async_httpx_client().request(**kwargs)
163
+
164
+ return _build_response(client=client, response=response)
165
+
166
+
167
+ async def asyncio(
168
+ sandbox_id: str,
169
+ *,
170
+ client: AuthenticatedClient,
171
+ body: ConnectSandbox,
172
+ ) -> Optional[Union[Error, Sandbox]]:
173
+ """Returns sandbox details. If the sandbox is paused, it will be resumed. TTL is only extended.
174
+
175
+ Args:
176
+ sandbox_id (str):
177
+ body (ConnectSandbox):
178
+
179
+ Raises:
180
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
181
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
182
+
183
+ Returns:
184
+ Union[Error, Sandbox]
185
+ """
186
+
187
+ return (
188
+ await asyncio_detailed(
189
+ sandbox_id=sandbox_id,
190
+ client=client,
191
+ body=body,
192
+ )
193
+ ).parsed
@@ -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,
@@ -38,6 +38,9 @@ class ListedSandbox:
38
38
  template_id: str
39
39
  alias: Union[Unset, str] = UNSET
40
40
  metadata: Union[Unset, Any] = UNSET
41
+ object_storage: Union[Unset, Any] = UNSET
42
+ uptime: Union[Unset, int] = UNSET
43
+ timeout: Union[Unset, int] = UNSET
41
44
  additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
42
45
 
43
46
  def to_dict(self) -> dict[str, Any]:
@@ -60,6 +63,9 @@ class ListedSandbox:
60
63
  alias = self.alias
61
64
 
62
65
  metadata = self.metadata
66
+ object_storage = self.object_storage
67
+ uptime = self.uptime
68
+ timeout = self.timeout
63
69
 
64
70
  field_dict: dict[str, Any] = {}
65
71
  field_dict.update(self.additional_properties)
@@ -79,6 +85,12 @@ class ListedSandbox:
79
85
  field_dict["alias"] = alias
80
86
  if metadata is not UNSET:
81
87
  field_dict["metadata"] = metadata
88
+ if object_storage is not UNSET:
89
+ field_dict["objectStorage"] = object_storage
90
+ if uptime is not UNSET:
91
+ field_dict["upTime"] = uptime
92
+ if timeout is not UNSET:
93
+ field_dict["timeout"] = timeout
82
94
 
83
95
  return field_dict
84
96
 
@@ -103,9 +115,12 @@ class ListedSandbox:
103
115
  template_id = d.pop("template_id")
104
116
 
105
117
  alias = d.pop("name", UNSET)
118
+ object_storage = d.pop("object_storage", UNSET)
106
119
 
107
120
  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
121
+ uptime = d.pop("uptime", UNSET)
122
+ timeout = d.pop("timeout", UNSET)
123
+ end_at = (started_at + datetime.timedelta(seconds=float(timeout1))) if (timeout1 := d.pop("timeout", "0")) is not UNSET and timeout1 is not None else None
109
124
 
110
125
  listed_sandbox = cls(
111
126
  client_id=client_id,
@@ -118,6 +133,9 @@ class ListedSandbox:
118
133
  template_id=template_id,
119
134
  alias=alias,
120
135
  metadata=metadata,
136
+ object_storage=object_storage,
137
+ uptime=uptime,
138
+ timeout=timeout,
121
139
  )
122
140
 
123
141
  listed_sandbox.additional_properties = d
@@ -32,6 +32,8 @@ class NewSandbox:
32
32
  additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
33
33
  is_async: Union[Unset, bool] = False
34
34
  storage_gb: Union[Unset, int] = UNSET
35
+ object_storage: Union[Unset, Any] = UNSET
36
+ net_proxy_country: Union[Unset, str] = UNSET
35
37
 
36
38
  def to_dict(self) -> dict[str, Any]:
37
39
  template_id = self.template_id
@@ -49,6 +51,8 @@ class NewSandbox:
49
51
  timeout = self.timeout
50
52
  is_async = self.is_async
51
53
  storage_gb = self.storage_gb
54
+ object_storage = self.object_storage
55
+ net_proxy_country = self.net_proxy_country
52
56
 
53
57
  field_dict: dict[str, Any] = {}
54
58
  field_dict.update(self.additional_properties)
@@ -73,6 +77,10 @@ class NewSandbox:
73
77
  field_dict["is_async"] = is_async
74
78
  if storage_gb is not UNSET:
75
79
  field_dict["storage_gb"] = storage_gb
80
+ if object_storage is not UNSET:
81
+ field_dict["object_storage"] = object_storage
82
+ if net_proxy_country is not UNSET:
83
+ field_dict["net_proxy_country"] = net_proxy_country
76
84
 
77
85
  return field_dict
78
86
 
@@ -103,6 +111,8 @@ class NewSandbox:
103
111
  timeout=timeout,
104
112
  is_async=d.pop("is_async", UNSET),
105
113
  storage_gb=d.pop("storage_gb", UNSET),
114
+ object_storage=d.pop("object_storage", UNSET),
115
+ net_proxy_country=d.pop("net_proxy_country", UNSET),
106
116
  )
107
117
 
108
118
  new_sandbox.additional_properties = d
@@ -29,6 +29,8 @@ class Sandbox:
29
29
  alias: Union[Unset, str] = UNSET
30
30
  domain: Union[None, Unset, str] = UNSET
31
31
  envd_access_token: Union[Unset, str] = UNSET
32
+ object_storage: Union[Unset, Any] = UNSET
33
+ network_proxy: Union[Unset, Any] = UNSET
32
34
  additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
33
35
 
34
36
  def to_dict(self) -> dict[str, Any]:
@@ -39,6 +41,8 @@ class Sandbox:
39
41
  sandbox_id = self.sandbox_id
40
42
 
41
43
  template_id = self.template_id
44
+ object_storage = self.object_storage
45
+ network_proxy = self.network_proxy
42
46
 
43
47
  alias = self.alias
44
48
 
@@ -66,6 +70,10 @@ class Sandbox:
66
70
  field_dict["domain"] = domain
67
71
  if envd_access_token is not UNSET:
68
72
  field_dict["envdAccessToken"] = envd_access_token
73
+ if object_storage is not UNSET:
74
+ field_dict["objectStorage"] = object_storage
75
+ if network_proxy is not UNSET:
76
+ field_dict["networkProxy"] = network_proxy
69
77
 
70
78
  return field_dict
71
79
 
@@ -82,6 +90,9 @@ class Sandbox:
82
90
 
83
91
  template_id = data.pop("template_id")
84
92
 
93
+ object_storage = data.pop("object_storage",{})
94
+ network_proxy = data.pop("network_proxy",{})
95
+
85
96
  alias = data.pop("alias", UNSET)
86
97
 
87
98
  def _parse_domain(data: object) -> Union[None, Unset, str]:
@@ -103,6 +114,8 @@ class Sandbox:
103
114
  alias=alias,
104
115
  domain=domain,
105
116
  envd_access_token=envd_access_token,
117
+ object_storage=object_storage,
118
+ network_proxy=network_proxy,
106
119
  )
107
120
 
108
121
  sandbox.additional_properties = d
@@ -44,6 +44,9 @@ class SandboxDetail:
44
44
  envd_access_token: Union[Unset, str] = UNSET
45
45
  envd_version: Union[Unset, str] = UNSET
46
46
  metadata: Union[Unset, Any] = UNSET
47
+ object_storage: Union[Unset, Any] = UNSET
48
+ uptime: Union[Unset, int] = UNSET
49
+ timeout: Union[Unset, int] = UNSET
47
50
  additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
48
51
 
49
52
  def to_dict(self) -> dict[str, Any]:
@@ -63,8 +66,14 @@ class SandboxDetail:
63
66
 
64
67
  template_id = self.template_id
65
68
 
69
+ object_storage = self.object_storage
70
+
66
71
  alias = self.alias
67
72
 
73
+ uptime = self.uptime
74
+
75
+ timeout = self.timeout
76
+
68
77
  domain: Union[None, Unset, str]
69
78
  if isinstance(self.domain, Unset):
70
79
  domain = UNSET
@@ -101,6 +110,12 @@ class SandboxDetail:
101
110
  field_dict["envdVersion"] = envd_version
102
111
  if metadata is not UNSET:
103
112
  field_dict["metadata"] = metadata
113
+ if object_storage is not UNSET:
114
+ field_dict["objectStorage"] = object_storage
115
+ if uptime is not UNSET:
116
+ field_dict["upTime"] = uptime
117
+ if timeout is not UNSET:
118
+ field_dict["timeout"] = timeout
104
119
 
105
120
  return field_dict
106
121
 
@@ -127,6 +142,12 @@ class SandboxDetail:
127
142
 
128
143
  alias = d.pop("alias", UNSET)
129
144
 
145
+ object_storage = data.pop("object_storage",UNSET)
146
+
147
+ uptime = data.pop("uptime",UNSET)
148
+
149
+ timeout = data.pop("timeout",UNSET)
150
+
130
151
  def _parse_domain(data: object) -> Union[None, Unset, str]:
131
152
  if data is None:
132
153
  return data
@@ -156,6 +177,9 @@ class SandboxDetail:
156
177
  envd_access_token=envd_access_token,
157
178
  envd_version=envd_version,
158
179
  metadata=metadata,
180
+ object_storage=object_storage,
181
+ uptime=uptime,
182
+ timeout=timeout,
159
183
  )
160
184
 
161
185
  sandbox_detail.additional_properties = d