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.2.tar.gz (483.2 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.2-py3-none-any.whl (482.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gpu_smi-1.2.2.tar.gz
  • Upload date:
  • Size: 483.2 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.2.tar.gz
Algorithm Hash digest
SHA256 62d6480fd7b5486fc318e57af3ae26d26b7e840a421fb95cb09a62c32cba2861
MD5 ce8b366b63dbd114f45e1786400c951b
BLAKE2b-256 be8e52d3a7c382b70c59debe167f865bf878b7dd9c4c748af75873f4261b4208

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gpu_smi-1.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 16fad06eaa820fc176d5618bd16a85e3a311ccfdbe30557c3c65187baf0f96bf
MD5 36b48b67348f3c4d4d5aa6cf5a085201
BLAKE2b-256 4408218f198ddafe8b6118a86076c3fc847d3bc423711278f39b8c941a04fa9e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 files

1.2.1

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