ai-computer-client 0.3.1__tar.gz → 0.3.2__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,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,195 @@
1
+ # AI Computer Python Client
2
+
3
+ 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.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install ai-computer-client
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ import asyncio
15
+ from ai_computer import SandboxClient
16
+
17
+ async def main():
18
+ # Initialize the client
19
+ client = SandboxClient()
20
+
21
+ # Setup the client (gets token and creates sandbox)
22
+ setup_response = await client.setup()
23
+ if not setup_response.success:
24
+ print(f"Setup failed: {setup_response.error}")
25
+ return
26
+
27
+ try:
28
+ # Example 1: Simple code execution
29
+ code = """x = 10
30
+ y = 20
31
+ result = x + y
32
+ print(f"The sum is: {result}")"""
33
+
34
+ print("\nExample 1: Simple execution")
35
+ print("-" * 50)
36
+ response = await client.execute_code(code)
37
+ if response.success:
38
+ print("Execution result:", response.data)
39
+ else:
40
+ print("Execution failed:", response.error)
41
+
42
+ # Example 2: Streaming execution
43
+ code = """import time
44
+
45
+ for i in range(5):
46
+ print(f"Processing step {i + 1}")
47
+ time.sleep(1) # Simulate work
48
+
49
+ result = "Calculation complete!"
50
+ print(result)"""
51
+
52
+ print("\nExample 2: Streaming execution")
53
+ print("-" * 50)
54
+ async for event in client.execute_code_stream(code):
55
+ if event.type == 'stdout':
56
+ print(f"Output: {event.data}")
57
+ elif event.type == 'stderr':
58
+ print(f"Error: {event.data}")
59
+ elif event.type == 'error':
60
+ print(f"Execution error: {event.data}")
61
+ break
62
+ elif event.type == 'completed':
63
+ print("Execution completed")
64
+ break
65
+
66
+ finally:
67
+ # Clean up
68
+ await client.cleanup()
69
+
70
+ if __name__ == "__main__":
71
+ asyncio.run(main())
72
+ ```
73
+
74
+ Example output:
75
+ ```
76
+ Example 1: Simple execution
77
+ --------------------------------------------------
78
+ Execution result: {'output': 'The sum is: 30\n', 'sandbox_id': '06a30496-b535-47b0-9fe7-34f7ec483cd7'}
79
+
80
+ Example 2: Streaming execution
81
+ --------------------------------------------------
82
+ Output: Processing step 1
83
+ Output: Processing step 2
84
+ Output: Processing step 3
85
+ Output: Processing step 4
86
+ Output: Processing step 5
87
+ Output: Calculation complete!
88
+ Execution completed
89
+ ```
90
+
91
+ ## Features
92
+
93
+ - Asynchronous API for efficient execution
94
+ - Real-time streaming of code output
95
+ - Automatic sandbox management
96
+ - Error handling and timeouts
97
+ - Type hints for better IDE support
98
+
99
+ ## API Reference
100
+
101
+ ### SandboxClient
102
+
103
+ The main client class for interacting with the AI Computer service.
104
+
105
+ ```python
106
+ client = SandboxClient(base_url="http://api.aicomputer.dev")
107
+ ```
108
+
109
+ #### Methods
110
+
111
+ ##### `async setup() -> SandboxResponse`
112
+ Initialize the client and create a sandbox. This must be called before executing any code.
113
+
114
+ ```python
115
+ response = await client.setup()
116
+ if response.success:
117
+ print("Sandbox ready")
118
+ ```
119
+
120
+ ##### `async execute_code(code: str, timeout: int = 30) -> SandboxResponse`
121
+ Execute Python code and return the combined output.
122
+
123
+ ```python
124
+ code = """
125
+ x = 10
126
+ y = 20
127
+ result = x + y
128
+ print(f"The sum is: {result}")
129
+ """
130
+
131
+ response = await client.execute_code(code)
132
+ if response.success:
133
+ print("Output:", response.data['output'])
134
+ ```
135
+
136
+ ##### `async execute_code_stream(code: str, timeout: int = 30) -> AsyncGenerator[StreamEvent, None]`
137
+ Execute Python code and stream the output in real-time.
138
+
139
+ ```python
140
+ async for event in client.execute_code_stream(code):
141
+ if event.type == 'stdout':
142
+ print("Output:", event.data)
143
+ elif event.type == 'stderr':
144
+ print("Error:", event.data)
145
+ ```
146
+
147
+ ##### `async cleanup() -> SandboxResponse`
148
+ Delete the sandbox and clean up resources.
149
+
150
+ ```python
151
+ await client.cleanup()
152
+ ```
153
+
154
+ ### Response Types
155
+
156
+ #### SandboxResponse
157
+ ```python
158
+ @dataclass
159
+ class SandboxResponse:
160
+ success: bool
161
+ data: Optional[Dict] = None
162
+ error: Optional[str] = None
163
+ ```
164
+
165
+ #### StreamEvent
166
+ ```python
167
+ @dataclass
168
+ class StreamEvent:
169
+ type: str # 'stdout', 'stderr', 'error', 'completed'
170
+ data: str
171
+ ```
172
+
173
+ ## Development
174
+
175
+ ### Running Tests
176
+
177
+ ```bash
178
+ # Install development dependencies
179
+ pip install -e ".[dev]"
180
+
181
+ # Run tests
182
+ pytest
183
+ ```
184
+
185
+ ### Contributing
186
+
187
+ 1. Fork the repository
188
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
189
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
190
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
191
+ 5. Open a Pull Request
192
+
193
+ ## License
194
+
195
+ MIT License
@@ -1,4 +1,4 @@
1
1
  from .client import SandboxClient, SandboxResponse, StreamEvent, FileOperationResponse
2
2
 
3
- __version__ = "0.3.1"
3
+ __version__ = "0.3.2"
4
4
  __all__ = ["SandboxClient", "SandboxResponse", "StreamEvent", "FileOperationResponse"]
@@ -63,7 +63,7 @@ class SandboxClient:
63
63
 
64
64
  def __init__(
65
65
  self,
66
- base_url: str = "http://aicomputer.dev",
66
+ base_url: str = "http://api.aicomputer.dev",
67
67
  token: Optional[str] = None
68
68
  ):
69
69
  self.base_url = base_url.rstrip('/')
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "ai-computer-client"
7
- version = "0.3.1"
7
+ version = "0.3.2"
8
8
  description = "Python client for interacting with the AI Computer service"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -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,120 +0,0 @@
1
- # AI Computer Python Client
2
-
3
- Python client library for interacting with the AI Computer Sandbox service.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pip install ai-computer-client
9
- ```
10
-
11
- ## Usage
12
-
13
- ### Basic Usage
14
-
15
- ```python
16
- from ai_computer import SandboxClient
17
-
18
- async def main():
19
- # Initialize client
20
- client = SandboxClient()
21
-
22
- # Setup sandbox environment
23
- await client.setup()
24
-
25
- try:
26
- # Execute code
27
- result = await client.execute_code("print('Hello, World!')")
28
- print(result.data["output"])
29
-
30
- # Upload a file
31
- response = await client.upload_file("local/path/to/file.txt")
32
- if response.success:
33
- print(f"File uploaded to {response.path}")
34
-
35
- # Download a file
36
- response = await client.download_file(
37
- "/workspace/file.txt",
38
- "local/download/path.txt"
39
- )
40
- if response.success:
41
- print(f"File downloaded to {response.path}")
42
-
43
- # Work with bytes directly
44
- content = b"Hello, World!"
45
- response = await client.upload_bytes(
46
- content=content,
47
- filename="hello.txt"
48
- )
49
-
50
- # Download as bytes
51
- content = await client.download_bytes("/workspace/hello.txt")
52
- if isinstance(content, bytes):
53
- print(content.decode())
54
-
55
- finally:
56
- # Cleanup
57
- await client.cleanup()
58
-
59
- # Run with asyncio
60
- import asyncio
61
- asyncio.run(main())
62
- ```
63
-
64
- ### Advanced Usage
65
-
66
- ```python
67
- # Stream code execution
68
- async for event in client.execute_code_stream("print('Hello')\nprint('World')"):
69
- if event.type == "stdout":
70
- print(f"Output: {event.data}")
71
- elif event.type == "stderr":
72
- print(f"Error: {event.data}")
73
- elif event.type == "completed":
74
- print("Execution completed")
75
-
76
- # Upload with custom settings
77
- response = await client.upload_file(
78
- "file.txt",
79
- destination="/workspace/custom/path",
80
- chunk_size=2*1024*1024, # 2MB chunks
81
- timeout=600 # 10 minutes
82
- )
83
-
84
- # Work with file-like objects
85
- from io import BytesIO
86
-
87
- buffer = BytesIO(b"Hello from buffer!")
88
- response = await client.upload_bytes(
89
- content=buffer,
90
- filename="buffer.txt",
91
- content_type="text/plain"
92
- )
93
- ```
94
-
95
- ## Development
96
-
97
- ### Setup
98
-
99
- ```bash
100
- # Clone the repository
101
- git clone https://github.com/ai-computer/ai-computer-client-python
102
- cd ai-computer-client-python
103
-
104
- # Create and activate virtual environment
105
- python -m venv venv
106
- source venv/bin/activate # or `venv\Scripts\activate` on Windows
107
-
108
- # Install development dependencies
109
- pip install -e ".[dev]"
110
- ```
111
-
112
- ### Running Tests
113
-
114
- ```bash
115
- pytest tests/
116
- ```
117
-
118
- ## License
119
-
120
- MIT License