gitmyhub

psutil

Python ★ 11k updated 5d ago

Cross-platform lib for process and system monitoring in Python

A Python library for reading real-time system information, CPU usage, memory, disk, network connections, and running processes, with the same code working on Linux, Windows, macOS, and more.

PythonCsetup: easycomplexity 2/5

psutil is a Python library that lets your code read information about what is running on the computer and how it is using its resources. With a few lines of Python, you can find out how much of the CPU is being used, how much memory is free, what network connections are open, which processes are running, and what files a particular process has open. It covers CPU, memory, disk, network, and hardware sensors.

The library works across Linux, Windows, macOS, FreeBSD, OpenBSD, NetBSD, Solaris, and AIX, using the same Python calls regardless of the operating system. It is essentially a Python-friendly way to get the same information you would get from command-line tools like ps, top, netstat, free, and ifconfig, without having to run those tools and parse their output yourself.

Installation is through pip, the standard Python package manager, with a single command. From there, you import psutil in your code and call functions like psutil.cpu_percent(), psutil.virtual_memory(), psutil.disk_usage(), or psutil.process_iter() to get structured data back. For working with a specific process, you create a Process object using its ID and then call methods on it for things like CPU usage, memory use, open files, and network connections.

The library is widely used. The README notes it ranks among the top 100 most-downloaded packages on PyPI with over 330 million downloads per month, and more than 760,000 GitHub repositories depend on it. It is commonly used in monitoring tools, profiling scripts, and system administration utilities. The license is BSD-3, which is permissive and allows commercial use.

Where it fits