ai-computer-client 0.3.1__py3-none-any.whl → 0.3.2__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.
- ai_computer/__init__.py +1 -1
- ai_computer/client.py +1 -1
- ai_computer_client-0.3.2.dist-info/METADATA +222 -0
- ai_computer_client-0.3.2.dist-info/RECORD +6 -0
- ai_computer_client-0.3.1.dist-info/METADATA +0 -147
- ai_computer_client-0.3.1.dist-info/RECORD +0 -6
- {ai_computer_client-0.3.1.dist-info → ai_computer_client-0.3.2.dist-info}/WHEEL +0 -0
- {ai_computer_client-0.3.1.dist-info → ai_computer_client-0.3.2.dist-info}/licenses/LICENSE +0 -0
ai_computer/__init__.py
CHANGED
ai_computer/client.py
CHANGED
@@ -0,0 +1,222 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: ai-computer-client
|
3
|
+
Version: 0.3.2
|
4
|
+
Summary: Python client for interacting with the AI Computer service
|
5
|
+
Project-URL: Homepage, https://github.com/ColeMurray/ai-computer-client-python
|
6
|
+
Project-URL: Documentation, https://github.com/ColeMurray/ai-computer-client-python#readme
|
7
|
+
Author: AI Computer
|
8
|
+
License: MIT
|
9
|
+
License-File: LICENSE
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3.7
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
19
|
+
Requires-Python: >=3.7
|
20
|
+
Requires-Dist: aiohttp>=3.8.0
|
21
|
+
Requires-Dist: typing-extensions>=4.0.0
|
22
|
+
Provides-Extra: dev
|
23
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
24
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
25
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
26
|
+
Description-Content-Type: text/markdown
|
27
|
+
|
28
|
+
# AI Computer Python Client
|
29
|
+
|
30
|
+
A Python client for interacting with the AI Computer service. This client provides a simple interface for executing Python code in an isolated sandbox environment.
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
```bash
|
35
|
+
pip install ai-computer-client
|
36
|
+
```
|
37
|
+
|
38
|
+
## Quick Start
|
39
|
+
|
40
|
+
```python
|
41
|
+
import asyncio
|
42
|
+
from ai_computer import SandboxClient
|
43
|
+
|
44
|
+
async def main():
|
45
|
+
# Initialize the client
|
46
|
+
client = SandboxClient()
|
47
|
+
|
48
|
+
# Setup the client (gets token and creates sandbox)
|
49
|
+
setup_response = await client.setup()
|
50
|
+
if not setup_response.success:
|
51
|
+
print(f"Setup failed: {setup_response.error}")
|
52
|
+
return
|
53
|
+
|
54
|
+
try:
|
55
|
+
# Example 1: Simple code execution
|
56
|
+
code = """x = 10
|
57
|
+
y = 20
|
58
|
+
result = x + y
|
59
|
+
print(f"The sum is: {result}")"""
|
60
|
+
|
61
|
+
print("\nExample 1: Simple execution")
|
62
|
+
print("-" * 50)
|
63
|
+
response = await client.execute_code(code)
|
64
|
+
if response.success:
|
65
|
+
print("Execution result:", response.data)
|
66
|
+
else:
|
67
|
+
print("Execution failed:", response.error)
|
68
|
+
|
69
|
+
# Example 2: Streaming execution
|
70
|
+
code = """import time
|
71
|
+
|
72
|
+
for i in range(5):
|
73
|
+
print(f"Processing step {i + 1}")
|
74
|
+
time.sleep(1) # Simulate work
|
75
|
+
|
76
|
+
result = "Calculation complete!"
|
77
|
+
print(result)"""
|
78
|
+
|
79
|
+
print("\nExample 2: Streaming execution")
|
80
|
+
print("-" * 50)
|
81
|
+
async for event in client.execute_code_stream(code):
|
82
|
+
if event.type == 'stdout':
|
83
|
+
print(f"Output: {event.data}")
|
84
|
+
elif event.type == 'stderr':
|
85
|
+
print(f"Error: {event.data}")
|
86
|
+
elif event.type == 'error':
|
87
|
+
print(f"Execution error: {event.data}")
|
88
|
+
break
|
89
|
+
elif event.type == 'completed':
|
90
|
+
print("Execution completed")
|
91
|
+
break
|
92
|
+
|
93
|
+
finally:
|
94
|
+
# Clean up
|
95
|
+
await client.cleanup()
|
96
|
+
|
97
|
+
if __name__ == "__main__":
|
98
|
+
asyncio.run(main())
|
99
|
+
```
|
100
|
+
|
101
|
+
Example output:
|
102
|
+
```
|
103
|
+
Example 1: Simple execution
|
104
|
+
--------------------------------------------------
|
105
|
+
Execution result: {'output': 'The sum is: 30\n', 'sandbox_id': '06a30496-b535-47b0-9fe7-34f7ec483cd7'}
|
106
|
+
|
107
|
+
Example 2: Streaming execution
|
108
|
+
--------------------------------------------------
|
109
|
+
Output: Processing step 1
|
110
|
+
Output: Processing step 2
|
111
|
+
Output: Processing step 3
|
112
|
+
Output: Processing step 4
|
113
|
+
Output: Processing step 5
|
114
|
+
Output: Calculation complete!
|
115
|
+
Execution completed
|
116
|
+
```
|
117
|
+
|
118
|
+
## Features
|
119
|
+
|
120
|
+
- Asynchronous API for efficient execution
|
121
|
+
- Real-time streaming of code output
|
122
|
+
- Automatic sandbox management
|
123
|
+
- Error handling and timeouts
|
124
|
+
- Type hints for better IDE support
|
125
|
+
|
126
|
+
## API Reference
|
127
|
+
|
128
|
+
### SandboxClient
|
129
|
+
|
130
|
+
The main client class for interacting with the AI Computer service.
|
131
|
+
|
132
|
+
```python
|
133
|
+
client = SandboxClient(base_url="http://api.aicomputer.dev")
|
134
|
+
```
|
135
|
+
|
136
|
+
#### Methods
|
137
|
+
|
138
|
+
##### `async setup() -> SandboxResponse`
|
139
|
+
Initialize the client and create a sandbox. This must be called before executing any code.
|
140
|
+
|
141
|
+
```python
|
142
|
+
response = await client.setup()
|
143
|
+
if response.success:
|
144
|
+
print("Sandbox ready")
|
145
|
+
```
|
146
|
+
|
147
|
+
##### `async execute_code(code: str, timeout: int = 30) -> SandboxResponse`
|
148
|
+
Execute Python code and return the combined output.
|
149
|
+
|
150
|
+
```python
|
151
|
+
code = """
|
152
|
+
x = 10
|
153
|
+
y = 20
|
154
|
+
result = x + y
|
155
|
+
print(f"The sum is: {result}")
|
156
|
+
"""
|
157
|
+
|
158
|
+
response = await client.execute_code(code)
|
159
|
+
if response.success:
|
160
|
+
print("Output:", response.data['output'])
|
161
|
+
```
|
162
|
+
|
163
|
+
##### `async execute_code_stream(code: str, timeout: int = 30) -> AsyncGenerator[StreamEvent, None]`
|
164
|
+
Execute Python code and stream the output in real-time.
|
165
|
+
|
166
|
+
```python
|
167
|
+
async for event in client.execute_code_stream(code):
|
168
|
+
if event.type == 'stdout':
|
169
|
+
print("Output:", event.data)
|
170
|
+
elif event.type == 'stderr':
|
171
|
+
print("Error:", event.data)
|
172
|
+
```
|
173
|
+
|
174
|
+
##### `async cleanup() -> SandboxResponse`
|
175
|
+
Delete the sandbox and clean up resources.
|
176
|
+
|
177
|
+
```python
|
178
|
+
await client.cleanup()
|
179
|
+
```
|
180
|
+
|
181
|
+
### Response Types
|
182
|
+
|
183
|
+
#### SandboxResponse
|
184
|
+
```python
|
185
|
+
@dataclass
|
186
|
+
class SandboxResponse:
|
187
|
+
success: bool
|
188
|
+
data: Optional[Dict] = None
|
189
|
+
error: Optional[str] = None
|
190
|
+
```
|
191
|
+
|
192
|
+
#### StreamEvent
|
193
|
+
```python
|
194
|
+
@dataclass
|
195
|
+
class StreamEvent:
|
196
|
+
type: str # 'stdout', 'stderr', 'error', 'completed'
|
197
|
+
data: str
|
198
|
+
```
|
199
|
+
|
200
|
+
## Development
|
201
|
+
|
202
|
+
### Running Tests
|
203
|
+
|
204
|
+
```bash
|
205
|
+
# Install development dependencies
|
206
|
+
pip install -e ".[dev]"
|
207
|
+
|
208
|
+
# Run tests
|
209
|
+
pytest
|
210
|
+
```
|
211
|
+
|
212
|
+
### Contributing
|
213
|
+
|
214
|
+
1. Fork the repository
|
215
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
216
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
217
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
218
|
+
5. Open a Pull Request
|
219
|
+
|
220
|
+
## License
|
221
|
+
|
222
|
+
MIT License
|
@@ -0,0 +1,6 @@
|
|
1
|
+
ai_computer/__init__.py,sha256=GlAloQ10Yg8fIBKNj9HXovNHWAq9PsazLtYCIS1jOig,197
|
2
|
+
ai_computer/client.py,sha256=fo0OxmbZPYsSCWeYWkBzEGGDQ7bvx0qqvijDkr8zO8M,28733
|
3
|
+
ai_computer_client-0.3.2.dist-info/METADATA,sha256=aFEKdik1aa7F2hBhhWImmdewJgekuXnqDU5QJoPKzpU,5658
|
4
|
+
ai_computer_client-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
+
ai_computer_client-0.3.2.dist-info/licenses/LICENSE,sha256=N_0S5G1Wik2LWVDViJMAM0Z-6vTBX1bvDjb8vouBA-c,1068
|
6
|
+
ai_computer_client-0.3.2.dist-info/RECORD,,
|
@@ -1,147 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: ai-computer-client
|
3
|
-
Version: 0.3.1
|
4
|
-
Summary: Python client for interacting with the AI Computer service
|
5
|
-
Project-URL: Homepage, https://github.com/ColeMurray/ai-computer-client-python
|
6
|
-
Project-URL: Documentation, https://github.com/ColeMurray/ai-computer-client-python#readme
|
7
|
-
Author: AI Computer
|
8
|
-
License: MIT
|
9
|
-
License-File: LICENSE
|
10
|
-
Classifier: Development Status :: 4 - Beta
|
11
|
-
Classifier: Intended Audience :: Developers
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
14
|
-
Classifier: Programming Language :: Python :: 3.7
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
19
|
-
Requires-Python: >=3.7
|
20
|
-
Requires-Dist: aiohttp>=3.8.0
|
21
|
-
Requires-Dist: typing-extensions>=4.0.0
|
22
|
-
Provides-Extra: dev
|
23
|
-
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
24
|
-
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
25
|
-
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
26
|
-
Description-Content-Type: text/markdown
|
27
|
-
|
28
|
-
# AI Computer Python Client
|
29
|
-
|
30
|
-
Python client library for interacting with the AI Computer Sandbox service.
|
31
|
-
|
32
|
-
## Installation
|
33
|
-
|
34
|
-
```bash
|
35
|
-
pip install ai-computer-client
|
36
|
-
```
|
37
|
-
|
38
|
-
## Usage
|
39
|
-
|
40
|
-
### Basic Usage
|
41
|
-
|
42
|
-
```python
|
43
|
-
from ai_computer import SandboxClient
|
44
|
-
|
45
|
-
async def main():
|
46
|
-
# Initialize client
|
47
|
-
client = SandboxClient()
|
48
|
-
|
49
|
-
# Setup sandbox environment
|
50
|
-
await client.setup()
|
51
|
-
|
52
|
-
try:
|
53
|
-
# Execute code
|
54
|
-
result = await client.execute_code("print('Hello, World!')")
|
55
|
-
print(result.data["output"])
|
56
|
-
|
57
|
-
# Upload a file
|
58
|
-
response = await client.upload_file("local/path/to/file.txt")
|
59
|
-
if response.success:
|
60
|
-
print(f"File uploaded to {response.path}")
|
61
|
-
|
62
|
-
# Download a file
|
63
|
-
response = await client.download_file(
|
64
|
-
"/workspace/file.txt",
|
65
|
-
"local/download/path.txt"
|
66
|
-
)
|
67
|
-
if response.success:
|
68
|
-
print(f"File downloaded to {response.path}")
|
69
|
-
|
70
|
-
# Work with bytes directly
|
71
|
-
content = b"Hello, World!"
|
72
|
-
response = await client.upload_bytes(
|
73
|
-
content=content,
|
74
|
-
filename="hello.txt"
|
75
|
-
)
|
76
|
-
|
77
|
-
# Download as bytes
|
78
|
-
content = await client.download_bytes("/workspace/hello.txt")
|
79
|
-
if isinstance(content, bytes):
|
80
|
-
print(content.decode())
|
81
|
-
|
82
|
-
finally:
|
83
|
-
# Cleanup
|
84
|
-
await client.cleanup()
|
85
|
-
|
86
|
-
# Run with asyncio
|
87
|
-
import asyncio
|
88
|
-
asyncio.run(main())
|
89
|
-
```
|
90
|
-
|
91
|
-
### Advanced Usage
|
92
|
-
|
93
|
-
```python
|
94
|
-
# Stream code execution
|
95
|
-
async for event in client.execute_code_stream("print('Hello')\nprint('World')"):
|
96
|
-
if event.type == "stdout":
|
97
|
-
print(f"Output: {event.data}")
|
98
|
-
elif event.type == "stderr":
|
99
|
-
print(f"Error: {event.data}")
|
100
|
-
elif event.type == "completed":
|
101
|
-
print("Execution completed")
|
102
|
-
|
103
|
-
# Upload with custom settings
|
104
|
-
response = await client.upload_file(
|
105
|
-
"file.txt",
|
106
|
-
destination="/workspace/custom/path",
|
107
|
-
chunk_size=2*1024*1024, # 2MB chunks
|
108
|
-
timeout=600 # 10 minutes
|
109
|
-
)
|
110
|
-
|
111
|
-
# Work with file-like objects
|
112
|
-
from io import BytesIO
|
113
|
-
|
114
|
-
buffer = BytesIO(b"Hello from buffer!")
|
115
|
-
response = await client.upload_bytes(
|
116
|
-
content=buffer,
|
117
|
-
filename="buffer.txt",
|
118
|
-
content_type="text/plain"
|
119
|
-
)
|
120
|
-
```
|
121
|
-
|
122
|
-
## Development
|
123
|
-
|
124
|
-
### Setup
|
125
|
-
|
126
|
-
```bash
|
127
|
-
# Clone the repository
|
128
|
-
git clone https://github.com/ai-computer/ai-computer-client-python
|
129
|
-
cd ai-computer-client-python
|
130
|
-
|
131
|
-
# Create and activate virtual environment
|
132
|
-
python -m venv venv
|
133
|
-
source venv/bin/activate # or `venv\Scripts\activate` on Windows
|
134
|
-
|
135
|
-
# Install development dependencies
|
136
|
-
pip install -e ".[dev]"
|
137
|
-
```
|
138
|
-
|
139
|
-
### Running Tests
|
140
|
-
|
141
|
-
```bash
|
142
|
-
pytest tests/
|
143
|
-
```
|
144
|
-
|
145
|
-
## License
|
146
|
-
|
147
|
-
MIT License
|
@@ -1,6 +0,0 @@
|
|
1
|
-
ai_computer/__init__.py,sha256=9slbwvU5DHW6aOeLy7qIFe7TQkXF3-kOMI2x82VqiAk,197
|
2
|
-
ai_computer/client.py,sha256=TwVsAmNjaj5MDytKZtoHefFJAwYyL2OndtVbY2YxJlM,28729
|
3
|
-
ai_computer_client-0.3.1.dist-info/METADATA,sha256=YDRTkYudV6X0SRLW0OECdduJgCc3dYITjTr99eat0ls,3754
|
4
|
-
ai_computer_client-0.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
-
ai_computer_client-0.3.1.dist-info/licenses/LICENSE,sha256=N_0S5G1Wik2LWVDViJMAM0Z-6vTBX1bvDjb8vouBA-c,1068
|
6
|
-
ai_computer_client-0.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|