What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.
There seems to be a few possible ways of extracting that from my search:
-
Using a library such as PSI (that currently seems not actively developed and not supported on multiple platform) or something like pystatgrab (again no activity since 2007 it seems and no support for Windows).
-
Using platform specific code such as using a
os.popen("ps")
or similar for the *nix systems andMEMORYSTATUS
inctypes.windll.kernel32
(see this recipe on ActiveState) for the Windows platform. One could put a Python class together with all those code snippets.
It's not that those methods are bad but is there already a well-supported, multi-platform way of doing the same thing?
Best Answer
The psutil library gives you information about CPU, RAM, etc., on a variety of platforms:
Some examples:
Here's other documentation that provides more concepts and interest concepts: