Home

PSI - Python System Information

PSI is a Python package providing real-time access to processes and other miscellaneous system information such as architecture, boottime and filesystems. It has a pythonic API which is consistent accross all supported platforms but also exposes platform-specific details where desirable.

>>> import pwd
>>> import psi
>>> import psi.process
>>> for p in psi.process.ProcessTable().values():
...     if 'postfix' in p.command:
...         break
... 
>>> p.command
'/usr/lib/postfix/master'
>>> pwd.getpwuid(p.euid).pw_name
'root'
>>> p.children()
FutureWarning: Experimental method
[psi.process.Process(pid=30381), psi.process.Process(pid=16111), psi.process.Process(pid=30034)]
>>> 'RSS: %.2f Kb' % (p.rss / 1024.0)
'RSS: 1904.00 Kb'
>>> str(p.cputime.timedelta())
'0:00:02.040000'
>>> str(p.start_time.datetime())
'2009-07-29 09:06:28.780872'
>>> str(psi.boottime().datetime())
'2009-07-29 08:58:04'

Under the hood it is mostly implemented as a number of extension modules written in C. This offers the most flexible way to retrieve system-depended information on all platforms leveraging native system calls and core library APIs while avoiding any other external dependencies.

Currently the supported platforms include Linux, Darwin, SunOS and AIX and all versions of Python starting from 2.2 are supported, including the 3.x series. In the future platform support for at least Windows and BSD are planned, as well as more modules providing access to other areas of the system such as memory, CPU, network interfaces etc.

All of PSI is available under the MIT license.

News

21 November 2009 - PSI 0.3b2 released

Version 0.3b2 has been released and is available for download from PyPI. It has many improvements:

  • Improved handling of time.
  • Improved handling of process names and arguments which simplifies usage by promising availability for some attributes.
  • New experimental methods on Process objects: .children() and .kill().
  • The ability to get the process list from a 64-bit process while running in a 32-bit python on Solaris.
  • New experimental mount module.

And many more small fixes and improvements!

12 August 2009 - PSI Lightning Talks

Floris and Chris recently gave lightning talks about PSI at EuroPython 2009 and MelbournePUG respectively. See Presentations for the slides.

TOC

Related Projects

psutil

psutil is a project with similar goals but more centered around just processes and the API follows a different style.

    psutil is a module providing an interface for retrieving information
    on running processes and system utilization (CPU, memory) in a
    portable way by using Python, implementing many functionalities
    offered by tools like ps, top and Windows task manager.

    It currently supports Linux, OS X, FreeBSD and Windows

pyutmp

pyutmp is a module providing a Python binding for UNIX utmp(x) files.

    The pyutmp module provides a Python-oriented interface to the utmp
    file on Unix-like operating systems. To paraphrase the Linux
    Programmer's Manual page utmp(5), the utmp file allows one to discover
    information about who is currently using (i.e., is logged into) the
    system. The utmp file is a series of entries whose structure is
    typically defined by the "utmp.h" C header file.

    This module provides an read-only interface to the underlying
    operating system's C utmp API.

python-prctl

The python-prctl module allows you to control process attributes on Linux. This includes setting it's name and capabilities.

   The linux prctl function allows you to control specific characteristics of a
   process' behaviour. Usage of the function is fairly messy though, due to
   limitations in C and linux. This module provides a nice non-messy python(ic)
   interface.

   Besides prctl, this library also wraps libcap for complete capability handling
   and allows you to set the process name as seen in ps and top.

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.