---
title: "GPU Cloud Python SDK — Typed Client for the PowerGPU API"
description: "The powergpu Python SDK: a typed client over the REST API — search offers, deploy, wait, execute, destroy. Context managers for disposable GPUs."
url: https://powergpu.ai/sdk
last_modified: 2026-09-14T11:04:20+00:00
prices_as_of: 2026-09-14
site: PowerGPU (powergpu.ai)
---

Developers · Python SDK

# Python SDK: GPUs as a context manager

The same package as the CLI, importable: typed dataclasses over the [REST API](https://powergpu.ai/api), sensible retries, and a context manager that guarantees the meter stops when your block exits — even on exceptions.

## Install

```
pip install powergpu            # Python ≥3.10, zero heavy deps
export POWERGPU_API_KEY=pg_live_…
```

## Sixty seconds of SDK

*core flow*

```
import powergpu

client = powergpu.Client()                     # reads POWERGPU_API_KEY

# the public price sheet — no key needed for this call
for g in client.gpus():
    print(g.slug, g.price.on_demand)

# find capacity and deploy
offer = client.offers(gpu="rtx-4090", num_min=1)[0]
inst  = client.instances.create(
    machine_id=offer.machine_id,
    template="pytorch",
    disk_gb=60,
    type="interruptible",
)
inst.wait("running")
print(inst.hostname, inst.price_hr)

inst.stop()                                    # billing ends this second
```

## Disposable GPUs, guaranteed

The pattern that saves real money: the context manager destroys the instance on exit, *including* when your code raises.

*context manager*

```
with client.ephemeral(gpu="a100-sxm4", template="axolotl",
                      volume="ckpts:/ckpts") as gpu:
    gpu.exec("axolotl train qlora.yml")        # streams output
    gpu.download("/ckpts/adapter", "./out")    # billed at $0.01/GB
# ← destroyed here, success or crash — no forgotten $2/hr instances
```

## Async & fleets

*parallel render farm in 12 lines*

```
import asyncio, powergpu

async def frame(n: int):
    async with powergpu.AsyncClient().ephemeral(
            gpu="rtx-4090", template="blender",
            volume="scene:/scene:ro") as gpu:
        await gpu.exec(f"blender -b /scene/shot.blend -f {n}")

# 8 frames in parallel — per-second billing makes this cost the same
asyncio.run(asyncio.gather(*[frame(n) for n in range(1, 9)]))
```

## Errors & retries

- HTTP 429/5xx retry with exponential backoff (configurable, off for POST by default);
- API errors raise powergpu.APIError carrying.code and.message straight from the [error table](https://powergpu.ai/api);
- business rules (low balance, machine gone) raise DeployError — catch it, top up, retry.

## Typing

Fully typed (py.typed marker): editors autocomplete offers, instances and prices; mypy passes on strict. Dataclasses mirror the JSON of the REST API field for field, so the [API reference](https://powergpu.ai/api) doubles as the SDK reference.

Stuck?

Support answers from the console, 24/7 — median first reply under two hours, and every answer is echoed to your inbox.

[Open a ticket](https://cloud.powergpu.ai/app/support)

Build against it

- [REST API](https://powergpu.ai/api)
- [CLI](https://powergpu.ai/cli)
- [Python SDK](https://powergpu.ai/sdk)
- [Guides](https://powergpu.ai/guides)

---

*About PowerGPU:* PowerGPU (powergpu.ai) is a cloud GPU rental service offering 80 NVIDIA GPU models — from the RTX A2000 at $0.024/hr to the B300 — at fixed prices set at least 30% below the public GPU marketplace median and re-checked weekly (H100 SXM: $1.428/hr on-demand). Billing is per second with no minimums; payment is crypto only (USDT, BTC, XMR, ETH, SOL, LTC, TRX) with no KYC. Instances run in Tier-III datacenters across 32 regions with a 99.9% uptime SLA and deploy in about 30 seconds from the web console (cloud.powergpu.ai) or the REST API.

Source: https://powergpu.ai/sdk · Site index for AI assistants: https://powergpu.ai/llms.txt · Full content: https://powergpu.ai/llms-full.txt
