scalebox-sdk 0.1.0__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.
- scalebox/__init__.py +80 -0
- scalebox/api/__init__.py +128 -0
- scalebox/api/client/__init__.py +8 -0
- scalebox/api/client/api/__init__.py +1 -0
- scalebox/api/client/api/sandboxes/__init__.py +0 -0
- scalebox/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py +161 -0
- scalebox/api/client/api/sandboxes/get_sandboxes.py +176 -0
- scalebox/api/client/api/sandboxes/get_sandboxes_metrics.py +173 -0
- scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id.py +163 -0
- scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py +199 -0
- scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +214 -0
- scalebox/api/client/api/sandboxes/get_v2_sandboxes.py +229 -0
- scalebox/api/client/api/sandboxes/post_sandboxes.py +174 -0
- scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_pause.py +165 -0
- scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_refreshes.py +182 -0
- scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_resume.py +190 -0
- scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_timeout.py +194 -0
- scalebox/api/client/client.py +288 -0
- scalebox/api/client/errors.py +16 -0
- scalebox/api/client/models/__init__.py +81 -0
- scalebox/api/client/models/build_log_entry.py +79 -0
- scalebox/api/client/models/created_access_token.py +100 -0
- scalebox/api/client/models/created_team_api_key.py +166 -0
- scalebox/api/client/models/error.py +67 -0
- scalebox/api/client/models/identifier_masking_details.py +83 -0
- scalebox/api/client/models/listed_sandbox.py +138 -0
- scalebox/api/client/models/log_level.py +11 -0
- scalebox/api/client/models/new_access_token.py +59 -0
- scalebox/api/client/models/new_sandbox.py +125 -0
- scalebox/api/client/models/new_team_api_key.py +59 -0
- scalebox/api/client/models/node.py +154 -0
- scalebox/api/client/models/node_detail.py +152 -0
- scalebox/api/client/models/node_status.py +11 -0
- scalebox/api/client/models/node_status_change.py +61 -0
- scalebox/api/client/models/post_sandboxes_sandbox_id_refreshes_body.py +59 -0
- scalebox/api/client/models/post_sandboxes_sandbox_id_timeout_body.py +59 -0
- scalebox/api/client/models/resumed_sandbox.py +68 -0
- scalebox/api/client/models/sandbox.py +125 -0
- scalebox/api/client/models/sandbox_detail.py +178 -0
- scalebox/api/client/models/sandbox_log.py +70 -0
- scalebox/api/client/models/sandbox_logs.py +73 -0
- scalebox/api/client/models/sandbox_metric.py +110 -0
- scalebox/api/client/models/sandbox_state.py +9 -0
- scalebox/api/client/models/sandboxes_with_metrics.py +59 -0
- scalebox/api/client/models/team.py +83 -0
- scalebox/api/client/models/team_api_key.py +158 -0
- scalebox/api/client/models/team_user.py +68 -0
- scalebox/api/client/models/template.py +179 -0
- scalebox/api/client/models/template_build.py +117 -0
- scalebox/api/client/models/template_build_file_upload.py +70 -0
- scalebox/api/client/models/template_build_request.py +115 -0
- scalebox/api/client/models/template_build_request_v2.py +88 -0
- scalebox/api/client/models/template_build_start_v2.py +114 -0
- scalebox/api/client/models/template_build_status.py +11 -0
- scalebox/api/client/models/template_step.py +91 -0
- scalebox/api/client/models/template_update_request.py +59 -0
- scalebox/api/client/models/update_team_api_key.py +59 -0
- scalebox/api/client/py.typed +1 -0
- scalebox/api/client/types.py +46 -0
- scalebox/api/metadata.py +19 -0
- scalebox/cli.py +125 -0
- scalebox/client/__init__.py +0 -0
- scalebox/client/aclient.py +57 -0
- scalebox/client/api.proto +460 -0
- scalebox/client/buf.gen.yaml +8 -0
- scalebox/client/client.py +102 -0
- scalebox/client/requirements.txt +5 -0
- scalebox/code_interpreter/__init__.py +12 -0
- scalebox/code_interpreter/charts.py +230 -0
- scalebox/code_interpreter/code_interpreter_async.py +369 -0
- scalebox/code_interpreter/code_interpreter_sync.py +317 -0
- scalebox/code_interpreter/constants.py +3 -0
- scalebox/code_interpreter/exceptions.py +13 -0
- scalebox/code_interpreter/models.py +485 -0
- scalebox/connection_config.py +92 -0
- scalebox/csx_connect/__init__.py +1 -0
- scalebox/csx_connect/client.py +485 -0
- scalebox/csx_desktop/__init__.py +0 -0
- scalebox/csx_desktop/main.py +651 -0
- scalebox/exceptions.py +83 -0
- scalebox/generated/__init__.py +0 -0
- scalebox/generated/api.py +61 -0
- scalebox/generated/api_pb2.py +203 -0
- scalebox/generated/api_pb2.pyi +956 -0
- scalebox/generated/api_pb2_connect.py +1456 -0
- scalebox/generated/rpc.py +50 -0
- scalebox/generated/versions.py +3 -0
- scalebox/requirements.txt +36 -0
- scalebox/sandbox/__init__.py +0 -0
- scalebox/sandbox/commands/__init__.py +0 -0
- scalebox/sandbox/commands/command_handle.py +69 -0
- scalebox/sandbox/commands/main.py +39 -0
- scalebox/sandbox/filesystem/__init__.py +0 -0
- scalebox/sandbox/filesystem/filesystem.py +95 -0
- scalebox/sandbox/filesystem/watch_handle.py +60 -0
- scalebox/sandbox/main.py +139 -0
- scalebox/sandbox/sandbox_api.py +91 -0
- scalebox/sandbox/signature.py +40 -0
- scalebox/sandbox/utils.py +34 -0
- scalebox/sandbox_async/__init__.py +1 -0
- scalebox/sandbox_async/commands/command.py +307 -0
- scalebox/sandbox_async/commands/command_handle.py +187 -0
- scalebox/sandbox_async/commands/pty.py +187 -0
- scalebox/sandbox_async/filesystem/filesystem.py +557 -0
- scalebox/sandbox_async/filesystem/watch_handle.py +61 -0
- scalebox/sandbox_async/main.py +646 -0
- scalebox/sandbox_async/sandbox_api.py +365 -0
- scalebox/sandbox_async/utils.py +7 -0
- scalebox/sandbox_sync/__init__.py +2 -0
- scalebox/sandbox_sync/commands/__init__.py +0 -0
- scalebox/sandbox_sync/commands/command.py +300 -0
- scalebox/sandbox_sync/commands/command_handle.py +150 -0
- scalebox/sandbox_sync/commands/pty.py +181 -0
- scalebox/sandbox_sync/filesystem/__init__.py +0 -0
- scalebox/sandbox_sync/filesystem/filesystem.py +543 -0
- scalebox/sandbox_sync/filesystem/watch_handle.py +66 -0
- scalebox/sandbox_sync/main.py +790 -0
- scalebox/sandbox_sync/sandbox_api.py +356 -0
- scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -0
- scalebox/test/README.md +329 -0
- scalebox/test/__init__.py +0 -0
- scalebox/test/aclient.py +72 -0
- scalebox/test/code_interpreter_centext.py +21 -0
- scalebox/test/code_interpreter_centext_sync.py +21 -0
- scalebox/test/code_interpreter_test.py +34 -0
- scalebox/test/code_interpreter_test_sync.py +34 -0
- scalebox/test/run_all_validation_tests.py +334 -0
- scalebox/test/run_code_interpreter_tests.sh +67 -0
- scalebox/test/run_tests.sh +230 -0
- scalebox/test/test_basic.py +78 -0
- scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -0
- scalebox/test/test_code_interpreter_e2basync_comprehensive.py +2655 -0
- scalebox/test/test_code_interpreter_e2bsync_comprehensive.py +3416 -0
- scalebox/test/test_code_interpreter_sync_comprehensive.py +3412 -0
- scalebox/test/test_e2b_first.py +11 -0
- scalebox/test/test_sandbox_async_comprehensive.py +738 -0
- scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -0
- scalebox/test/test_sandbox_sync_comprehensive.py +770 -0
- scalebox/test/test_sandbox_usage_examples.py +987 -0
- scalebox/test/testacreate.py +24 -0
- scalebox/test/testagetinfo.py +18 -0
- scalebox/test/testcodeinterpreter_async.py +508 -0
- scalebox/test/testcodeinterpreter_sync.py +239 -0
- scalebox/test/testcomputeuse.py +243 -0
- scalebox/test/testnovnc.py +12 -0
- scalebox/test/testsandbox_async.py +118 -0
- scalebox/test/testsandbox_sync.py +38 -0
- scalebox/utils/__init__.py +0 -0
- scalebox/utils/httpcoreclient.py +297 -0
- scalebox/utils/httpxclient.py +403 -0
- scalebox/version.py +16 -0
- scalebox_sdk-0.1.0.dist-info/METADATA +292 -0
- scalebox_sdk-0.1.0.dist-info/RECORD +157 -0
- scalebox_sdk-0.1.0.dist-info/WHEEL +5 -0
- scalebox_sdk-0.1.0.dist-info/entry_points.txt +2 -0
- scalebox_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
- scalebox_sdk-0.1.0.dist-info/top_level.txt +1 -0
scalebox/__init__.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ScaleBox Python SDK
|
|
3
|
+
|
|
4
|
+
A multi-language code execution sandbox with support for:
|
|
5
|
+
- Python, R, Node.js, Deno/TypeScript, Java, and Bash
|
|
6
|
+
- Synchronous and asynchronous execution
|
|
7
|
+
- Persistent context across executions
|
|
8
|
+
- Rich result formats (text, HTML, Markdown, SVG, images, LaTeX, JSON, etc.)
|
|
9
|
+
- Real-time callbacks and monitoring
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
__author__ = "ScaleBox Team"
|
|
14
|
+
__email__ = "dev@scalebox.dev"
|
|
15
|
+
|
|
16
|
+
# API client imports
|
|
17
|
+
from .api.client import Client
|
|
18
|
+
from .api.client.errors import UnexpectedStatus
|
|
19
|
+
|
|
20
|
+
# Core imports
|
|
21
|
+
from .code_interpreter import AsyncSandbox, Sandbox
|
|
22
|
+
from .code_interpreter.models import (
|
|
23
|
+
Context,
|
|
24
|
+
Execution,
|
|
25
|
+
ExecutionError,
|
|
26
|
+
Logs,
|
|
27
|
+
MIMEType,
|
|
28
|
+
OutputHandler,
|
|
29
|
+
OutputMessage,
|
|
30
|
+
Result,
|
|
31
|
+
)
|
|
32
|
+
from .connection_config import ConnectionConfig
|
|
33
|
+
from .exceptions import (
|
|
34
|
+
AuthenticationException,
|
|
35
|
+
InvalidArgumentException,
|
|
36
|
+
NotEnoughSpaceException,
|
|
37
|
+
NotFoundException,
|
|
38
|
+
RateLimitException,
|
|
39
|
+
SandboxException,
|
|
40
|
+
TemplateException,
|
|
41
|
+
TimeoutException,
|
|
42
|
+
)
|
|
43
|
+
from .sandbox_async.main import AsyncSandbox as BaseAsyncSandbox
|
|
44
|
+
|
|
45
|
+
# Sandbox imports
|
|
46
|
+
from .sandbox_sync.main import Sandbox as BaseSandbox
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
# Version info
|
|
50
|
+
"__version__",
|
|
51
|
+
"__author__",
|
|
52
|
+
"__email__",
|
|
53
|
+
# Core classes
|
|
54
|
+
"Sandbox",
|
|
55
|
+
"AsyncSandbox",
|
|
56
|
+
"BaseSandbox",
|
|
57
|
+
"BaseAsyncSandbox",
|
|
58
|
+
"Client",
|
|
59
|
+
# Models
|
|
60
|
+
"Context",
|
|
61
|
+
"Execution",
|
|
62
|
+
"ExecutionError",
|
|
63
|
+
"Result",
|
|
64
|
+
"MIMEType",
|
|
65
|
+
"Logs",
|
|
66
|
+
"OutputHandler",
|
|
67
|
+
"OutputMessage",
|
|
68
|
+
# Exceptions
|
|
69
|
+
"SandboxException",
|
|
70
|
+
"TimeoutException",
|
|
71
|
+
"InvalidArgumentException",
|
|
72
|
+
"NotEnoughSpaceException",
|
|
73
|
+
"NotFoundException",
|
|
74
|
+
"AuthenticationException",
|
|
75
|
+
"TemplateException",
|
|
76
|
+
"RateLimitException",
|
|
77
|
+
"APIError",
|
|
78
|
+
# Configuration
|
|
79
|
+
"ConnectionConfig",
|
|
80
|
+
]
|
scalebox/api/__init__.py
ADDED
|
@@ -0,0 +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}")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Contains methods for accessing the API"""
|
|
File without changes
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, Optional, Union, cast
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from ... import errors
|
|
7
|
+
from ...client import AuthenticatedClient, Client
|
|
8
|
+
from ...models.error import Error
|
|
9
|
+
from ...types import Response
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _get_kwargs(
|
|
13
|
+
sandbox_id: str,
|
|
14
|
+
) -> dict[str, Any]:
|
|
15
|
+
_kwargs: dict[str, Any] = {
|
|
16
|
+
"method": "delete",
|
|
17
|
+
"url": f"/sandboxes/{sandbox_id}",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return _kwargs
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _parse_response(
|
|
24
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
25
|
+
) -> Optional[Union[Any, Error]]:
|
|
26
|
+
if response.status_code == 204:
|
|
27
|
+
response_204 = cast(Any, None)
|
|
28
|
+
return response_204
|
|
29
|
+
if response.status_code == 401:
|
|
30
|
+
response_401 = Error.from_dict(response.json())
|
|
31
|
+
|
|
32
|
+
return response_401
|
|
33
|
+
if response.status_code == 404:
|
|
34
|
+
response_404 = Error.from_dict(response.json())
|
|
35
|
+
|
|
36
|
+
return response_404
|
|
37
|
+
if response.status_code == 500:
|
|
38
|
+
response_500 = Error.from_dict(response.json())
|
|
39
|
+
|
|
40
|
+
return response_500
|
|
41
|
+
if client.raise_on_unexpected_status:
|
|
42
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
43
|
+
else:
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _build_response(
|
|
48
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
49
|
+
) -> Response[Union[Any, Error]]:
|
|
50
|
+
return Response(
|
|
51
|
+
status_code=HTTPStatus(response.status_code),
|
|
52
|
+
content=response.content,
|
|
53
|
+
headers=response.headers,
|
|
54
|
+
parsed=_parse_response(client=client, response=response),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def sync_detailed(
|
|
59
|
+
sandbox_id: str,
|
|
60
|
+
*,
|
|
61
|
+
client: AuthenticatedClient,
|
|
62
|
+
) -> Response[Union[Any, Error]]:
|
|
63
|
+
"""Kill a sandbox
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
sandbox_id (str):
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
70
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
Response[Union[Any, Error]]
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
kwargs = _get_kwargs(
|
|
77
|
+
sandbox_id=sandbox_id,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
response = client.get_httpx_client().request(
|
|
81
|
+
**kwargs,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
return _build_response(client=client, response=response)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def sync(
|
|
88
|
+
sandbox_id: str,
|
|
89
|
+
*,
|
|
90
|
+
client: AuthenticatedClient,
|
|
91
|
+
) -> Optional[Union[Any, Error]]:
|
|
92
|
+
"""Kill a sandbox
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
sandbox_id (str):
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
99
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Union[Any, Error]
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
return sync_detailed(
|
|
106
|
+
sandbox_id=sandbox_id,
|
|
107
|
+
client=client,
|
|
108
|
+
).parsed
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
async def asyncio_detailed(
|
|
112
|
+
sandbox_id: str,
|
|
113
|
+
*,
|
|
114
|
+
client: AuthenticatedClient,
|
|
115
|
+
) -> Response[Union[Any, Error]]:
|
|
116
|
+
"""Kill a sandbox
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
sandbox_id (str):
|
|
120
|
+
|
|
121
|
+
Raises:
|
|
122
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
123
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
Response[Union[Any, Error]]
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
kwargs = _get_kwargs(
|
|
130
|
+
sandbox_id=sandbox_id,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
134
|
+
|
|
135
|
+
return _build_response(client=client, response=response)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async def asyncio(
|
|
139
|
+
sandbox_id: str,
|
|
140
|
+
*,
|
|
141
|
+
client: AuthenticatedClient,
|
|
142
|
+
) -> Optional[Union[Any, Error]]:
|
|
143
|
+
"""Kill a sandbox
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
sandbox_id (str):
|
|
147
|
+
|
|
148
|
+
Raises:
|
|
149
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
150
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Union[Any, Error]
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
await asyncio_detailed(
|
|
158
|
+
sandbox_id=sandbox_id,
|
|
159
|
+
client=client,
|
|
160
|
+
)
|
|
161
|
+
).parsed
|
|
@@ -0,0 +1,176 @@
|
|
|
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.error import Error
|
|
9
|
+
from ...models.listed_sandbox import ListedSandbox
|
|
10
|
+
from ...types import UNSET, Response, Unset
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_kwargs(
|
|
14
|
+
*,
|
|
15
|
+
metadata: Union[Unset, str] = UNSET,
|
|
16
|
+
) -> dict[str, Any]:
|
|
17
|
+
params: dict[str, Any] = {}
|
|
18
|
+
|
|
19
|
+
params["metadata"] = metadata
|
|
20
|
+
|
|
21
|
+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
|
|
22
|
+
|
|
23
|
+
_kwargs: dict[str, Any] = {
|
|
24
|
+
"method": "get",
|
|
25
|
+
"url": "/sandboxes",
|
|
26
|
+
"params": params,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return _kwargs
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _parse_response(
|
|
33
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
34
|
+
) -> Optional[Union[Error, list["ListedSandbox"]]]:
|
|
35
|
+
if response.status_code == 200:
|
|
36
|
+
response_200 = []
|
|
37
|
+
_response_200 = response.json()
|
|
38
|
+
for response_200_item_data in _response_200:
|
|
39
|
+
response_200_item = ListedSandbox.from_dict(response_200_item_data)
|
|
40
|
+
|
|
41
|
+
response_200.append(response_200_item)
|
|
42
|
+
|
|
43
|
+
return response_200
|
|
44
|
+
if response.status_code == 400:
|
|
45
|
+
response_400 = Error.from_dict(response.json())
|
|
46
|
+
|
|
47
|
+
return response_400
|
|
48
|
+
if response.status_code == 401:
|
|
49
|
+
response_401 = Error.from_dict(response.json())
|
|
50
|
+
|
|
51
|
+
return response_401
|
|
52
|
+
if response.status_code == 500:
|
|
53
|
+
response_500 = Error.from_dict(response.json())
|
|
54
|
+
|
|
55
|
+
return response_500
|
|
56
|
+
if client.raise_on_unexpected_status:
|
|
57
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
58
|
+
else:
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _build_response(
|
|
63
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
|
64
|
+
) -> Response[Union[Error, list["ListedSandbox"]]]:
|
|
65
|
+
return Response(
|
|
66
|
+
status_code=HTTPStatus(response.status_code),
|
|
67
|
+
content=response.content,
|
|
68
|
+
headers=response.headers,
|
|
69
|
+
parsed=_parse_response(client=client, response=response),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def sync_detailed(
|
|
74
|
+
*,
|
|
75
|
+
client: AuthenticatedClient,
|
|
76
|
+
metadata: Union[Unset, str] = UNSET,
|
|
77
|
+
) -> Response[Union[Error, list["ListedSandbox"]]]:
|
|
78
|
+
"""List all running sandboxes
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
metadata (Union[Unset, str]):
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
85
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Response[Union[Error, list['ListedSandbox']]]
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
kwargs = _get_kwargs(
|
|
92
|
+
metadata=metadata,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
response = client.get_httpx_client().request(
|
|
96
|
+
**kwargs,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
return _build_response(client=client, response=response)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def sync(
|
|
103
|
+
*,
|
|
104
|
+
client: AuthenticatedClient,
|
|
105
|
+
metadata: Union[Unset, str] = UNSET,
|
|
106
|
+
) -> Optional[Union[Error, list["ListedSandbox"]]]:
|
|
107
|
+
"""List all running sandboxes
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
metadata (Union[Unset, str]):
|
|
111
|
+
|
|
112
|
+
Raises:
|
|
113
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
114
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
Union[Error, list['ListedSandbox']]
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
return sync_detailed(
|
|
121
|
+
client=client,
|
|
122
|
+
metadata=metadata,
|
|
123
|
+
).parsed
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
async def asyncio_detailed(
|
|
127
|
+
*,
|
|
128
|
+
client: AuthenticatedClient,
|
|
129
|
+
metadata: Union[Unset, str] = UNSET,
|
|
130
|
+
) -> Response[Union[Error, list["ListedSandbox"]]]:
|
|
131
|
+
"""List all running sandboxes
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
metadata (Union[Unset, str]):
|
|
135
|
+
|
|
136
|
+
Raises:
|
|
137
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
138
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
Response[Union[Error, list['ListedSandbox']]]
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
kwargs = _get_kwargs(
|
|
145
|
+
metadata=metadata,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
|
149
|
+
|
|
150
|
+
return _build_response(client=client, response=response)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
async def asyncio(
|
|
154
|
+
*,
|
|
155
|
+
client: AuthenticatedClient,
|
|
156
|
+
metadata: Union[Unset, str] = UNSET,
|
|
157
|
+
) -> Optional[Union[Error, list["ListedSandbox"]]]:
|
|
158
|
+
"""List all running sandboxes
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
metadata (Union[Unset, str]):
|
|
162
|
+
|
|
163
|
+
Raises:
|
|
164
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
165
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
Union[Error, list['ListedSandbox']]
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
await asyncio_detailed(
|
|
173
|
+
client=client,
|
|
174
|
+
metadata=metadata,
|
|
175
|
+
)
|
|
176
|
+
).parsed
|