py-cpuinfo
Py-cpuinfo is a pure Python library designed to retrieve detailed CPU information across various operating systems, including Linux, macOS, Windows, BSD, Solaris, Cygwin, Haiku, and BeagleBone. It functions without requiring any external programs or compilation beyond the standard OS provisions. The library is compatible with Python 3. The current stable version is 9.0.0, released in October 2022.
Warnings
- gotcha When compiling applications using PyInstaller or Cx_Freeze that incorporate `py-cpuinfo`, the frozen executable may exhibit high CPU usage or create multiple processes, potentially leading to crashes. This is a common issue with libraries that use multiprocessing.
- gotcha The `py-cpuinfo` library provides 'Raw Fields' which are direct outputs from underlying system calls or CPUID registers. These values are unverified and may contain unexpected, incorrect, or even garbage data. Relying on these raw fields directly can lead to inaccurate information.
- gotcha On some systems, the `hz_actual` and `hz_advertised` fields returned by `get_cpu_info()` may incorrectly report a static low frequency (e.g., 400MHz) instead of the CPU's actual or advertised maximum clock rates. This can lead to misleading performance metrics.
Install
-
pip install py-cpuinfo
Imports
- get_cpu_info
from cpuinfo import get_cpu_info
Quickstart
from cpuinfo import get_cpu_info
info = get_cpu_info()
for key, value in info.items():
print(f"{key}: {value}")