Registry / data / py-cpuinfo

py-cpuinfo

JSON →
library9.0.0pypypi✓ verified 27d ago

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.

pip install py-cpuinfo
INSTALL
IMPORT
SIG · PY-CPUINFO
P
py-cpuinfo
datapythonv9.0.0
Install
1.6s avg
Import
65ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v9.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.064s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.066s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_cpu_info
from cpuinfo import get_cpu_info

This example demonstrates how to retrieve and print all available CPU information using the `get_cpu_info()` function.

from cpuinfo import get_cpu_info info = get_cpu_info() for key, value in info.items(): print(f"{key}: {value}")
cpuinfo --version
Debug
Known issues
gotchaWhen 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.
fix
Add `multiprocessing.freeze_support()` at the very beginning of your main script (before any other code) or ensure it's called if your freezing tool has a specific entry point for multiprocessing initialization. Refer to the `py-cpuinfo` GitHub issues or `multiprocessing` documentation for detailed integration with freezing tools.
affects: All versions
gotchaThe `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.
fix
Always prefer the parsed and standardized fields provided by `get_cpu_info()` for reliable data. Use 'Raw Fields' with extreme caution and implement robust validation if absolutely necessary.
affects: All versions
gotchaOn 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.
fix
Be aware that these specific frequency fields might not always be accurate. If precise clock speed measurement is critical, consider cross-referencing with other system tools or exploring alternative hardware-specific methods outside of this library.
affects: All versions, especially on specific hardware/OS configurations.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cpuinfo'
The Python package is installed as `py-cpuinfo`, but developers often mistakenly try to import it using `import py-cpuinfo` or when it's not correctly bundled with freezing tools like PyInstaller.
fix
The correct way to import the library after installing `py-cpuinfo` is `import cpuinfo`.
KeyError: 'brand'
The `get_cpu_info()` function returns a dictionary, and the 'brand' key might not always be present or directly available on certain CPU architectures (e.g., ARM-based systems like Raspberry Pi) or with older versions of the library, leading to a KeyError when attempting to access it directly.
fix
Safely access the dictionary key using the `.get()` method, for example: `cpuinfo.get_cpu_info().get('brand')`, which will return `None` if the key is not found instead of raising a KeyError.
py-cpuinfo module not working correctly when compiling using pyinstaller or Cx_freeze
When `py-cpuinfo` is bundled into an executable using PyInstaller or Cx_freeze, it can sometimes cause issues like high CPU usage or multiple processes spawning due to how the library interacts with the process environment during freezing.
fix
If your application uses multiprocessing and is frozen into an executable, add `from multiprocessing import freeze_support; if __name__ == '__main__': freeze_support()` at the very beginning of your main script file.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. inference-sdk 0.9.23 requires py-cpuinfo>=9.0.0, but you have py-cpuinfo 3.3.0 which is incompatible.
This error occurs when a project or another installed package has a dependency on a specific version range of `py-cpuinfo` (e.g., `>=9.0.0`), but an incompatible version is currently installed, or a conflicting requirement forces an older version.
fix
Try to upgrade `py-cpuinfo` to meet the dependency requirements using `pip install --upgrade py-cpuinfo` or explicitly install the required version: `pip install py-cpuinfo>=9.0.0`. If conflicts persist, consider creating a virtual environment or resolving broader dependency issues among your installed packages.
Upgrade
Version history
9.0.0latest on PyPI · released Oct 25, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Resources
py-cpuinfo — pip install py-cpuinfo · libregistry