ai-computer-client 0.3.1__tar.gz → 0.3.3__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.3
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
@@ -0,0 +1,14 @@
1
+ from .client import SandboxClient
2
+ from .models import SandboxResponse, StreamEvent, FileOperationResponse
3
+ from .submodules import FileSystemModule, ShellModule, CodeModule
4
+
5
+ __version__ = "0.3.3"
6
+ __all__ = [
7
+ "SandboxClient",
8
+ "SandboxResponse",
9
+ "StreamEvent",
10
+ "FileOperationResponse",
11
+ "FileSystemModule",
12
+ "ShellModule",
13
+ "CodeModule"
14
+ ]