computesdk 0.1.0__tar.gz

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.
@@ -0,0 +1,16 @@
1
+ # ComputeSDK API Key (required for integration tests)
2
+ COMPUTESDK_API_KEY="your-computesdk-api-key"
3
+
4
+ # Provider credentials (set at least one)
5
+
6
+ # E2B
7
+ E2B_API_KEY="your-e2b-key"
8
+
9
+ # Modal
10
+ MODAL_TOKEN_ID="your-modal-token-id"
11
+ MODAL_TOKEN_SECRET="your-modal-token-secret"
12
+
13
+ # Railway
14
+ RAILWAY_API_KEY="your-railway-key"
15
+ RAILWAY_PROJECT_ID="your-project-id"
16
+ RAILWAY_ENVIRONMENT_ID="your-env-id"
@@ -0,0 +1,85 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ *.egg
25
+
26
+ # PyInstaller
27
+ *.manifest
28
+ *.spec
29
+
30
+ # Installer logs
31
+ pip-log.txt
32
+ pip-delete-this-directory.txt
33
+
34
+ # Unit test / coverage reports
35
+ htmlcov/
36
+ .tox/
37
+ .nox/
38
+ .coverage
39
+ .coverage.*
40
+ .cache
41
+ nosetests.xml
42
+ coverage.xml
43
+ *.cover
44
+ *.py,cover
45
+ .hypothesis/
46
+ .pytest_cache/
47
+
48
+ # Translations
49
+ *.mo
50
+ *.pot
51
+
52
+ # Environments
53
+ .env
54
+ .venv
55
+ env/
56
+ venv/
57
+ ENV/
58
+ env.bak/
59
+ venv.bak/
60
+
61
+ # IDEs
62
+ .idea/
63
+ .vscode/
64
+ *.swp
65
+ *.swo
66
+ *~
67
+
68
+ # mypy
69
+ .mypy_cache/
70
+ .dmypy.json
71
+ dmypy.json
72
+
73
+ # ruff
74
+ .ruff_cache/
75
+
76
+ # Jupyter Notebook
77
+ .ipynb_checkpoints
78
+
79
+ # OS
80
+ .DS_Store
81
+ Thumbs.db
82
+
83
+ .claude
84
+ PYTHON_SDK_PLAN.md
85
+ TESTING.md
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ComputeSDK Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,387 @@
1
+ Metadata-Version: 2.4
2
+ Name: computesdk
3
+ Version: 0.1.0
4
+ Summary: A unified SDK for running code in remote sandboxes
5
+ Project-URL: Homepage, https://github.com/computesdk/computesdk
6
+ Project-URL: Documentation, https://docs.computesdk.com
7
+ Project-URL: Repository, https://github.com/computesdk/computesdk
8
+ Author: ComputeSDK Team
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai,cloud,code-execution,llm,remote-execution,sandbox
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: httpx>=0.25.0
26
+ Requires-Dist: websockets>=12.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: mypy>=1.8; extra == 'dev'
29
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
30
+ Requires-Dist: pytest>=8.0; extra == 'dev'
31
+ Requires-Dist: python-dotenv>=1.0; extra == 'dev'
32
+ Requires-Dist: ruff>=0.2; extra == 'dev'
33
+ Provides-Extra: publish
34
+ Requires-Dist: build>=1.0; extra == 'publish'
35
+ Requires-Dist: twine>=5.0; extra == 'publish'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # ComputeSDK Python
39
+
40
+ Official Python SDK for the ComputeSDK gateway — run code in remote sandboxes across multiple cloud providers.
41
+
42
+ ComputeSDK provides a unified interface for executing code, running commands, and managing files in isolated sandbox environments. Connect to providers like E2B, Modal, Railway, Daytona, and more through a single, consistent API.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install git+https://github.com/computesdk/computesdk-py.git
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ```python
53
+ import asyncio
54
+ from computesdk import compute
55
+
56
+ async def main():
57
+ # Create a sandbox (auto-configured from environment variables)
58
+ sandbox = await compute.sandbox.create()
59
+
60
+ try:
61
+ # Execute Python code
62
+ result = await sandbox.run_code('print("Hello, World!")', 'python')
63
+ print(result.output) # Hello, World!
64
+
65
+ # Execute shell commands
66
+ cmd = await sandbox.run_command('ls -la')
67
+ print(cmd.stdout)
68
+
69
+ finally:
70
+ await sandbox.destroy()
71
+
72
+ asyncio.run(main())
73
+ ```
74
+
75
+ ## Configuration
76
+
77
+ ### Environment Variables (Recommended)
78
+
79
+ Set your API keys as environment variables:
80
+
81
+ ```bash
82
+ # Required: ComputeSDK API key
83
+ export COMPUTESDK_API_KEY="your-computesdk-api-key"
84
+
85
+ # Provider credentials (set one of these based on your provider)
86
+ export E2B_API_KEY="your-e2b-key"
87
+ # OR
88
+ export MODAL_TOKEN_ID="your-modal-token-id"
89
+ export MODAL_TOKEN_SECRET="your-modal-token-secret"
90
+ # OR
91
+ export RAILWAY_API_KEY="your-railway-key"
92
+ export RAILWAY_PROJECT_ID="your-project-id"
93
+ export RAILWAY_ENVIRONMENT_ID="your-env-id"
94
+ # etc.
95
+ ```
96
+
97
+ The SDK will automatically detect your provider based on which credentials are set.
98
+
99
+ ### Explicit Configuration
100
+
101
+ ```python
102
+ from computesdk import Compute, GatewayConfig
103
+
104
+ config = GatewayConfig(
105
+ api_key="your-computesdk-api-key",
106
+ provider="e2b",
107
+ provider_headers={"X-E2B-API-Key": "your-e2b-key"},
108
+ )
109
+
110
+ compute = Compute(config=config)
111
+ sandbox = await compute.sandbox.create()
112
+ ```
113
+
114
+ ## Features
115
+
116
+ ### Code Execution
117
+
118
+ ```python
119
+ # Python
120
+ result = await sandbox.run_code('''
121
+ import sys
122
+ print(f"Python {sys.version}")
123
+ ''', 'python')
124
+
125
+ # Node.js
126
+ result = await sandbox.run_code('console.log("Hello from Node!")', 'node')
127
+ ```
128
+
129
+ ### Command Execution
130
+
131
+ ```python
132
+ from computesdk import RunCommandOptions
133
+
134
+ # Simple command
135
+ result = await sandbox.run_command('echo "Hello"')
136
+ print(result.stdout)
137
+
138
+ # With options
139
+ result = await sandbox.run_command(
140
+ 'npm install',
141
+ RunCommandOptions(cwd='/app', timeout=60000)
142
+ )
143
+ ```
144
+
145
+ ### File System Operations
146
+
147
+ ```python
148
+ # Write files
149
+ await sandbox.filesystem.write_file('/app/main.py', 'print("Hello")')
150
+
151
+ # Read files
152
+ content = await sandbox.filesystem.read_file('/app/main.py')
153
+
154
+ # List directory
155
+ entries = await sandbox.filesystem.readdir('/app')
156
+ for entry in entries:
157
+ print(f"{entry.type}: {entry.name}")
158
+
159
+ # Check existence
160
+ exists = await sandbox.filesystem.exists('/app/main.py')
161
+
162
+ # Delete files
163
+ await sandbox.filesystem.remove('/app/main.py')
164
+
165
+ # Batch write
166
+ await sandbox.filesystem.batch_write([
167
+ {"path": "/app/a.py", "content": "# file a"},
168
+ {"path": "/app/b.py", "content": "# file b"},
169
+ ])
170
+ ```
171
+
172
+ ### Named Sandboxes
173
+
174
+ Named sandboxes persist across sessions:
175
+
176
+ ```python
177
+ # Find or create a named sandbox
178
+ sandbox = await compute.sandbox.find_or_create(
179
+ name="my-dev-sandbox",
180
+ namespace="development",
181
+ )
182
+
183
+ # Find an existing sandbox
184
+ sandbox = await compute.sandbox.find(
185
+ name="my-dev-sandbox",
186
+ namespace="development",
187
+ )
188
+ ```
189
+
190
+ ### Terminal Sessions
191
+
192
+ ```python
193
+ from computesdk import CreateTerminalOptions
194
+
195
+ # Create a terminal
196
+ terminal = await sandbox.create_terminal(
197
+ CreateTerminalOptions(shell="/bin/bash", pty=True)
198
+ )
199
+
200
+ # Execute commands
201
+ result = await sandbox.execute_in_terminal(
202
+ terminal.id,
203
+ "npm test",
204
+ background=False
205
+ )
206
+
207
+ # List terminals
208
+ terminals = await sandbox.list_terminals()
209
+
210
+ # Destroy terminal
211
+ await sandbox.destroy_terminal(terminal.id)
212
+ ```
213
+
214
+ ### WIP - Server Management
215
+
216
+ ```python
217
+ from computesdk import StartServerOptions
218
+
219
+ # Start a server
220
+ server = await sandbox.start_server(StartServerOptions(
221
+ slug="api",
222
+ command="node server.js",
223
+ path="/app",
224
+ ))
225
+
226
+ # Get public URL
227
+ url = await sandbox.get_url(port=3000)
228
+ print(f"Server available at: {url}")
229
+
230
+ # List servers
231
+ servers = await sandbox.list_servers()
232
+
233
+ # Stop server
234
+ await sandbox.stop_server("api")
235
+ ```
236
+
237
+ ### File Watchers
238
+
239
+ ```python
240
+ from computesdk import CreateWatcherOptions
241
+
242
+ # Create a file watcher
243
+ watcher = await sandbox.create_watcher(
244
+ "/app",
245
+ CreateWatcherOptions(
246
+ include_content=True,
247
+ ignored=["node_modules", ".git"],
248
+ )
249
+ )
250
+
251
+ # Use WebSocket to receive events
252
+ # watcher.ws_url and watcher.channel for real-time updates
253
+
254
+ # Destroy watcher
255
+ await sandbox.destroy_watcher(watcher.id)
256
+ ```
257
+
258
+ ### WIP - Session Tokens
259
+
260
+ ```python
261
+ from computesdk import CreateSessionTokenOptions
262
+
263
+ # Create a session token
264
+ token = await sandbox.create_session_token(
265
+ CreateSessionTokenOptions(
266
+ description="My App Token",
267
+ expires_in=604800, # 7 days
268
+ )
269
+ )
270
+ print(f"Token: {token.token}")
271
+
272
+ # Use the token
273
+ sandbox.set_token(token.token)
274
+
275
+ # List and revoke tokens
276
+ tokens = await sandbox.list_session_tokens()
277
+ await sandbox.revoke_session_token(token.id)
278
+ ```
279
+
280
+
281
+ ## Supported Providers
282
+
283
+ | Provider | Environment Variables |
284
+ |----------|----------------------|
285
+ | E2B | `E2B_API_KEY` |
286
+ | Modal | `MODAL_TOKEN_ID`, `MODAL_TOKEN_SECRET` |
287
+ | Railway | `RAILWAY_API_KEY`, `RAILWAY_PROJECT_ID`, `RAILWAY_ENVIRONMENT_ID` |
288
+ | Daytona | `DAYTONA_API_KEY` |
289
+ | Vercel | `VERCEL_TOKEN`, `VERCEL_TEAM_ID`, `VERCEL_PROJECT_ID` |
290
+
291
+
292
+ ## Error Handling
293
+
294
+ ```python
295
+ from computesdk import (
296
+ ComputeSDKError,
297
+ AuthenticationError,
298
+ NotFoundError,
299
+ TimeoutError,
300
+ )
301
+
302
+ try:
303
+ sandbox = await compute.sandbox.create()
304
+ result = await sandbox.run_code('print("Hello")', 'python')
305
+ except AuthenticationError:
306
+ print("Invalid API key")
307
+ except NotFoundError:
308
+ print("Sandbox not found")
309
+ except TimeoutError:
310
+ print("Request timed out")
311
+ except ComputeSDKError as e:
312
+ print(f"Error: {e}")
313
+ ```
314
+
315
+ ## API Reference
316
+
317
+ ### Sandbox Methods
318
+
319
+ | Method | Description |
320
+ |--------|-------------|
321
+ | `run_code(code, language)` | Execute code in the sandbox |
322
+ | `run_command(command, options)` | Execute a shell command |
323
+ | `get_info()` | Get sandbox information |
324
+ | `get_url(port, protocol)` | Get public URL for a service |
325
+ | `destroy()` | Destroy the sandbox |
326
+ | `extend(duration)` | WIP Extend sandbox timeout |
327
+ | `health()` | Check sandbox health |
328
+
329
+ ### FileSystem Methods
330
+
331
+ | Method | Description |
332
+ |--------|-------------|
333
+ | `read_file(path)` | Read file contents |
334
+ | `write_file(path, content)` | Write to a file |
335
+ | `readdir(path)` | List directory contents |
336
+ | `mkdir(path)` | Create a directory |
337
+ | `exists(path)` | Check if path exists |
338
+ | `remove(path)` | Delete file or directory |
339
+ | `batch_write(files)` | Write multiple files |
340
+
341
+ ### Terminal Methods
342
+
343
+ | Method | Description |
344
+ |--------|-------------|
345
+ | `create_terminal(options)` | Create a terminal session |
346
+ | `list_terminals()` | List all terminals |
347
+ | `get_terminal(id)` | Get terminal by ID |
348
+ | `destroy_terminal(id)` | Destroy a terminal |
349
+ | `execute_in_terminal(id, cmd)` | Execute command in terminal |
350
+
351
+ ### WIP Server Methods
352
+
353
+ | Method | Description |
354
+ |--------|-------------|
355
+ | `start_server(options)` | Start a server process |
356
+ | `list_servers()` | List all servers |
357
+ | `get_server(slug)` | Get server by slug |
358
+ | `stop_server(slug)` | Stop a server |
359
+ | `restart_server(slug)` | Restart a server |
360
+
361
+ ## Requirements
362
+
363
+ - Python >= 3.9
364
+ - httpx >= 0.25.0
365
+ - websockets >= 12.0 (optional, for real-time features)
366
+
367
+ ## Development
368
+
369
+ ```bash
370
+ # Clone the repository
371
+ git clone https://github.com/computesdk/computesdk
372
+ cd sdk/computesdk-py
373
+
374
+ # Create virtual environment
375
+ python3 -m venv venv
376
+ source venv/bin/activate
377
+
378
+ # Install with dev dependencies
379
+ pip install -e ".[dev]"
380
+
381
+ # Run tests
382
+ pytest
383
+ ```
384
+
385
+ ## License
386
+
387
+ MIT