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.
Files changed (157) hide show
  1. scalebox/__init__.py +80 -0
  2. scalebox/api/__init__.py +128 -0
  3. scalebox/api/client/__init__.py +8 -0
  4. scalebox/api/client/api/__init__.py +1 -0
  5. scalebox/api/client/api/sandboxes/__init__.py +0 -0
  6. scalebox/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py +161 -0
  7. scalebox/api/client/api/sandboxes/get_sandboxes.py +176 -0
  8. scalebox/api/client/api/sandboxes/get_sandboxes_metrics.py +173 -0
  9. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id.py +163 -0
  10. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py +199 -0
  11. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +214 -0
  12. scalebox/api/client/api/sandboxes/get_v2_sandboxes.py +229 -0
  13. scalebox/api/client/api/sandboxes/post_sandboxes.py +174 -0
  14. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_pause.py +165 -0
  15. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_refreshes.py +182 -0
  16. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_resume.py +190 -0
  17. scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_timeout.py +194 -0
  18. scalebox/api/client/client.py +288 -0
  19. scalebox/api/client/errors.py +16 -0
  20. scalebox/api/client/models/__init__.py +81 -0
  21. scalebox/api/client/models/build_log_entry.py +79 -0
  22. scalebox/api/client/models/created_access_token.py +100 -0
  23. scalebox/api/client/models/created_team_api_key.py +166 -0
  24. scalebox/api/client/models/error.py +67 -0
  25. scalebox/api/client/models/identifier_masking_details.py +83 -0
  26. scalebox/api/client/models/listed_sandbox.py +138 -0
  27. scalebox/api/client/models/log_level.py +11 -0
  28. scalebox/api/client/models/new_access_token.py +59 -0
  29. scalebox/api/client/models/new_sandbox.py +125 -0
  30. scalebox/api/client/models/new_team_api_key.py +59 -0
  31. scalebox/api/client/models/node.py +154 -0
  32. scalebox/api/client/models/node_detail.py +152 -0
  33. scalebox/api/client/models/node_status.py +11 -0
  34. scalebox/api/client/models/node_status_change.py +61 -0
  35. scalebox/api/client/models/post_sandboxes_sandbox_id_refreshes_body.py +59 -0
  36. scalebox/api/client/models/post_sandboxes_sandbox_id_timeout_body.py +59 -0
  37. scalebox/api/client/models/resumed_sandbox.py +68 -0
  38. scalebox/api/client/models/sandbox.py +125 -0
  39. scalebox/api/client/models/sandbox_detail.py +178 -0
  40. scalebox/api/client/models/sandbox_log.py +70 -0
  41. scalebox/api/client/models/sandbox_logs.py +73 -0
  42. scalebox/api/client/models/sandbox_metric.py +110 -0
  43. scalebox/api/client/models/sandbox_state.py +9 -0
  44. scalebox/api/client/models/sandboxes_with_metrics.py +59 -0
  45. scalebox/api/client/models/team.py +83 -0
  46. scalebox/api/client/models/team_api_key.py +158 -0
  47. scalebox/api/client/models/team_user.py +68 -0
  48. scalebox/api/client/models/template.py +179 -0
  49. scalebox/api/client/models/template_build.py +117 -0
  50. scalebox/api/client/models/template_build_file_upload.py +70 -0
  51. scalebox/api/client/models/template_build_request.py +115 -0
  52. scalebox/api/client/models/template_build_request_v2.py +88 -0
  53. scalebox/api/client/models/template_build_start_v2.py +114 -0
  54. scalebox/api/client/models/template_build_status.py +11 -0
  55. scalebox/api/client/models/template_step.py +91 -0
  56. scalebox/api/client/models/template_update_request.py +59 -0
  57. scalebox/api/client/models/update_team_api_key.py +59 -0
  58. scalebox/api/client/py.typed +1 -0
  59. scalebox/api/client/types.py +46 -0
  60. scalebox/api/metadata.py +19 -0
  61. scalebox/cli.py +125 -0
  62. scalebox/client/__init__.py +0 -0
  63. scalebox/client/aclient.py +57 -0
  64. scalebox/client/api.proto +460 -0
  65. scalebox/client/buf.gen.yaml +8 -0
  66. scalebox/client/client.py +102 -0
  67. scalebox/client/requirements.txt +5 -0
  68. scalebox/code_interpreter/__init__.py +12 -0
  69. scalebox/code_interpreter/charts.py +230 -0
  70. scalebox/code_interpreter/code_interpreter_async.py +369 -0
  71. scalebox/code_interpreter/code_interpreter_sync.py +317 -0
  72. scalebox/code_interpreter/constants.py +3 -0
  73. scalebox/code_interpreter/exceptions.py +13 -0
  74. scalebox/code_interpreter/models.py +485 -0
  75. scalebox/connection_config.py +92 -0
  76. scalebox/csx_connect/__init__.py +1 -0
  77. scalebox/csx_connect/client.py +485 -0
  78. scalebox/csx_desktop/__init__.py +0 -0
  79. scalebox/csx_desktop/main.py +651 -0
  80. scalebox/exceptions.py +83 -0
  81. scalebox/generated/__init__.py +0 -0
  82. scalebox/generated/api.py +61 -0
  83. scalebox/generated/api_pb2.py +203 -0
  84. scalebox/generated/api_pb2.pyi +956 -0
  85. scalebox/generated/api_pb2_connect.py +1456 -0
  86. scalebox/generated/rpc.py +50 -0
  87. scalebox/generated/versions.py +3 -0
  88. scalebox/requirements.txt +36 -0
  89. scalebox/sandbox/__init__.py +0 -0
  90. scalebox/sandbox/commands/__init__.py +0 -0
  91. scalebox/sandbox/commands/command_handle.py +69 -0
  92. scalebox/sandbox/commands/main.py +39 -0
  93. scalebox/sandbox/filesystem/__init__.py +0 -0
  94. scalebox/sandbox/filesystem/filesystem.py +95 -0
  95. scalebox/sandbox/filesystem/watch_handle.py +60 -0
  96. scalebox/sandbox/main.py +139 -0
  97. scalebox/sandbox/sandbox_api.py +91 -0
  98. scalebox/sandbox/signature.py +40 -0
  99. scalebox/sandbox/utils.py +34 -0
  100. scalebox/sandbox_async/__init__.py +1 -0
  101. scalebox/sandbox_async/commands/command.py +307 -0
  102. scalebox/sandbox_async/commands/command_handle.py +187 -0
  103. scalebox/sandbox_async/commands/pty.py +187 -0
  104. scalebox/sandbox_async/filesystem/filesystem.py +557 -0
  105. scalebox/sandbox_async/filesystem/watch_handle.py +61 -0
  106. scalebox/sandbox_async/main.py +646 -0
  107. scalebox/sandbox_async/sandbox_api.py +365 -0
  108. scalebox/sandbox_async/utils.py +7 -0
  109. scalebox/sandbox_sync/__init__.py +2 -0
  110. scalebox/sandbox_sync/commands/__init__.py +0 -0
  111. scalebox/sandbox_sync/commands/command.py +300 -0
  112. scalebox/sandbox_sync/commands/command_handle.py +150 -0
  113. scalebox/sandbox_sync/commands/pty.py +181 -0
  114. scalebox/sandbox_sync/filesystem/__init__.py +0 -0
  115. scalebox/sandbox_sync/filesystem/filesystem.py +543 -0
  116. scalebox/sandbox_sync/filesystem/watch_handle.py +66 -0
  117. scalebox/sandbox_sync/main.py +790 -0
  118. scalebox/sandbox_sync/sandbox_api.py +356 -0
  119. scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -0
  120. scalebox/test/README.md +329 -0
  121. scalebox/test/__init__.py +0 -0
  122. scalebox/test/aclient.py +72 -0
  123. scalebox/test/code_interpreter_centext.py +21 -0
  124. scalebox/test/code_interpreter_centext_sync.py +21 -0
  125. scalebox/test/code_interpreter_test.py +34 -0
  126. scalebox/test/code_interpreter_test_sync.py +34 -0
  127. scalebox/test/run_all_validation_tests.py +334 -0
  128. scalebox/test/run_code_interpreter_tests.sh +67 -0
  129. scalebox/test/run_tests.sh +230 -0
  130. scalebox/test/test_basic.py +78 -0
  131. scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -0
  132. scalebox/test/test_code_interpreter_e2basync_comprehensive.py +2655 -0
  133. scalebox/test/test_code_interpreter_e2bsync_comprehensive.py +3416 -0
  134. scalebox/test/test_code_interpreter_sync_comprehensive.py +3412 -0
  135. scalebox/test/test_e2b_first.py +11 -0
  136. scalebox/test/test_sandbox_async_comprehensive.py +738 -0
  137. scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -0
  138. scalebox/test/test_sandbox_sync_comprehensive.py +770 -0
  139. scalebox/test/test_sandbox_usage_examples.py +987 -0
  140. scalebox/test/testacreate.py +24 -0
  141. scalebox/test/testagetinfo.py +18 -0
  142. scalebox/test/testcodeinterpreter_async.py +508 -0
  143. scalebox/test/testcodeinterpreter_sync.py +239 -0
  144. scalebox/test/testcomputeuse.py +243 -0
  145. scalebox/test/testnovnc.py +12 -0
  146. scalebox/test/testsandbox_async.py +118 -0
  147. scalebox/test/testsandbox_sync.py +38 -0
  148. scalebox/utils/__init__.py +0 -0
  149. scalebox/utils/httpcoreclient.py +297 -0
  150. scalebox/utils/httpxclient.py +403 -0
  151. scalebox/version.py +16 -0
  152. scalebox_sdk-0.1.0.dist-info/METADATA +292 -0
  153. scalebox_sdk-0.1.0.dist-info/RECORD +157 -0
  154. scalebox_sdk-0.1.0.dist-info/WHEEL +5 -0
  155. scalebox_sdk-0.1.0.dist-info/entry_points.txt +2 -0
  156. scalebox_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
  157. scalebox_sdk-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,102 @@
1
+ import os
2
+ import sys
3
+
4
+ from utils.httpxclient import HTTPXClient
5
+
6
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "generated"))
7
+
8
+ import asyncio
9
+
10
+ import httpx
11
+ from generated import api_pb2
12
+ from generated.api_pb2_connect import AsyncFilesystemClient
13
+
14
+
15
+ # 自定义 HTTP 客户端适配器
16
+ class CustomHTTPClient:
17
+ def __init__(self):
18
+ self.client = httpx.Client()
19
+
20
+ def request(self, method, url, headers, content, timeout, extensions):
21
+ # 移除可能导致问题的参数或调整调用方式
22
+ # 根据 ConnectRPC 的实际需求调整
23
+ try:
24
+ response = self.client.request(
25
+ method=method,
26
+ url=url,
27
+ headers=headers,
28
+ content=content,
29
+ timeout=timeout,
30
+ )
31
+ return response
32
+ except TypeError as e:
33
+ # 如果仍然有参数问题,尝试不同的调用方式
34
+ if "unexpected keyword argument" in str(e):
35
+ # 移除有问题的参数
36
+ kwargs = {
37
+ "method": method,
38
+ "url": url,
39
+ "headers": headers,
40
+ "content": content,
41
+ "timeout": timeout,
42
+ }
43
+ # 移除可能引起问题的参数
44
+ if "body" in str(e):
45
+ kwargs.pop("content", None)
46
+
47
+ response = self.client.request(**kwargs)
48
+ return response
49
+ raise
50
+
51
+
52
+ async def main():
53
+ # 创建客户端
54
+ client = AsyncFilesystemClient(
55
+ base_url="http://localhost:8080", http_client=HTTPXClient
56
+ )
57
+
58
+ # 调用服务器流式方法
59
+ # extra = {"Authorization": "Bearer root","Transfer-Encoding":"chunked",
60
+ # "Keepalive-Ping-Interval":1000}
61
+ extra = {"Authorization": "Bearer root"}
62
+ # resp=fs_cli.stat(api_pb2.StatRequest(path="/root/Dockerfile"),extra_headers=extra)
63
+ # print(resp)
64
+ # print(resp.entry)
65
+ # stream = fs_cli.watch_dir(api_pb2.WatchDirRequest(path="/root"), extra_headers=extra)
66
+ # request = RequestType(your_field="value")
67
+
68
+ # 处理流式响应
69
+ async for response in client.watch_dir(
70
+ api_pb2.WatchDirRequest(path="/root"), extra_headers=extra
71
+ ):
72
+ print(f"Received: {response}")
73
+ # 处理每个响应项
74
+
75
+
76
+ if __name__ == "__main__":
77
+ asyncio.run(main())
78
+
79
+ # print("Available protocol options:")
80
+ # print(f"CONNECT_PROTOBUF: {ConnectProtocol.CONNECT_PROTOBUF}")
81
+ # print(f"CONNECT_JSON: {ConnectProtocol.CONNECT_JSON}")
82
+ # # print(f"GRPC_PROTOBUF: {ConnectProtocol.GRPC_PROTOBUF}")
83
+ # # print(f"GRPC_JSON: {ConnectProtocol.GRPC_JSON}")
84
+ # BASE = "http://localhost:8080"
85
+ # # client = CustomHTTPClient()
86
+ # fs_cli=FilesystemClient(base_url=BASE,protocol=ConnectProtocol.CONNECT_PROTOBUF)
87
+ # # extra = {"Authorization": "Bearer root","Transfer-Encoding":"chunked",
88
+ # # "Keepalive-Ping-Interval":1000}
89
+ # extra = {"Authorization": "Bearer root"}
90
+ # # resp=fs_cli.stat(api_pb2.StatRequest(path="/root/Dockerfile"),extra_headers=extra)
91
+ # # print(resp)
92
+ # # print(resp.entry)
93
+ # stream=fs_cli.watch_dir(api_pb2.WatchDirRequest(path="/root"),extra_headers=extra)
94
+ # # 3. 消费流
95
+ # print("-------------------------")
96
+ # for resp in stream:
97
+ # # resp 就是 api_pb2.WatchDirResponse
98
+ # print(resp)
99
+ #
100
+ # # 4. 检查错误(可选)
101
+ # if stream.error():
102
+ # raise stream.error()
@@ -0,0 +1,5 @@
1
+ connect-python[protobuf]>=0.4.2
2
+ protobuf>=4.21
3
+ httpx>=0.24
4
+ grpcio>=1.74.0
5
+ grpcio-tools>=1.74.0
@@ -0,0 +1,12 @@
1
+ from .code_interpreter_async import AsyncSandbox
2
+ from .code_interpreter_sync import Sandbox
3
+ from .models import (
4
+ Context,
5
+ Execution,
6
+ ExecutionError,
7
+ Logs,
8
+ MIMEType,
9
+ OutputHandler,
10
+ OutputMessage,
11
+ Result,
12
+ )
@@ -0,0 +1,230 @@
1
+ import enum
2
+ from typing import Any, List, Optional, Tuple, Union
3
+
4
+
5
+ class ChartType(str, enum.Enum):
6
+ """
7
+ Chart types
8
+ """
9
+
10
+ LINE = "line"
11
+ SCATTER = "scatter"
12
+ BAR = "bar"
13
+ PIE = "pie"
14
+ BOX_AND_WHISKER = "box_and_whisker"
15
+ SUPERCHART = "superchart"
16
+ UNKNOWN = "unknown"
17
+
18
+
19
+ class ScaleType(str, enum.Enum):
20
+ """
21
+ Ax scale types
22
+ """
23
+
24
+ LINEAR = "linear"
25
+ DATETIME = "datetime"
26
+ CATEGORICAL = "categorical"
27
+ LOG = "log"
28
+ SYMLOG = "symlog"
29
+ LOGIT = "logit"
30
+ FUNCTION = "function"
31
+ FUNCTIONLOG = "functionlog"
32
+ ASINH = "asinh"
33
+ UNKNOWN = "unknown"
34
+
35
+
36
+ class Chart:
37
+ """
38
+ Extracted data from a chart. It's useful for building an interactive charts or custom visualizations.
39
+ """
40
+
41
+ type: ChartType
42
+ title: str
43
+
44
+ elements: List[Any]
45
+
46
+ def __init__(self, **kwargs) -> None:
47
+ self._raw_data = kwargs
48
+ self.type = ChartType(kwargs["type"] or ChartType.UNKNOWN)
49
+ self.title = kwargs["title"]
50
+ self.elements = kwargs["elements"]
51
+
52
+ def to_dict(self) -> dict:
53
+ return self._raw_data
54
+
55
+
56
+ class Chart2D(Chart):
57
+ x_label: Optional[str]
58
+ y_label: Optional[str]
59
+ x_unit: Optional[str]
60
+ y_unit: Optional[str]
61
+
62
+ def __init__(self, **kwargs) -> None:
63
+ super().__init__(**kwargs)
64
+ self.x_label = kwargs["x_label"]
65
+ self.y_label = kwargs["y_label"]
66
+ self.x_unit = kwargs["x_unit"]
67
+ self.y_unit = kwargs["y_unit"]
68
+
69
+
70
+ class PointData:
71
+ label: str
72
+ points: List[Tuple[Union[str, float], Union[str, float]]]
73
+
74
+ def __init__(self, **kwargs) -> None:
75
+ self.label = kwargs["label"]
76
+ self.points = [(x, y) for x, y in kwargs["points"]]
77
+
78
+
79
+ class PointChart(Chart2D):
80
+ x_ticks: List[Union[str, float]]
81
+ x_tick_labels: List[str]
82
+ x_scale: ScaleType
83
+
84
+ y_ticks: List[Union[str, float]]
85
+ y_tick_labels: List[str]
86
+ y_scale: ScaleType
87
+
88
+ elements: List[PointData]
89
+
90
+ def __init__(self, **kwargs) -> None:
91
+ super().__init__(**kwargs)
92
+ self.x_label = kwargs["x_label"]
93
+
94
+ try:
95
+ self.x_scale = ScaleType(kwargs.get("x_scale"))
96
+ except ValueError:
97
+ self.x_scale = ScaleType.UNKNOWN
98
+
99
+ self.x_ticks = kwargs["x_ticks"]
100
+ self.x_tick_labels = kwargs["x_tick_labels"]
101
+
102
+ self.y_label = kwargs["y_label"]
103
+
104
+ try:
105
+ self.y_scale = ScaleType(kwargs.get("y_scale"))
106
+ except ValueError:
107
+ self.y_scale = ScaleType.UNKNOWN
108
+
109
+ self.y_ticks = kwargs["y_ticks"]
110
+ self.y_tick_labels = kwargs["y_tick_labels"]
111
+
112
+ self.elements = [PointData(**d) for d in kwargs["elements"]]
113
+
114
+
115
+ class LineChart(PointChart):
116
+ type = ChartType.LINE
117
+
118
+
119
+ class ScatterChart(PointChart):
120
+ type = ChartType.SCATTER
121
+
122
+
123
+ class BarData:
124
+ label: str
125
+ group: str
126
+ value: str
127
+
128
+ def __init__(self, **kwargs) -> None:
129
+ self.label = kwargs["label"]
130
+ self.value = kwargs["value"]
131
+ self.group = kwargs["group"]
132
+
133
+
134
+ class BarChart(Chart2D):
135
+ type = ChartType.BAR
136
+
137
+ elements: List[BarData]
138
+
139
+ def __init__(self, **kwargs) -> None:
140
+ super().__init__(**kwargs)
141
+ self.elements = [BarData(**d) for d in kwargs["elements"]]
142
+
143
+
144
+ class PieData:
145
+ label: str
146
+ angle: float
147
+ radius: float
148
+
149
+ def __init__(self, **kwargs) -> None:
150
+ self.label = kwargs["label"]
151
+ self.angle = kwargs["angle"]
152
+ self.radius = kwargs["radius"]
153
+
154
+
155
+ class PieChart(Chart):
156
+ type = ChartType.PIE
157
+
158
+ elements: List[PieData]
159
+
160
+ def __init__(self, **kwargs) -> None:
161
+ super().__init__(**kwargs)
162
+ self.elements = [PieData(**d) for d in kwargs["elements"]]
163
+
164
+
165
+ class BoxAndWhiskerData:
166
+ label: str
167
+ min: float
168
+ first_quartile: float
169
+ median: float
170
+ third_quartile: float
171
+ max: float
172
+ outliers: List[float]
173
+
174
+ def __init__(self, **kwargs) -> None:
175
+ self.label = kwargs["label"]
176
+ self.min = kwargs["min"]
177
+ self.first_quartile = kwargs["first_quartile"]
178
+ self.median = kwargs["median"]
179
+ self.third_quartile = kwargs["third_quartile"]
180
+ self.max = kwargs["max"]
181
+ self.outliers = kwargs.get("outliers") or []
182
+
183
+
184
+ class BoxAndWhiskerChart(Chart2D):
185
+ type = ChartType.BOX_AND_WHISKER
186
+
187
+ elements: List[BoxAndWhiskerData]
188
+
189
+ def __init__(self, **kwargs) -> None:
190
+ super().__init__(**kwargs)
191
+ self.elements = [BoxAndWhiskerData(**d) for d in kwargs["elements"]]
192
+
193
+
194
+ class SuperChart(Chart):
195
+ type = ChartType.SUPERCHART
196
+
197
+ elements: List[
198
+ Union[LineChart, ScatterChart, BarChart, PieChart, BoxAndWhiskerChart]
199
+ ]
200
+
201
+ def __init__(self, **kwargs) -> None:
202
+ super().__init__(**kwargs)
203
+ self.elements = [_deserialize_chart(g) for g in kwargs["elements"]]
204
+
205
+
206
+ ChartTypes = Union[
207
+ LineChart, ScatterChart, BarChart, PieChart, BoxAndWhiskerChart, SuperChart
208
+ ]
209
+
210
+
211
+ def _deserialize_chart(data: Optional[dict]) -> Optional[ChartTypes]:
212
+ if not data:
213
+ return None
214
+
215
+ if data["type"] == ChartType.LINE:
216
+ chart = LineChart(**data)
217
+ elif data["type"] == ChartType.SCATTER:
218
+ chart = ScatterChart(**data)
219
+ elif data["type"] == ChartType.BAR:
220
+ chart = BarChart(**data)
221
+ elif data["type"] == ChartType.PIE:
222
+ chart = PieChart(**data)
223
+ elif data["type"] == ChartType.BOX_AND_WHISKER:
224
+ chart = BoxAndWhiskerChart(**data)
225
+ elif data["type"] == ChartType.SUPERCHART:
226
+ chart = SuperChart(**data)
227
+ else:
228
+ chart = Chart(**data)
229
+
230
+ return chart