Registry / observability / psutil

psutil

JSON →
library7.2.2pypypi✓ verified 27d ago

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.

pip install psutil
INSTALL
IMPORT
SIG · PSUTIL
P
psutil
observabilitypythonv7.2.2
Install
1.8s avg
Import
63ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.064s · 18.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.062s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

psutil
import psutil
Ensure that psutil is installed in your environment to avoid ImportError.

This script demonstrates how to retrieve CPU times and list all running processes using psutil.

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)
Debug
Known issues
breakingIn version 8.0.0, the 'psutil.OSX' constant has been deprecated and replaced with 'psutil.MACOS'.
fix
Replace 'psutil.OSX' with 'psutil.MACOS' in your code.
affects: 8.0.0
gotchaEnsure that psutil is installed in your environment to avoid ImportError.
fix
Install psutil using 'pip install psutil'.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'psutil'
The 'psutil' library is not installed in your Python environment or the Python interpreter being used cannot find it.
fix
Run `pip install psutil` in your terminal to install the library. If using a virtual environment, ensure it's activated.
psutil.AccessDenied (pid=...)
Your script lacks the necessary permissions to retrieve information for certain system processes or processes owned by other users.
fix
Wrap the problematic `psutil` calls in a `try-except psutil.AccessDenied:` block to gracefully skip processes you don't have access to, or run the script with elevated privileges (e.g., `sudo python your_script.py` on Linux/macOS or 'Run as Administrator' on Windows).
psutil.NoSuchProcess: process no longer exists (pid=...)
The process with the specified PID terminated between the time its PID was obtained and when psutil attempted to gather its information.
fix
Always enclose operations on `psutil.Process` objects, especially when iterating through processes, within a `try-except psutil.NoSuchProcess:` block to handle cases where a process disappears.
psutil.cpu_percent() always returns 0.0 (or Process.cpu_percent())
The `cpu_percent()` function (both system-wide and per-process) calculates CPU utilization based on the difference between two calls. The first call provides a baseline and will always return 0.0.
fix
Call `psutil.cpu_percent()` (or `Process.cpu_percent()`) twice with a short time interval (e.g., 0.1 to 1 second) in between. Discard the result of the first call as it's a meaningless baseline. Example: `psutil.cpu_percent(interval=None)` then `time.sleep(0.1)` then `psutil.cpu_percent(interval=None)`.
AttributeError: module 'psutil' has no attribute 'some_attribute'
You are attempting to access a function or attribute that does not exist in the installed version of psutil, or your script might be shadowed by a local file named `psutil.py`.
fix
Ensure `psutil` is updated to the latest version (`pip install --upgrade psutil`) and verify the attribute/method name against the official psutil documentation. Also, check if there's any file named `psutil.py` in your project directory that might be conflicting with the installed library.
Upgrade
Version history
7.2.2latest on PyPI · released Jan 28, 2026
Audit
Dependencies
psutilrequiredpsutil is a standalone library and does not have external dependencies.
Agent activity
43 hits · last 30 days
node
38
OpenAI (training)
2
Resources
psutil — pip install psutil · libregistry