Skip to main content

Python client for interacting with the AI Computer service

Project description

AI Computer Python Client

Python client library for interacting with the AI Computer Sandbox service.

Installation

pip install ai-computer-client

Usage

Basic Usage

from ai_computer import SandboxClient

async def main():
    # Initialize client
    client = SandboxClient()
    
    # Setup sandbox environment
    await client.setup()
    
    try:
        # Execute code
        result = await client.execute_code("print('Hello, World!')")
        print(result.data["output"])
        
        # Upload a file
        response = await client.upload_file("local/path/to/file.txt")
        if response.success:
            print(f"File uploaded to {response.path}")
        
        # Download a file
        response = await client.download_file(
            "/workspace/file.txt",
            "local/download/path.txt"
        )
        if response.success:
            print(f"File downloaded to {response.path}")
            
        # Work with bytes directly
        content = b"Hello, World!"
        response = await client.upload_bytes(
            content=content,
            filename="hello.txt"
        )
        
        # Download as bytes
        content = await client.download_bytes("/workspace/hello.txt")
        if isinstance(content, bytes):
            print(content.decode())
            
    finally:
        # Cleanup
        await client.cleanup()

# Run with asyncio
import asyncio
asyncio.run(main())

Advanced Usage

# Stream code execution
async for event in client.execute_code_stream("print('Hello')\nprint('World')"):
    if event.type == "stdout":
        print(f"Output: {event.data}")
    elif event.type == "stderr":
        print(f"Error: {event.data}")
    elif event.type == "completed":
        print("Execution completed")

# Upload with custom settings
response = await client.upload_file(
    "file.txt",
    destination="/workspace/custom/path",
    chunk_size=2*1024*1024,  # 2MB chunks
    timeout=600  # 10 minutes
)

# Work with file-like objects
from io import BytesIO

buffer = BytesIO(b"Hello from buffer!")
response = await client.upload_bytes(
    content=buffer,
    filename="buffer.txt",
    content_type="text/plain"
)

Development

Setup

# Clone the repository
git clone https://github.com/ai-computer/ai-computer-client-python
cd ai-computer-client-python

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install development dependencies
pip install -e ".[dev]"

Running Tests

pytest tests/

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_computer_client-0.3.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_computer_client-0.3.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file ai_computer_client-0.3.1.tar.gz.

File metadata

  • Download URL: ai_computer_client-0.3.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for ai_computer_client-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ef4740b9a66c7fb5a40ac86d726df47328ef9c238b813c741b6873fa7bf4bd71
MD5 9e0c772d251a5b1e66e7133e16902852
BLAKE2b-256 44bfeb0de022640361ad8baaac768140a343d04b5fa954d880eac739726bd2fc

See more details on using hashes here.

File details

Details for the file ai_computer_client-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_computer_client-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 074a9e8e2172891ccf05fc78ea5b54e7dbe01cbebd4a8e9b73fd215ca18961db
MD5 c6e58df872d1f379a4088b5da220dd19
BLAKE2b-256 3ebfda1651fba02f21ad600aee7cac2f41247c699aa06d3526d7cba35f7281a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page