Skip to main content

Get CPU info with pure Python 2 & 3

Project description

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. Works on Linux, OS X, Windows, BSD, Solaris, Cygwin, and Haiku.

These approaches are used for getting info:

  1. Windows Registry

  2. /proc/cpuinfo

  3. sysctl

  4. dmesg

  5. isainfo and psrinfo

  6. Querying x86 CPUID register

Run as a script

$ python cpuinfo.py
python cpuinfo.py
Vendor ID: GenuineIntel
Brand: Genuine Intel(R) CPU           T2050  @ 1.60GHz
Hz: 1.6000 GHz
Raw Hz: (1600000000, 0)
Arch: X86_32
Bits: 32
Count: 2
Raw Arch String: i686
L2 Cache Size: 2048 KB
L2 Cache Line Size: 0
L2 Cache Associativity: 0
Stepping: 8
Model: 14
Family: 6
Processor Type: 0
Extended Model: 0
Extended Family: 0
Flags: acpi, aperfmperf, apic, arch_perfmon, bts, clflush, cmov,
constant_tsc, cx8, de, dtherm, dts, est, fpu, fxsr, ht, mca, mce, mmx,
monitor, msr, mtrr, nx, pae, pbe, pdcm, pge, pni, pse, sep, ss, sse, sse2,
tm, tm2, tsc, vme, xtpr

Run as a library

import cpuinfo

# Have the library pick the best method for getting your CPU info
info = cpuinfo.get_cpu_info()

# Or use /proc/cpuinfo
#info = cpuinfo.get_cpu_info_from_proc_cpuinfo()

# Or use the Windows registry
#info = cpuinfo.get_cpu_info_from_registry()

# Or use sysctl
#info = cpuinfo.get_cpu_info_from_sysctl()

# Or use CPU CPUID register
#info = cpuinfo.get_cpu_info_from_cpuid()

# Print some CPU values
print('Vendor ID: {0}'.format(info['vendor_id']))
print('Brand: {0}'.format(info['brand']))
print('Hz: {0}'.format(info['hz']))
print('Raw Hz: {0}'.format(info['raw_hz']))
print('Arch: {0}'.format(info['arch']))
print('Bits: {0}'.format(info['bits']))
print('Count: {0}'.format(info['count']))
print('Flags: {0}'.format(', '.join(info['flags'])))

Bugs and Corrections

Please report a Bug if you suspect any of this information is wrong.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-cpuinfo-0.1.0.tar.gz (13.5 kB view details)

Uploaded Source

File details

Details for the file py-cpuinfo-0.1.0.tar.gz.

File metadata

  • Download URL: py-cpuinfo-0.1.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py-cpuinfo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8a17d173b8753326234730d116ad8126c4909cb47c024d4b090dfa8e05a3f8c
MD5 163caa7f53e3fa6bb38a41690de4cbfc
BLAKE2b-256 1f492f537c38f34bddf650aa091879fb48a0274423bd2656b58efd14c745a09a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page