Skip to main content

psutil is a cross-platform library for retrieving information onrunning processes and system utilization (CPU, memory, disks, network)in Python.

Project description

Downloads this month Linux tests (Travis) Windows tests (Appveyor) Test coverage (coverall.io) Latest version Github stars Code quality (scrutinizer-ci.com) License

Summary

psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, FreeBSD and Sun Solaris, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.5 (users of Python 2.4 and 2.5 may use 2.1.3 version). PyPy is also known to work.

Example applications

top nettop iotop

See also:

Example usages

CPU

>>> import psutil
>>> psutil.cpu_times()
scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, guest=0, nice=0.0)
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1)
...
4.0
5.9
3.8
>>>
>>> for x in range(3):
...     psutil.cpu_percent(interval=1, percpu=True)
...
[4.0, 6.9, 3.7, 9.2]
[7.0, 8.5, 2.4, 2.1]
[1.2, 9.0, 9.9, 7.2]
>>>
>>>
>>> for x in range(3):
...     psutil.cpu_times_percent(interval=1, percpu=False)
...
scputimes(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
>>>
>>> psutil.cpu_count()
4
>>> psutil.cpu_count(logical=False)
2
>>>

Memory

>>> psutil.virtual_memory()
svmem(total=8374149120, available=2081050624, percent=75.1, used=8074080256, free=300068864, active=3294920704, inactive=1361616896, buffers=529895424, cached=1251086336)
>>> psutil.swap_memory()
sswap(total=2097147904, used=296128512, free=1801019392, percent=14.1, sin=304193536, sout=677842944)
>>>

Disks

>>> psutil.disk_partitions()
[sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
 sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')]
>>>
>>> psutil.disk_usage('/')
sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
>>>
>>> psutil.disk_io_counters(perdisk=False)
sdiskio(read_count=719566, write_count=1082197, read_bytes=18626220032, write_bytes=24081764352, read_time=5023392, write_time=63199568)
>>>

Network

>>> psutil.net_io_counters(pernic=True)
{'eth0': netio(bytes_sent=485291293, bytes_recv=6004858642, packets_sent=3251564, packets_recv=4787798, errin=0, errout=0, dropin=0, dropout=0),
 'lo': netio(bytes_sent=2838627, bytes_recv=2838627, packets_sent=30567, packets_recv=30567, errin=0, errout=0, dropin=0, dropout=0)}
>>>
>>> psutil.net_connections()
[pconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 48776), raddr=('93.186.135.91', 80), status='ESTABLISHED', pid=1254),
 pconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 43761), raddr=('72.14.234.100', 80), status='CLOSING', pid=2987),
 pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 60759), raddr=('72.14.234.104', 80), status='ESTABLISHED', pid=None),
 pconn(fd=-1, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 51314), raddr=('72.14.234.83', 443), status='SYN_SENT', pid=None)
 ...]
>>>
>>> psutil.net_if_addrs()
{'lo': [snic(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1', ptp=None),
        snic(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None, ptp=None),
        snic(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00', ptp=None)],
 'wlan0': [snic(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),
           snic(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None, ptp=None),
           snic(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}
>>>
>>> psutil.net_if_stats()
{'eth0': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=100, mtu=1500),
 'lo': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=65536)}

Other system info

>>> psutil.users()
[user(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0),
 user(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0)]
>>>
>>> psutil.boot_time()
1365519115.0
>>>

Process management

>>> import psutil
>>> psutil.pids()
[1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224,
 268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355,
 2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245,
 4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358,
 4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235,
 5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071]
>>>
>>> p = psutil.Process(7055)
>>> p.name()
'python'
>>> p.exe()
'/usr/bin/python'
>>> p.cwd()
'/home/giampaolo'
>>> p.cmdline()
['/usr/bin/python', 'main.py']
>>>
>>> p.status()
'running'
>>> p.username()
'giampaolo'
>>> p.create_time()
1267551141.5019531
>>> p.terminal()
'/dev/pts/0'
>>>
>>> p.uids()
puids(real=1000, effective=1000, saved=1000)
>>> p.gids()
pgids(real=1000, effective=1000, saved=1000)
>>>
>>> p.cpu_times()
pcputimes(user=1.02, system=0.31)
>>> p.cpu_percent(interval=1.0)
12.1
>>> p.cpu_affinity()
[0, 1, 2, 3]
>>> p.cpu_affinity([0])  # set
>>>
>>> p.memory_percent()
0.63423
>>>
>>> p.memory_info()
pmem(rss=7471104, vms=68513792)
>>> p.memory_info_ex()
extmem(rss=9662464, vms=49192960, shared=3612672, text=2564096, lib=0, data=5754880, dirty=0)
>>> p.memory_maps()
[pmmap_grouped(path='/lib/x86_64-linux-gnu/libutil-2.15.so', rss=16384, anonymous=8192, swap=0),
 pmmap_grouped(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=6384, anonymous=15, swap=0),
 pmmap_grouped(path='/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', rss=34124, anonymous=1245, swap=0),
 pmmap_grouped(path='[heap]', rss=54653, anonymous=8192, swap=0),
 pmmap_grouped(path='[stack]', rss=1542, anonymous=166, swap=0),
 ...]
>>>
>>> p.io_counters()
pio(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632)
>>>
>>> p.open_files()
[popenfile(path='/home/giampaolo/svn/psutil/somefile', fd=3)]
>>>
>>> p.connections()
[pconn(fd=115, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 48776), raddr=('93.186.135.91', 80), status='ESTABLISHED'),
 pconn(fd=117, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 43761), raddr=('72.14.234.100', 80), status='CLOSING'),
 pconn(fd=119, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 60759), raddr=('72.14.234.104', 80), status='ESTABLISHED'),
 pconn(fd=123, family=<AddressFamily.AF_INET: 2>, type=<SocketType.SOCK_STREAM: 1>, laddr=('10.0.0.1', 51314), raddr=('72.14.234.83', 443), status='SYN_SENT')]
>>>
>>> p.num_threads()
4
>>> p.num_fds()
8
>>> p.threads()
[pthread(id=5234, user_time=22.5, system_time=9.2891),
 pthread(id=5235, user_time=0.0, system_time=0.0),
 pthread(id=5236, user_time=0.0, system_time=0.0),
 pthread(id=5237, user_time=0.0707, system_time=1.1)]
>>>
>>> p.num_ctx_switches()
pctxsw(voluntary=78, involuntary=19)
>>>
>>> p.nice()
0
>>> p.nice(10)  # set
>>>
>>> p.ionice(psutil.IOPRIO_CLASS_IDLE)  # IO priority (Win and Linux only)
>>> p.ionice()
pionice(ioclass=<IOPriority.IOPRIO_CLASS_IDLE: 3>, value=0)
>>>
>>> p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))  # set resource limits (Linux only)
>>> p.rlimit(psutil.RLIMIT_NOFILE)
(5, 5)
>>>
>>> p.suspend()
>>> p.resume()
>>>
>>> p.terminate()
>>> p.wait(timeout=3)
0
>>>
>>> psutil.test()
USER         PID %CPU %MEM     VSZ     RSS TTY        START    TIME  COMMAND
root           1  0.0  0.0   24584    2240            Jun17   00:00  init
root           2  0.0  0.0       0       0            Jun17   00:00  kthreadd
root           3  0.0  0.0       0       0            Jun17   00:05  ksoftirqd/0
...
giampaolo  31475  0.0  0.0   20760    3024 /dev/pts/0 Jun19   00:00  python2.4
giampaolo  31721  0.0  2.2  773060  181896            00:04   10:30  chrome
root       31763  0.0  0.0       0       0            00:05   00:00  kworker/0:1
>>>

Further process APIs

>>> for p in psutil.process_iter():
...     print(p)
...
psutil.Process(pid=1, name='init')
psutil.Process(pid=2, name='kthreadd')
psutil.Process(pid=3, name='ksoftirqd/0')
...
>>>
>>> def on_terminate(proc):
...     print("process {} terminated".format(proc))
...
>>> # waits for multiple processes to terminate
>>> gone, alive = psutil.wait_procs(procs_list, 3, callback=on_terminate)
>>>

Mailing list

http://groups.google.com/group/psutil/

Timeline

Release history Release notifications | RSS feed

This version

3.2.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psutil-3.2.2.tar.gz (253.5 kB view details)

Uploaded Source

Built Distributions

psutil-3.2.2.win-amd64-py3.5.exe (242.5 kB view details)

Uploaded Source

psutil-3.2.2.win-amd64-py3.3.exe (325.6 kB view details)

Uploaded Source

psutil-3.2.2.win-amd64-py2.7.exe (327.2 kB view details)

Uploaded Source

psutil-3.2.2.win32-py3.5.exe (232.4 kB view details)

Uploaded Source

psutil-3.2.2.win32-py3.4.exe (292.5 kB view details)

Uploaded Source

psutil-3.2.2.win32-py3.3.exe (292.1 kB view details)

Uploaded Source

psutil-3.2.2.win32-py2.6.exe (297.3 kB view details)

Uploaded Source

psutil-3.2.2-cp35-none-win_amd64.whl (93.3 kB view details)

Uploaded CPython 3.5 Windows x86-64

psutil-3.2.2-cp35-none-win32.whl (90.4 kB view details)

Uploaded CPython 3.5 Windows x86

psutil-3.2.2-cp34-none-win_amd64.whl (90.5 kB view details)

Uploaded CPython 3.4 Windows x86-64

psutil-3.2.2-cp34-none-win32.whl (88.2 kB view details)

Uploaded CPython 3.4 Windows x86

psutil-3.2.2-cp33-none-win_amd64.whl (90.5 kB view details)

Uploaded CPython 3.3 Windows x86-64

psutil-3.2.2-cp33-none-win32.whl (88.2 kB view details)

Uploaded CPython 3.3 Windows x86

psutil-3.2.2-cp27-none-win_amd64.whl (90.6 kB view details)

Uploaded CPython 2.7 Windows x86-64

psutil-3.2.2-cp27-none-win32.whl (88.2 kB view details)

Uploaded CPython 2.7 Windows x86

psutil-3.2.2-cp26-none-win32.whl (88.4 kB view details)

Uploaded CPython 2.6 Windows x86

File details

Details for the file psutil-3.2.2.tar.gz.

File metadata

  • Download URL: psutil-3.2.2.tar.gz
  • Upload date:
  • Size: 253.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for psutil-3.2.2.tar.gz
Algorithm Hash digest
SHA256 f9d848e5bd475ffe7fa3ab1c20d249807e648568af64bb0058412296ec990a0c
MD5 56df1727c9e26076a80da4c3f8f67976
BLAKE2b-256 dcb2ab65a2209b996c891209b8a7444a0c825125fba850efaec07b95bccb3ff5

See more details on using hashes here.

File details

Details for the file psutil-3.2.2.win-amd64-py3.5.exe.

File metadata

File hashes

Hashes for psutil-3.2.2.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 9afc68c02717fb4416f91b3c2da4c407756f683804383d1499cdc9e1512e7942
MD5 d020b1838cb0521ed22b58c656b07cbc
BLAKE2b-256 1d0b9582cadcba005f4eb0207107baeae7eb2382431fea5e4bc0ea7ce683430f

See more details on using hashes here.

File details

Details for the file psutil-3.2.2.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for psutil-3.2.2.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 01a1f55819019ad13c288c41cb233e17a6ee648baf19591a70f6c2c2295dde6c
MD5 09e8ff28d15a0850edc1da3a7af1b7fc
BLAKE2b-256 5d89b3bfca24d038b16af09055912e3a5bc35347ebeb0e6af322959b68dbf237

See more details on using hashes here.

File details

Details for the file psutil-3.2.2.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for psutil-3.2.2.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 1fca15005063b401cbf94cebe3c01ef6ba3d86ba563730d5d5d6be962a637cf4
MD5 ce34dda716f92ccc7941ed3a6b4acb77
BLAKE2b-256 017c47b7ac498c9dd6ac9f9b4489d3bd9cea8158e774592661a7c956a815dc78

See more details on using hashes here.

File details

Details for the file psutil-3.2.2.win32-py3.5.exe.

File metadata

File hashes

Hashes for psutil-3.2.2.win32-py3.5.exe
Algorithm Hash digest
SHA256 f0e88f94f9822fd34bcd927aba4bb606bcb0ad0dda1543c9333e8175d5c05822
MD5 12b4c5ae85f7f6be289aec08866e4ea7
BLAKE2b-256 1db8b725f9bd884f75ce141a9e871a79b2bdd1b5f31e814fc4e396d9ff7c98a2

See more details on using hashes here.

File details

Details for the file psutil-3.2.2.win32-py3.4.exe.

File metadata

File hashes

Hashes for psutil-3.2.2.win32-py3.4.exe
Algorithm Hash digest
SHA256 d5c96aa591ba711dfdadb1ab7a0adf08c5e637644a21437f3a39a9e427aa969b
MD5 0241ee8daa99a14deeea54065c6e41d6
BLAKE2b-256 28fc08f1098976de5416cd15967d88e03297569e9a34ca875e7dee38ff9150f0

See more details on using hashes here.

File details

Details for the file psutil-3.2.2.win32-py3.3.exe.

File metadata

File hashes

Hashes for psutil-3.2.2.win32-py3.3.exe
Algorithm Hash digest
SHA256 5168f99f065f6116ad1e8529bd5dd5309815198c6250c9180ff6058c6a3641d9
MD5 4432ab7a3dce090ece45d73b51c7aaaf
BLAKE2b-256 8e868f1e1c0ffc0530dca5e71777f04fb90833c92d3ffc1d075b8b546874eae5

See more details on using hashes here.

File details

Details for the file psutil-3.2.2.win32-py2.6.exe.

File metadata

File hashes

Hashes for psutil-3.2.2.win32-py2.6.exe
Algorithm Hash digest
SHA256 c7c516a83d072d1a375ed3a0b5a1b1b9307ad839011e8d30aa16b0f932f6c481
MD5 8084cbc65645a789defb85d97bca48ca
BLAKE2b-256 66e4bb85391bb46b607be0578e0a091bc064daeb2d1c2e80aa2dab89260dff00

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp35-none-win_amd64.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 d3ac8ad04a509819d7b5d58e453749a3ceb37253267dac6e8856ea7953e22ca0
MD5 ea2c8811e3eb92ce2377a6db62a492bd
BLAKE2b-256 03c515e44d590afc788228e93cdacf55f98828f326de985242bbf03b3545b129

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp35-none-win32.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp35-none-win32.whl
Algorithm Hash digest
SHA256 76c68c9005a2aa983fce440ef98b66e6f200f740f52064a90fdcc30d11771bc2
MD5 19badf29ec31cdb56d57c7cb28a3588c
BLAKE2b-256 cb79fcedcf009ab9f8c605f2f345b1797b72134ecc6c9c9f786575e34b3471bc

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp34-none-win_amd64.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 e321d3f029268bc8442a7ff214da43fe91041924898f5e23d88bfda7ecb81acc
MD5 a8dcf65e8108ac37c0a2753b760b7ac1
BLAKE2b-256 edfef31bb708dfdecfbc59b946ecb9ee3379fe7a8183c37ea6c43d6f4da5117d

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp34-none-win32.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp34-none-win32.whl
Algorithm Hash digest
SHA256 3df8d3e32e2b4f7c2ea91014294844670eddb125ba76c24152c0a155a1f73b5b
MD5 a984de0e324de12b306715a3319af0b5
BLAKE2b-256 626eee3597f32c650f744359e57fd18bcede773dd7465d392dabbb008bc79b48

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp33-none-win_amd64.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp33-none-win_amd64.whl
Algorithm Hash digest
SHA256 65c78ba625cf9761d5966603838cc959f396bd03536c480db69f8cf37bdf9994
MD5 d69fbf5de44e2bc345c497abc3de8ae5
BLAKE2b-256 59333ccdbec4ef1452758ba80f711af46736717f63d73786744d6251afb68624

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp33-none-win32.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp33-none-win32.whl
Algorithm Hash digest
SHA256 f8fb145f8fa9e223696ff2f99924ea42538f3ad6b9738707292d840acbde528f
MD5 15645584ee24cff8c194ebd8b3ac4acf
BLAKE2b-256 77f36b3742040b634692393faf3a81e6c0e40366c22bc338ad3fc62ed21b157a

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp27-none-win_amd64.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp27-none-win_amd64.whl
Algorithm Hash digest
SHA256 37f1cc8fc7586cc930ea3737533d6d79c1f761d577fd1bb1bb5798ccd1543b53
MD5 85dcf0e3e4791cd481c933ce14136f03
BLAKE2b-256 e7b7f04d64a692159733ed383b4638abd9d3dc4538d4aacb5e193af02a3840a2

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp27-none-win32.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp27-none-win32.whl
Algorithm Hash digest
SHA256 6c5809582d3d165511d2319401bd0f6c0e825d7853e49da59027c1fb8aa8f897
MD5 1cc5711b28815abd6f697f08e37103b9
BLAKE2b-256 631ea510f3f310b5f530336fbc708fb1456bf3e49e3b3d85c31d151b6e389c4f

See more details on using hashes here.

File details

Details for the file psutil-3.2.2-cp26-none-win32.whl.

File metadata

File hashes

Hashes for psutil-3.2.2-cp26-none-win32.whl
Algorithm Hash digest
SHA256 5a8ce70327c0da578a31ebbf0042671ed9be6f4b6b022c02f03302b690074966
MD5 86bb9938e137e8e99708a4b3e6806000
BLAKE2b-256 4daf5b8c2471ea942a4b6ee85706e9279284ae9dc86ee30b6f97db2d84a95433

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page