Skip to main content

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 sandbox
  • execute_code(code: str, timeout: int = 30): Execute code and return combined output
  • execute_code_stream(code: str, timeout: int = 30): Execute code and stream output
  • cleanup(): Delete the sandbox
  • wait_for_ready(): Wait for sandbox to be ready

Development

Running Tests

pip install -e ".[dev]"
pytest

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

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.1.0.tar.gz (4.8 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.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

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

Hashes for ai_computer_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 55f94aefdf24a94fda6f98b63fb9f3858c0c034fa11a1ea42ab078c0e88e6fa6
MD5 b3ad92fa5553349d5bfc919dbc4aaac6
BLAKE2b-256 e9bb73cf28da0b100e9d557e6fb6872ead7de0fdb855dfdabe4cdca36a98681c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ai_computer_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddf666c2bbcb66f14d11279bfb3ba55eacdc68f7adc1bb01dbfc5d21fb2da674
MD5 a23912a49d3edea7b9e7b81559064094
BLAKE2b-256 bce3b6cffb0e6149ebeb3dd541096b1a2ee34f2b3e6eea3c46bc98f15d96a0bd

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