Read CPU Information with Python and psutil

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.

Python projects · System information

Start here

Read the requirements and any configuration below, then follow the usage example. Source paths below are relative to the repository root; run commands from the working directory stated in Usage. This example’s source is in Extract CPU Information/Console_Code/. Install any third-party packages in an isolated Python environment.

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)

Prerequisites and installation

psutil
py-cpuinfo

Install dependencies:

python -m 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

Architecture

Extract CPU Information/
└── Console_Code/
    └── CPU.py    # Main script

Troubleshooting and limitations

  • 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.
  • psutil and cpuinfo support Windows, macOS, and Linux.


Read all Python Projects and Code Examples guides online · Project overview · All developer projects