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
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.24"
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,128 +1,130 @@
1
- import json
2
- import logging
3
- from dataclasses import dataclass
4
- from typing import Optional
5
-
6
- from httpx import Limits
7
-
8
- from ..api.client.client import AuthenticatedClient
9
- from ..api.client.types import Response
10
- from ..api.metadata import default_headers
11
- from ..connection_config import ConnectionConfig
12
- from ..exceptions import AuthenticationException, RateLimitException, SandboxException
13
-
14
- logger = logging.getLogger(__name__)
15
-
16
-
17
- @dataclass
18
- class SandboxCreateResponse:
19
- sandbox_id: str
20
- sandbox_domain: Optional[str]
21
- envd_version: str
22
- envd_access_token: str
23
-
24
-
25
- def handle_api_exception(e: Response):
26
- try:
27
- body = json.loads(e.content) if e.content else {}
28
- except json.JSONDecodeError:
29
- body = {}
30
-
31
- if e.status_code == 429:
32
- return RateLimitException(
33
- f"{e.status_code}: Rate limit exceeded, please try again later."
34
- )
35
-
36
- if "message" in body:
37
- return SandboxException(f"{e.status_code}: {body['message']}")
38
- return SandboxException(f"{e.status_code}: {e.content}")
39
-
40
-
41
- class ApiClient(AuthenticatedClient):
42
- """
43
- The client for interacting with the CSX API.
44
- """
45
-
46
- def __init__(
47
- self,
48
- config: ConnectionConfig,
49
- require_api_key: bool = True,
50
- require_access_token: bool = False,
51
- limits: Optional[Limits] = None,
52
- *args,
53
- **kwargs,
54
- ):
55
- if require_api_key and require_access_token:
56
- raise AuthenticationException(
57
- "Only one of api_key or access_token can be required, not both",
58
- )
59
-
60
- if not require_api_key and not require_access_token:
61
- raise AuthenticationException(
62
- "Either api_key or access_token is required",
63
- )
64
-
65
- token = None
66
- if require_api_key:
67
- if config.api_key is None:
68
- raise AuthenticationException(
69
- "API key is required, please visit the Team tab at https://dev/dashboard to get your API key. "
70
- "You can either set the environment variable `SBX_API_KEY` "
71
- 'or you can pass it directly to the sandbox like Sandbox(api_key="sbx_...")',
72
- )
73
- token = config.api_key
74
-
75
- if require_access_token:
76
- if config.access_token is None:
77
- raise AuthenticationException(
78
- "Access token is required, please visit the Personal tab at https://dev/dashboard to get your access token. "
79
- "You can set the environment variable `SBX_ACCESS_TOKEN` or pass the `access_token` in options.",
80
- )
81
- token = config.access_token
82
-
83
- auth_header_name = "X-API-KEY" if require_api_key else "Authorization"
84
- prefix = "" if require_api_key else "Bearer"
85
-
86
- headers = {
87
- **default_headers,
88
- **(config.headers or {}),
89
- }
90
-
91
- super().__init__(
92
- base_url=config.api_url,
93
- httpx_args={
94
- "event_hooks": {
95
- "request": [self._log_request],
96
- "response": [self._log_response],
97
- },
98
- "proxy": config.proxy,
99
- "limits": limits,
100
- },
101
- headers=headers,
102
- token=token,
103
- auth_header_name=auth_header_name,
104
- prefix=prefix,
105
- *args,
106
- **kwargs,
107
- )
108
-
109
- def _log_request(self, request):
110
- logger.info(f"Request {request.method} {request.url}")
111
-
112
- def _log_response(self, response: Response):
113
- if response.status_code >= 400:
114
- logger.error(f"Response {response.status_code}")
115
- else:
116
- logger.info(f"Response {response.status_code}")
117
-
118
-
119
- # We need to override the logging hooks for the async usage
120
- class AsyncApiClient(ApiClient):
121
- async def _log_request(self, request):
122
- logger.info(f"Request {request.method} {request.url}")
123
-
124
- async def _log_response(self, response: Response):
125
- if response.status_code >= 400:
126
- logger.error(f"Response {response.status_code}")
127
- else:
128
- logger.info(f"Response {response.status_code}")
1
+ import json
2
+ import logging
3
+ from dataclasses import dataclass
4
+ from typing import Optional, Dict
5
+
6
+ from httpx import Limits
7
+
8
+ from ..api.client.client import AuthenticatedClient
9
+ from ..api.client.types import Response
10
+ from ..api.metadata import default_headers
11
+ from ..connection_config import ConnectionConfig
12
+ from ..exceptions import AuthenticationException, RateLimitException, SandboxException
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ @dataclass
18
+ class SandboxCreateResponse:
19
+ sandbox_id: str
20
+ sandbox_domain: Optional[str]
21
+ envd_version: str
22
+ envd_access_token: str
23
+ object_storage: Optional[Dict[str, str]]
24
+ network_proxy: Optional[Dict[str, any]]
25
+
26
+
27
+ def handle_api_exception(e: Response):
28
+ try:
29
+ body = json.loads(e.content) if e.content else {}
30
+ except json.JSONDecodeError:
31
+ body = {}
32
+
33
+ if e.status_code == 429:
34
+ return RateLimitException(
35
+ f"{e.status_code}: Rate limit exceeded, please try again later."
36
+ )
37
+
38
+ if "message" in body:
39
+ return SandboxException(f"{e.status_code}: {body['message']}")
40
+ return SandboxException(f"{e.status_code}: {e.content}")
41
+
42
+
43
+ class ApiClient(AuthenticatedClient):
44
+ """
45
+ The client for interacting with the CSX API.
46
+ """
47
+
48
+ def __init__(
49
+ self,
50
+ config: ConnectionConfig,
51
+ require_api_key: bool = True,
52
+ require_access_token: bool = False,
53
+ limits: Optional[Limits] = None,
54
+ *args,
55
+ **kwargs,
56
+ ):
57
+ if require_api_key and require_access_token:
58
+ raise AuthenticationException(
59
+ "Only one of api_key or access_token can be required, not both",
60
+ )
61
+
62
+ if not require_api_key and not require_access_token:
63
+ raise AuthenticationException(
64
+ "Either api_key or access_token is required",
65
+ )
66
+
67
+ token = None
68
+ if require_api_key:
69
+ if config.api_key is None:
70
+ raise AuthenticationException(
71
+ "API key is required, please visit the Team tab at https://dev/dashboard to get your API key. "
72
+ "You can either set the environment variable `SBX_API_KEY` "
73
+ 'or you can pass it directly to the sandbox like Sandbox(api_key="sbx_...")',
74
+ )
75
+ token = config.api_key
76
+
77
+ if require_access_token:
78
+ if config.access_token is None:
79
+ raise AuthenticationException(
80
+ "Access token is required, please visit the Personal tab at https://dev/dashboard to get your access token. "
81
+ "You can set the environment variable `SBX_ACCESS_TOKEN` or pass the `access_token` in options.",
82
+ )
83
+ token = config.access_token
84
+
85
+ auth_header_name = "X-API-KEY" if require_api_key else "Authorization"
86
+ prefix = "" if require_api_key else "Bearer"
87
+
88
+ headers = {
89
+ **default_headers,
90
+ **(config.headers or {}),
91
+ }
92
+
93
+ super().__init__(
94
+ base_url=config.api_url,
95
+ httpx_args={
96
+ "event_hooks": {
97
+ "request": [self._log_request],
98
+ "response": [self._log_response],
99
+ },
100
+ "proxy": config.proxy,
101
+ "limits": limits,
102
+ },
103
+ headers=headers,
104
+ token=token,
105
+ auth_header_name=auth_header_name,
106
+ prefix=prefix,
107
+ *args,
108
+ **kwargs,
109
+ )
110
+
111
+ def _log_request(self, request):
112
+ logger.info(f"Request {request.method} {request.url}")
113
+
114
+ def _log_response(self, response: Response):
115
+ if response.status_code >= 400:
116
+ logger.error(f"Response {response.status_code}")
117
+ else:
118
+ logger.info(f"Response {response.status_code}")
119
+
120
+
121
+ # We need to override the logging hooks for the async usage
122
+ class AsyncApiClient(ApiClient):
123
+ async def _log_request(self, request):
124
+ logger.info(f"Request {request.method} {request.url}")
125
+
126
+ async def _log_response(self, response: Response):
127
+ if response.status_code >= 400:
128
+ logger.error(f"Response {response.status_code}")
129
+ else:
130
+ logger.info(f"Response {response.status_code}")
@@ -1,8 +1,8 @@
1
- """A client library for accessing Scalebox API"""
2
-
3
- from .client import AuthenticatedClient, Client
4
-
5
- __all__ = (
6
- "AuthenticatedClient",
7
- "Client",
8
- )
1
+ """A client library for accessing Scalebox API"""
2
+
3
+ from .client import AuthenticatedClient, Client
4
+
5
+ __all__ = (
6
+ "AuthenticatedClient",
7
+ "Client",
8
+ )
@@ -39,9 +39,9 @@ def _parse_response(
39
39
  if response.status_code == 200:
40
40
  response_200 = []
41
41
  _response_200 = response.json()
42
- print(_response_200)
42
+ # print(_response_200)
43
43
  for response_200_item_data in _response_200["data"]["metrics"]:
44
- print(response_200_item_data)
44
+ # print(response_200_item_data)
45
45
  response_200_item = SandboxMetric.from_dict(response_200_item_data)
46
46
 
47
47
  response_200.append(response_200_item)
@@ -35,7 +35,7 @@ def _parse_response(
35
35
  *, client: Union[AuthenticatedClient, Client], response: httpx.Response
36
36
  ) -> Optional[Union[Error, Sandbox]]:
37
37
  if response.status_code == 201:
38
- print(response.json())
38
+ # print(response.json())
39
39
  response_201 = Sandbox.from_dict(response.json())
40
40
 
41
41
  return response_201
@@ -89,7 +89,7 @@ def sync_detailed(
89
89
  kwargs = _get_kwargs(
90
90
  body=body,
91
91
  )
92
- print(kwargs)
92
+ # print(kwargs)
93
93
  response = client.get_httpx_client().request(
94
94
  **kwargs,
95
95
  )
@@ -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