Introduction
The Magpie Cloud Python SDK provides a simple and intuitive interface for creating runtime workers and code sandboxes in the cloud. Build ephemeral or persistent compute environments for CI/CD, data processing, interactive development, and more.
Key Features
- Create ephemeral and persistent jobs with customizable compute resources
- Run batch jobs and code execution in isolated environments
- SSH into virtual machines for interactive debugging
- Stateful workspaces that persist data between runs
- Reusable job templates for common workflows
- IPv6 networking support
Installation
Install the Magpie Cloud SDK using pip:
pip install magpie-cloud
Requirements
- Python 3.9 or higher
- A Magpie Cloud API key
Authentication
Authenticate with your Magpie Cloud API key. You can provide the key directly to the client or set it as an environment variable.
Direct API Key
from magpie import Magpie client = Magpie(api_key="your_api_key_here")
Environment Variable
# Set environment variable export MAGPIE_API_KEY="your_api_key_here" # Initialize client without explicit key from magpie import Magpie client = Magpie()
Quick Start
Create and run your first job in minutes:
from magpie import Magpie
# Initialize the client
client = Magpie(api_key="your_api_key_here")
# Create an ephemeral job
response = client.jobs.create(
name="hello-world",
script="echo 'Hello from Magpie!'",
vcpus=2,
memory_mb=512
)
print(f"Job created: {response.id}")
print(f"Status: {response.status}") Core Concepts
Jobs
Jobs are the fundamental unit of computation in Magpie Cloud. A job represents a script or command that runs in an isolated environment with specified compute resources.
Templates
Templates allow you to define reusable job configurations. Create a template once and run it multiple times with different parameters.
View Templates API Reference →
Workspaces
Workspaces provide persistent storage for stateful jobs. The /workspace directory is preserved between job runs, allowing you to maintain state, cache data, and store outputs.