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). Get it from releases, cargo build --release, and either put it on PATH or set GPU_SMI_BIN to its full path. Wheels may bundle it under gpu_smi/bin/ in the future.

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.0.tar.gz (10.4 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.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gpu_smi-1.2.0.tar.gz
  • Upload date:
  • Size: 10.4 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.0.tar.gz
Algorithm Hash digest
SHA256 5449b162c3d4121fdde322d06c7c2fb32ecc6a160640a67060d3777752f2f8ce
MD5 70e759125663d15a851cba08d34ef5d5
BLAKE2b-256 8330afdd07c76798e7557b0012476845df40e00e85dd852c8ea75aadd8042086

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gpu_smi-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e41b2f1c12f9af521069cbaaf0d0e043db43b101365a7a3918f7648b3cf4e992
MD5 3593ae9537dfd5fe3ab06cda6360a03a
BLAKE2b-256 68c3a46b47564a7fb27eff1e1cbacbee13889705a9c10be1a2f1852ba01d02d7

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.2

2 files

1.2.1

2 files

This release

1.2.0 This release

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