Python client for interacting with the AI Computer service
Project description
AI Computer Python Client
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.
Installation
pip install ai-computer-client
Quick Start
import asyncio
from ai_computer import SandboxClient
async def main():
# Initialize the client
client = SandboxClient()
# Setup the client (gets token and creates sandbox)
setup_response = await client.setup()
if not setup_response.success:
print(f"Setup failed: {setup_response.error}")
return
try:
# Execute some code
code = """
print('Hello from AI Computer!')
result = 42
print(f'The answer is {result}')
"""
# Stream execution
async for event in client.execute_code_stream(code):
if event.type == 'stdout':
print(f"Output: {event.data}")
elif event.type == 'stderr':
print(f"Error: {event.data}")
elif event.type == 'error':
print(f"Execution error: {event.data}")
break
elif event.type == 'completed':
print("Execution completed")
break
finally:
# Clean up
await client.cleanup()
if __name__ == "__main__":
asyncio.run(main())
Features
- Asynchronous API
- Streaming execution output
- Automatic sandbox management
- Error handling and timeouts
- Type hints for better IDE support
API Reference
SandboxClient
The main client class for interacting with the AI Computer service.
Methods
setup(): Initialize the client and create a sandboxexecute_code(code: str, timeout: int = 30): Execute code and return combined outputexecute_code_stream(code: str, timeout: int = 30): Execute code and stream outputcleanup(): Delete the sandboxwait_for_ready(): Wait for sandbox to be ready
Development
Running Tests
pip install -e ".[dev]"
pytest
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_computer_client-0.1.0.tar.gz.
File metadata
- Download URL: ai_computer_client-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55f94aefdf24a94fda6f98b63fb9f3858c0c034fa11a1ea42ab078c0e88e6fa6
|
|
| MD5 |
b3ad92fa5553349d5bfc919dbc4aaac6
|
|
| BLAKE2b-256 |
e9bb73cf28da0b100e9d557e6fb6872ead7de0fdb855dfdabe4cdca36a98681c
|
File details
Details for the file ai_computer_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_computer_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddf666c2bbcb66f14d11279bfb3ba55eacdc68f7adc1bb01dbfc5d21fb2da674
|
|
| MD5 |
a23912a49d3edea7b9e7b81559064094
|
|
| BLAKE2b-256 |
bce3b6cffb0e6149ebeb3dd541096b1a2ee34f2b3e6eea3c46bc98f15d96a0bd
|