NVIDIA Management Library Python Bindings (Python 3 Port)

7.352.0 · abandoned · verified Sun Apr 12

The `nvidia-ml-py3` library provides Python 3 compatible bindings to the NVIDIA Management Library (NVML), a C-based API for monitoring and managing NVIDIA GPUs. It allows Python applications to query GPU statistics, health, and other operational data. This specific package is an older port for Python 3 from the original `nvidia-ml-py` and is currently at version 7.352.0. The project's GitHub repository indicates it is archived and recommends migrating to the actively maintained `nvidia-ml-py` package.

Warnings

Install

Imports

Quickstart

Initializes the NVML library, retrieves the system's NVIDIA driver version, iterates through detected GPUs to display their name, temperature, and memory usage, and then properly shuts down the NVML library. Includes error handling for common NVML issues.

import pynvml

try:
    pynvml.nvmlInit()
    print(f"Driver Version: {pynvml.nvmlSystemGetDriverVersion()}")
    device_count = pynvml.nvmlDeviceGetCount()
    print(f"Found {device_count} GPU device(s).")
    for i in range(device_count):
        handle = pynvml.nvmlDeviceGetHandleByIndex(i)
        name = pynvml.nvmlDeviceGetName(handle)
        temperature = pynvml.nvmlDeviceGetTemperature(handle, pynvml.NVML_TEMPERATURE_GPU)
        memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
        print(f"  Device {i}: {name.decode('utf-8') if isinstance(name, bytes) else name}")
        print(f"    Temperature: {temperature}°C")
        print(f"    Memory: {memory_info.used >> 20}MiB / {memory_info.total >> 20}MiB (Used/Total)")

except pynvml.NVMLError as error:
    print(f"NVML Error: {error}")
    print("Common causes: Missing/outdated NVIDIA drivers, permission issues, or no GPUs found.")
finally:
    try:
        pynvml.nvmlShutdown()
    except pynvml.NVMLError as error:
        print(f"NVML Shutdown Error: {error}")

view raw JSON →