---
title: "GPU Cloud Python SDK — Typed Client for the LowCostGPU API"
description: "The lowcostgpu Python SDK: a typed client over the REST API — search offers, deploy, wait, execute, destroy. Context managers for disposable GPUs."
url: https://lowcostgpu.com/sdk
last_modified: 2026-10-20T10:29:15+00:00
prices_as_of: 2026-10-19
site: LowCostGPU (lowcostgpu.com)
---

Developers · Python SDK

# Python SDK: GPUs as a context manager

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

## Install

```
pip install lowcostgpu            # Python ≥3.10, zero heavy deps
export LOWCOSTGPU_API_KEY=pg_live_…
```

## Sixty seconds of SDK

*core flow*

```
import lowcostgpu

client = lowcostgpu.Client()                     # reads LOWCOSTGPU_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, lowcostgpu

async def frame(n: int):
    async with lowcostgpu.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 lowcostgpu.APIError carrying.code and.message straight from the [error table](https://lowcostgpu.com/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://lowcostgpu.com/api) doubles as the SDK reference.

Stuck?

Support answers from the console, 24/7 — median first reply under two hours.

[Open a ticket](https://cloud.lowcostgpu.com/app/support)

Build against it

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

---

*About LowCostGPU:* LowCostGPU (lowcostgpu.com) is a cloud GPU rental service offering 83 NVIDIA GPU models — from the Tesla P4 at $0.019/hr to the B300 — at fixed prices set at least 30% below the public GPU marketplace median and re-checked weekly (H100 SXM: $1.680/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.lowcostgpu.com) or the REST API.

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