psutil
psutil is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful for system monitoring, profiling, limiting process resources, and managing running processes. The current version is 8.0.0, released on March 28, 2026, with a regular release cadence.
Warnings
- breaking In version 8.0.0, the 'psutil.OSX' constant has been deprecated and replaced with 'psutil.MACOS'.
- gotcha Ensure that psutil is installed in your environment to avoid ImportError.
Install
-
pip install psutil
Imports
- psutil
import psutil
Quickstart
import psutil
# Get CPU times
cpu_times = psutil.cpu_times(percpu=False)
print(cpu_times)
# List all processes
for proc in psutil.process_iter(['pid', 'name']):
print(proc.info)