Get CPU info with pure Python
Project description
py-cpuinfo2
This is a friendly drop-in fork of py-cpuinfo.
Py-cpuinfo gets CPU info with pure Python. Py-cpuinfo should work without any extra programs or libraries, beyond what your OS provides. It does not require any compilation(C/C++, assembly, et cetera) to use. It works with Python 3.
Example
if __name__ == '__main__':
from cpuinfo import get_cpu_info
for key, value in get_cpu_info().items():
print("{0}: {1}".format(key, value))
API
'''
Returns the CPU info by using the best sources of information for your OS.
Returns the result in a dict
'''
get_cpu_info()
'''
Returns the CPU info by using the best sources of information for your OS.
Returns the result in a json string
'''
get_cpu_info_json()
Fields
| key | Example value | Return Format |
|---|---|---|
| "python_version" | "3.10.4.final.0 (64 bit)" | string |
| "cpuinfo_version" | (8, 0, 0) | (int, int, int) |
| "cpuinfo_version_string" | "8.0.0" | string |
| "hz_advertised_friendly" | "2.9300 GHz" | string |
| "hz_actual_friendly" | "1.7330 GHz" | string |
| "hz_advertised" | (2930000000, 0) | (int, int) |
| "hz_actual" | (1733000000, 0) | (int, int) |
| "arch" | "X86_64" | 'ARM_7', 'ARM_8', 'LOONG_32', 'LOONG_64', 'MIPS_32', 'MIPS_64', 'PPC_32', 'PPC_64', 'RISCV_32', 'RISCV_64', 'SPARC_32', 'SPARC_64', 'S390X', 'X86_32', 'X86_64' |
| "bits" | 64 | int |
| "count" | 4 | int |
| "l1_data_cache_size" | 32768 | int |
| "l1_instruction_cache_size" | 32768 | int |
| "l2_cache_size" | 262144 | int |
| "l2_cache_line_size" | 256 | int |
| "l2_cache_associativity" | 6 | int |
| "l3_cache_size" | 3145728 | int |
| "stepping" | 5 | int |
| "model" | 30 | int |
| "family" | 6 | int |
| "processor_type" | 0 | int |
| "flags" | ['acpi', 'aperfmperf', 'apic', 'arch_perfmon', 'bts', 'clflush', 'cmov', 'constant_tsc', 'cx16', 'cx8', 'de', 'ds_cpl', 'dtes64', 'dtherm', 'dts', 'ept', 'est', 'flexpriority', 'fpu', 'fxsr', 'ht', 'ida', 'lahf_lm', 'lm', 'mca', 'mce', 'mmx', 'monitor', 'msr', 'mtrr', 'nonstop_tsc', 'nopl', 'nx', 'pae', 'pat', 'pbe', 'pdcm', 'pebs', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'rdtscp', 'rep_good', 'sep', 'smx', 'ss', 'sse', 'sse2', 'sse4_1', 'sse4_2', 'ssse3', 'syscall', 'tm', 'tm2', 'tpr_shadow', 'tsc', 'vme', 'vmx', 'vnmi', 'vpid', 'xtopology', 'xtpr'] | [string] |
Raw Fields
These fields are pulled directly from the CPU and are unverified. They may contain expected results. Other times they may contain wildly unexpected results or garbage. So it would be a bad idea to rely on them.
| key | Example value | Return Format |
|---|---|---|
| "vendor_id_raw" | "GenuineIntel" | string |
| "hardware_raw" | "BCM2708" | string |
| "brand_raw" | "Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz" | string |
| "arch_string_raw" | "x86_64" | string |
Run as a module
$ python -m cpuinfo
Run as a library
if __name__ == '__main__':
from cpuinfo import get_cpu_info
info = get_cpu_info()
print(info)
Run under Pyinstaller
# NOTE: Pyinstaller may spawn infinite processes if __main__ is not used
if __name__ == '__main__':
from cpuinfo import get_cpu_info
from multiprocessing import freeze_support
# NOTE: Pyinstaller also requires freeze_support
freeze_support()
info = get_cpu_info()
print(info)
Install instructions
$ python -m pip install -U py-cpuinfo
Command Line Arguments
--help: show this help message and exit
--json: Return the info in JSON format
--version: Return the version of py-cpuinfo
--trace: Traces code paths used to find CPU info to file
OS Support
| OS | Tested and should work | Untested |
|---|---|---|
| Android | Everything | |
| BSD | FreeBSD, PC-BSD, TrueOS | OpenBSD, NetBSD |
| Cygwin | Windows | |
| Haiku | Haiku Nightly | BeOS |
| Linux | Arch, Centos, Debian, Fedora, Gentoo, OpenSuse, Ubuntu | |
| OS X | 10.8 - 10.14 | |
| Solaris | Oracle Solaris, OpenIndiana | |
| Windows | XP, Vista, 7, 8, 10 | RT |
CPU Support
- X86 32bit and 64bit
- Some ARM, LoongArch, MIPS, PPC, RISCV, SPARC, and S390X CPUs
These approaches are used for getting info:
- Windows Registry (Windows)
- /proc/cpuinfo (Linux)
- sysctl (OS X)
- dmesg (Unix/Linux)
- /var/run/dmesg.boot (BSD/Unix)
- isainfo and kstat (Solaris)
- cpufreq-info (BeagleBone)
- lscpu (Unix/Linux)
- sysinfo (Haiku)
- device-tree ibm features flags (Linux PPC)
- Querying the CPUID register (Intel X86 CPUs)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_cpuinfo2-10.1.1.tar.gz.
File metadata
- Download URL: py_cpuinfo2-10.1.1.tar.gz
- Upload date:
- Size: 100.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7861133863663f16e06eca63b12904ef100b5760415e92372dac0162799a4771
|
|
| MD5 |
233fabe25bb7ccff314c3b67c544aa38
|
|
| BLAKE2b-256 |
dc97a8b1ddada14c8280a047c0746f95cb05d94a31b1a331cea22bcdc2b2a82d
|
Provenance
The following attestation bundles were made for py_cpuinfo2-10.1.1.tar.gz:
Publisher:
ci.yml on akx/py-cpuinfo2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_cpuinfo2-10.1.1.tar.gz -
Subject digest:
7861133863663f16e06eca63b12904ef100b5760415e92372dac0162799a4771 - Sigstore transparency entry: 1182079340
- Sigstore integration time:
-
Permalink:
akx/py-cpuinfo2@d913481d35ca523f2a775165bf555200e72b383b -
Branch / Tag:
refs/tags/v10.1.1 - Owner: https://github.com/akx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@d913481d35ca523f2a775165bf555200e72b383b -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_cpuinfo2-10.1.1-py3-none-any.whl.
File metadata
- Download URL: py_cpuinfo2-10.1.1-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adc53396bfb206e6498d078ec2ab407f85799ecd819584ac36a8f80a2d4d762d
|
|
| MD5 |
915b4baf6f8e019245ed996cebb643d0
|
|
| BLAKE2b-256 |
230aba69d2dde1ae12ef1d389ea5a216384c5ff6ef7a1e7a48d1e9b6686f6790
|
Provenance
The following attestation bundles were made for py_cpuinfo2-10.1.1-py3-none-any.whl:
Publisher:
ci.yml on akx/py-cpuinfo2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_cpuinfo2-10.1.1-py3-none-any.whl -
Subject digest:
adc53396bfb206e6498d078ec2ab407f85799ecd819584ac36a8f80a2d4d762d - Sigstore transparency entry: 1182079352
- Sigstore integration time:
-
Permalink:
akx/py-cpuinfo2@d913481d35ca523f2a775165bf555200e72b383b -
Branch / Tag:
refs/tags/v10.1.1 - Owner: https://github.com/akx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@d913481d35ca523f2a775165bf555200e72b383b -
Trigger Event:
push
-
Statement type: