Stdlib equivalents

This page maps psutil’s Python API to the closest equivalent in the Python standard library. This is useful for understanding what psutil replaces and how the two APIs differ. The most common difference is that stdlib functions only operate on the current process, while psutil works on any process (PID).

System-wide functions

CPU

psutil

stdlib

notes

cpu_count()

os.cpu_count(), multiprocessing.cpu_count()

Same as cpu_count(logical=True); no support for physical cores (logical=False). See FAQ.

cpu_count()

os.process_cpu_count()

CPUs the process is allowed to use (Python 3.13+). Equivalent to len(psutil.Process().cpu_affinity()). See FAQ.

getloadavg()

os.getloadavg()

Same on POSIX; psutil also supports Windows.

Disk

psutil

stdlib

notes

disk_usage()

shutil.disk_usage()

Same as shutil.disk_usage(); psutil also adds percent. Added to CPython 3.3 (BPO-12442).

disk_partitions()

os.listdrives(), os.listmounts(), os.listvolumes()

Windows only (Python 3.12+). Low-level APIs: drive letters, volume GUIDs, mount points. psutil combines them in one cross-platform call.

Network

psutil

stdlib

notes

net_if_addrs()

socket.if_nameindex()

Stdlib returns NIC names only; psutil also returns addresses, netmasks, broadcast, and PTP.

Process

psutil

stdlib

notes

pid_exists()

os.kill(pid, 0)

Common POSIX idiom; psutil also supports Windows.

Process methods

Assuming p = psutil.Process().

Identity

psutil

stdlib

notes

p.pid

os.getpid()

p.ppid()

os.getppid()

p.cwd()

os.getcwd()

p.environ()

os.environ

Will differ from launch environment if modified at runtime.

p.exe()

sys.executable

Python interpreter path only.

p.cmdline()

sys.argv

Python process only.

Credentials

psutil

stdlib

notes

p.uids()

os.getuid(), os.geteuid(), os.getresuid()

p.gids()

os.getgid(), os.getegid(), os.getresgid()

p.username()

os.getlogin(), getpass.getuser()

Rough equivalent; not per-process.

CPU / scheduling

psutil

stdlib

notes

p.cpu_times()

os.times()

os.times() also has elapsed; psutil adds iowait (Linux).

p.cpu_times()

resource.getrusage()

ru_utime / ru_stime match; have higher precision.

p.num_ctx_switches()

resource.getrusage()

Current process only; psutil works for any PID.

p.nice()

os.getpriority(), os.setpriority()

POSIX only; psutil also supports Windows. Added to CPython 3.3 (BPO-10784).

p.nice()

os.nice()

POSIX only; psutil also supports Windows.

no equivalent

os.sched_getscheduler(), os.sched_setscheduler()

Sets scheduling policy (SCHED_*). Unlike nice, which sets priority within SCHED_OTHER. Real-time policies preempt normal processes.

p.cpu_affinity()

os.sched_getaffinity(), os.sched_setaffinity()

Nearly equivalent; both accept a PID. Stdlib is Linux/BSD; psutil also supports Windows.

p.rlimit()

resource.getrlimit(), resource.setrlimit()

Same interface; psutil works for any PID (Linux only).

Memory

psutil

stdlib

notes

p.memory_info()

resource.getrusage()

Only peak_rss (ru_maxrss); psutil returns RSS, VMS, and more.

p.page_faults()

resource.getrusage()

Current process only.

I/O

psutil

stdlib

notes

p.io_counters()

resource.getrusage()

Block I/O only (ru_inblock / ru_oublock), current process. psutil returns bytes and counts for any PID.

Threads

psutil

stdlib

notes

p.num_threads()

threading.active_count()

Stdlib counts Python threads only; psutil counts all OS threads.

p.threads()

threading.enumerate()

Stdlib returns threading.Thread objects; psutil returns OS thread IDs with CPU times.

Signals

psutil

stdlib

notes

p.send_signal()

os.kill()

Same on POSIX; limited on Windows. psutil adds NoSuchProcess / AccessDenied and avoids killing reused PIDs.

p.suspend()

os.kill() + signal.SIGSTOP

Same as above.

p.resume()

os.kill() + signal.SIGCONT

Same as above.

p.terminate()

os.kill() + signal.SIGTERM

Same as above. On Windows uses TerminateProcess().

p.kill()

os.kill() + signal.SIGKILL

Same as above. On Windows uses TerminateProcess().

p.wait()

os.waitpid()

Child processes only; psutil works for any PID.

p.wait()

subprocess.Popen.wait()

Equivalent; psutil uses efficient OS-level waiting on Linux/BSD. Added to CPython 3.15 (cpython/PR-144047).