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
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.4"
12
+ __version__ = "0.1.25"
13
13
  __author__ = "ScaleBox Team"
14
14
  __email__ = "dev@scalebox.dev"
15
15
 
scalebox/api/__init__.py CHANGED
@@ -1,128 +1,128 @@
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 `E2B_API_KEY` "
71
- 'or you can pass it directly to the sandbox like Sandbox(api_key="e2b_...")',
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 `E2B_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
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,8 +1,8 @@
1
- """A client library for accessing E2B 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
+ )
@@ -17,6 +17,7 @@ def _get_kwargs(
17
17
  params: dict[str, Any] = {}
18
18
 
19
19
  params["metadata"] = metadata
20
+ params["status"] = "running"
20
21
 
21
22
  params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
22
23
 
@@ -35,9 +36,11 @@ def _parse_response(
35
36
  if response.status_code == 200:
36
37
  response_200 = []
37
38
  _response_200 = response.json()
38
- for response_200_item_data in _response_200:
39
+ data=_response_200["data"]
40
+ if data["sandboxes"] is None:
41
+ return None
42
+ for response_200_item_data in data["sandboxes"]:
39
43
  response_200_item = ListedSandbox.from_dict(response_200_item_data)
40
-
41
44
  response_200.append(response_200_item)
42
45
 
43
46
  return response_200
@@ -95,7 +98,6 @@ def sync_detailed(
95
98
  response = client.get_httpx_client().request(
96
99
  **kwargs,
97
100
  )
98
-
99
101
  return _build_response(client=client, response=response)
100
102
 
101
103
 
@@ -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
  )