Python SDK for creating and managing cloud sandboxes with Excloud
Project description
Excloud Python SDK
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.0websockets>=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
- Documentation: https://docs.excloud.in
- Issues: GitHub Issues
- Support: support@excloud.in
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.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7b76d1352d65d522d3db4f72e6a4c4a3322d8da47f9d722c07f82baab11849f
|
|
| MD5 |
73ff71f9c883b87b94b2f25ec60d4358
|
|
| BLAKE2b-256 |
9cb226ab56367ad2a81f82dbae8a81070f09b295901c54163973f67963271803
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ce20177ece8cfb76dc0e20bcef9f0e5d19a65c2090dabdd519ff8cf57c13ab
|
|
| MD5 |
959f22cdf3eaaf2aba0e9a8176f7d05f
|
|
| BLAKE2b-256 |
19d9c239a61eb06e8fedc575e8a11f4c20fc8e7ee06e9322b9eade19c2c78384
|