explaingit

giampaolo/psutil

11,168PythonAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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.

Mindmap

mindmap
  root((repo))
    What it monitors
      CPU usage
      Memory and disk
      Network connections
      Running processes
    Platforms
      Linux and Windows
      macOS and BSD
      Solaris and AIX
    Use cases
      System monitoring
      Process profiling
      Admin scripts
    Setup
      pip install psutil
      Import and call
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Monitor CPU and memory usage in a Python script to detect when a server is under load.

USE CASE 2

List all running processes and their resource consumption from Python without parsing shell command output.

USE CASE 3

Check open network connections or disk usage in a cross-platform way using the same Python calls on any OS.

USE CASE 4

Build a custom monitoring tool or profiler that tracks a specific process's CPU and memory over time.

Tech stack

PythonC

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose including commercial projects, just keep the copyright notice (BSD-3 license).

In plain English

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.

Copy-paste prompts

Prompt 1
Write a Python script using psutil that monitors CPU and memory usage every 5 seconds and prints a warning when either exceeds 80%.
Prompt 2
Using psutil, find all Python processes currently running on this machine and print their PID, name, and memory usage.
Prompt 3
Write a psutil script that checks disk usage on all mounted drives and raises an alert if any is over 90% full.
Prompt 4
I want to track CPU and memory usage of a specific process by PID over 60 seconds using psutil. Show me how.
Prompt 5
Using psutil, write a function that returns a summary of all network connections grouped by state like ESTABLISHED and LISTEN.
Open on GitHub → Explain another repo

← giampaolo on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.