Python SDK

Python SDK

The Pulserun Python SDK provides a convenient way to manage GPU instances programmatically.

Installation

pip install pulserun

Quick Start

import pulserun
 
client = pulserun.Client("pr_live_xxxxxxxxxxxxx")
 
# Launch cheapest A100
instance = client.instances.create(
    gpu="a100_80gb",
    template="pytorch"
)
 
print(f"Instance ID: {instance.id}")
print(f"Status: {instance.status}")
print(f"SSH: {instance.ssh_command}")
print(f"Jupyter: {instance.jupyter_url}")
print(f"Cost: ${instance.cost_per_hour}/hr")

Managing Instances

# List running instances
instances = client.instances.list(status="running")
for inst in instances:
    print(f"{inst.id}: {inst.gpu_name} @ ${inst.cost_per_hour}/hr")
 
# Get instance details
instance = client.instances.get("inst_abc123")
 
# Stop (pause billing)
instance.stop()
 
# Restart
instance.start()
 
# Terminate (delete)
instance.terminate()

Checking Prices

# Get all pricing
pricing = client.pricing.list()
 
# Filter by GPU
a100_prices = client.pricing.list(gpu="a100_80gb")
for p in a100_prices:
    print(f"{p.provider}: ${p.price_per_hour}/hr ({p.availability} available)")
 
# Get cheapest
cheapest = client.pricing.cheapest(gpu="a100_80gb")
print(f"Cheapest: {cheapest.provider} @ ${cheapest.price_per_hour}/hr")

Billing

# Check balance
balance = client.billing.balance()
print(f"Balance: ${balance.balance}")
 
# Add credit (returns checkout URL)
checkout = client.billing.add_credit(amount=50)
print(f"Pay here: {checkout.checkout_url}")
 
# Transaction history
transactions = client.billing.transactions()
for txn in transactions:
    print(f"{txn.type}: ${txn.amount} ({txn.description})")

Spot Instances

# Launch a cheap spot instance
instance = client.instances.create(
    gpu="a100_80gb",
    template="pytorch",
    spot=True,
    auto_spot_recovery=True  # Phase 3: auto-restart if interrupted
)

Scheduled Jobs (Phase 3)

# Create a recurring job
job = client.schedules.create(
    name="Nightly training",
    gpu="a100_80gb",
    template="pytorch",
    cron="0 2 * * *",
    max_duration_hours=4,
    max_cost=5.00,
    prefer_spot=True
)

Error Handling

from pulserun.exceptions import InsufficientBalanceError, GPUUnavailableError
 
try:
    instance = client.instances.create(gpu="h200_141gb", template="pytorch")
except InsufficientBalanceError:
    print("Add more credit first!")
except GPUUnavailableError:
    print("No H200s available right now, try again later")