Skip to main content

Python SDK for creating and managing cloud sandboxes with Excloud

Project description

Excloud Python SDK

PyPI version Python versions License: MIT

Python SDK for creating and managing cloud sandboxes with Excloud. Easily spin up isolated computing environments for development, testing, and automation.

Installation

pip install excloud

Quick Start

from excloud import Client

# Initialize client with your API key
client = Client(api_key="your_api_key_here")

# Create a sandbox
sandbox = client.create()
print(f"Sandbox created: {sandbox.name}")

# Execute commands in the sandbox
result = sandbox.run("python --version")
print(result)

# Clean up
sandbox.destroy()

Usage with Context Manager

For automatic cleanup, use the context manager:

from excloud import Client

client = Client(api_key="your_api_key")

with client.create() as sandbox:
    # Execute commands
    result = sandbox.run("ls -la")
    print(result)

# Sandbox is automatically destroyed when exiting the context

Features

  • Easy Sandbox Management: Create, manage, and destroy cloud sandboxes with simple API calls
  • Command Execution: Run shell commands and scripts in isolated environments
  • Real-time Communication: WebSocket-based real-time command execution and output streaming
  • Context Manager Support: Automatic resource cleanup with Python context managers
  • Comprehensive Error Handling: Detailed exceptions for different failure scenarios
  • Logging Support: Built-in logging for debugging and monitoring

API Reference

Client

from excloud import Client

client = Client(
    api_key="your_api_key",
    base_url="https://compute.excloud.in",  # Optional, defaults to production URL
    timeout=10  # Optional, request timeout in seconds
)

Methods

client.create()

Creates a new sandbox and returns a Sandbox instance.

client.get(sandbox_id)

Retrieves an existing sandbox by ID.

client.list()

Lists all sandboxes associated with your account.

Sandbox

sandbox.run(command)

Executes a command in the sandbox and returns the result.

result = sandbox.run("echo 'Hello, World!'")
print(result)  # Output from the command
print(result.exit_code)  # Exit code (0 for success)

sandbox.upload_file(local_path, remote_path)

Uploads a file from your local machine to the sandbox.

sandbox.download_file(remote_path, local_path)

Downloads a file from the sandbox to your local machine.

sandbox.destroy()

Destroys the sandbox and cleans up all resources.

Error Handling

The SDK provides specific exceptions for different error scenarios:

from excloud import Client
from excloud import (
    AuthenticationError,
    SandboxCreationError,
    CommandExecutionError,
    ConnectionError,
    SandboxNotFoundError
)

try:
    client = Client(api_key="invalid_key")
    sandbox = client.create()
except AuthenticationError:
    print("Invalid API key")
except SandboxCreationError:
    print("Failed to create sandbox")
except ConnectionError:
    print("Network connection failed")

Configuration

Environment Variables

You can also configure the client using environment variables:

export EXCLOUD_API_KEY="your_api_key"
export EXCLOUD_BASE_URL="https://compute.excloud.in"
import os
from excloud import Client

# Client will automatically use environment variables
client = Client(api_key=os.getenv("EXCLOUD_API_KEY"))

Requirements

  • Python 3.7+
  • requests>=2.25.0
  • websockets>=11.0

Examples

Running a Python Script

from excloud import Client

client = Client(api_key="your_api_key")

with client.create() as sandbox:
    # Create a Python script
    script = """
import json
data = {"message": "Hello from sandbox!", "status": "success"}
print(json.dumps(data, indent=2))
"""

    # Write script to file
    sandbox.run(f"cat > script.py << 'EOF'\n{script}\nEOF")

    # Execute the script
    result = sandbox.run("python script.py")
    print(result)

Installing and Using Packages

from excloud import Client

client = Client(api_key="your_api_key")

with client.create() as sandbox:
    # Install packages
    sandbox.run("pip install numpy pandas")

    # Use the packages
    result = sandbox.run("python -c 'import numpy as np; print(np.__version__)'")
    print(f"NumPy version: {result}")

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Changelog

0.1.0

  • Initial release
  • Basic sandbox creation and management
  • Command execution support
  • WebSocket-based real-time communication
  • Context manager support

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

excloud-0.1.2.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

excloud-0.1.2-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file excloud-0.1.2.tar.gz.

File metadata

  • Download URL: excloud-0.1.2.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for excloud-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a7b76d1352d65d522d3db4f72e6a4c4a3322d8da47f9d722c07f82baab11849f
MD5 73ff71f9c883b87b94b2f25ec60d4358
BLAKE2b-256 9cb226ab56367ad2a81f82dbae8a81070f09b295901c54163973f67963271803

See more details on using hashes here.

File details

Details for the file excloud-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: excloud-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for excloud-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79ce20177ece8cfb76dc0e20bcef9f0e5d19a65c2090dabdd519ff8cf57c13ab
MD5 959f22cdf3eaaf2aba0e9a8176f7d05f
BLAKE2b-256 19d9c239a61eb06e8fedc575e8a11f4c20fc8e7ee06e9322b9eade19c2c78384

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