Get CPU Information in Python — psutil and py-cpuinfo Example
A short script that shows how to get CPU information in Python: processor brand, architecture, clock speed, and physical and logical core counts, using psutil and py-cpuinfo.
Overview
This script uses the psutil and py-cpuinfo libraries to gather and print CPU details to the console, including brand name, architecture, clock speed, core counts, and an estimated temperature.
Features
- CPU brand name and architecture
- cpuinfo version string
- Actual clock frequency (human-readable)
- Number of physical cores
- Number of logical cores (including hyper-threaded)
- Estimated temperature in °C (derived from current frequency)
Requirements
psutil
py-cpuinfo
Install dependencies:
pip install psutil py-cpuinfo
Usage
From the Console_Code folder:
python CPU.py
Example Output
Values depend on your machine; the labels are printed exactly as below (including the script’s Actucal Hz spelling).
Processor Info
Brand : Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Architecture : X86_64
Version : cpuinfo-9.0.0
Actucal Hz : 2.6000 GHz
Physical Cores : 6
Logical Cores : 12
Temperature : 41.0°C
Notes
- Temperature is estimated based on the current CPU frequency (
freq / 100 + 15). It is not a hardware sensor reading and should not be used to judge whether a CPU is overheating. On Linux,psutil.sensors_temperatures()can read real sensor values where the hardware exposes them. psutilandcpuinfosupport Windows, macOS, and Linux.
File Structure
Extract CPU Information/
└── Console_Code/
└── CPU.py # Main script
Related Projects
Documentation links
Read all Python Projects and Code Examples guides online · Project overview · All developer projects