Skip to main content

gpu-smi (Python wrapper)

Friendly Python access to gpu-smi — stdlib only, no compiler, no dependencies.

You still need the gpu-smi binary itself (this package calls it for you). Windows: it's bundled — pip install is all you need. Linux: get it from releases or cargo build --release, then put it on PATH or set GPU_SMI_BIN (a Linux binary will be bundled in a later release the same way).

pip install gpu-smi
# from source: pip install ./python

Beginner (no JSON needed)

import gpu_smi

for gpu in gpu_smi.gpus():
    print(gpu.summary())
    # [1] AMD Radeon RX 9070 XT | VRAM 2513/16304 MB (15%) | 39C | 22% util | 8.2W

gpu = gpu_smi.first()          # single-GPU shortcut (raises NoGpuError if none)
print(gpu.name, gpu.temp_c, gpu.util_percent)
print(gpu.vram_free_mb, gpu.usage_ratio)
for p in gpu.processes:        # pid, name, mem_mb, kind ("C"/"G"), is_compute
    print(p.pid, p.name, p.mem_mb)

python -m gpu_smi prints the same report with zero code (--raw for JSON).

Power user

import gpu_smi

rows = gpu_smi.query_raw()                          # raw list[dict], untouched
for snap in gpu_smi.watch(interval=0.5, count=10):  # polling generator
    ...

# Long-running HTTP API (one persistent process, Prometheus included):
with gpu_smi.serve(port=8080, token=True) as api:   # token=True -> auto 256-bit token via mode-600 tempfile
    print(api.gpus()[0].summary())
    print(api.metrics())                            # raw Prometheus exposition text

api = gpu_smi.ServeClient("http://ml-box:8080", token=open("token.txt").read().strip())
api.health()  # {"status": "ok"} — open even with auth on

Binary lookup order: explicit arg > GPU_SMI_BIN env > PATH > bundled gpu_smi/bin/. Errors: BinaryNotFoundError, QueryError, AuthError (bad bearer token), NoGpuError — all subclass GpuSmiError.

License

MIT, same as gpu-smi.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpu_smi-1.2.1.tar.gz (483.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpu_smi-1.2.1-py3-none-any.whl (482.3 kB view details)

Uploaded Python 3

File details

Details for the file gpu_smi-1.2.1.tar.gz.

File metadata

  • Download URL: gpu_smi-1.2.1.tar.gz
  • Upload date:
  • Size: 483.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for gpu_smi-1.2.1.tar.gz
Algorithm Hash digest
SHA256 5693d2b8d25c677694041359f30e566c96af84bb22c20b4e734fceb8e636ccea
MD5 f9be4f34b56d3fdb9e393aaa9eb5b15d
BLAKE2b-256 0a752fbf68f00b2b7befac0fe79817e165a0a14d3cb8bbdc83908921405dd316

See more details on using hashes here.

File details

Details for the file gpu_smi-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: gpu_smi-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 482.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for gpu_smi-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40bb300dabc39f72d0f27817b66c6b97e0738df9fd6bcc0826b88f6ce0cd9d1d
MD5 6a7691ae3f8a7f1715efe28cdad72274
BLAKE2b-256 fbfbdfb83e1e9c1dd7405a56d0a2e7ad9909116a6e8219f9a9ac69bd1372c497

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.2

2 files

This release

1.2.1 This release

2 files

1.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page