psutil
module?In Python, psutil
(Python system and process utilities) is a package that retrieves information on ongoing processes and system usage (CPU, memory, storage, network, and sensors). It is mostly used for system monitoring, profiling, restricting process resources, and process management.
The module can be installed via pip
as follows:
pip install psutil
disk_partitions
methodThe disk_partitions
method retrieves information on all the mounted disk partitions. This method returns a named tuple with the following attributes:
device
: This represents the device path.mountpoint
: This represents the mount point path.fstype
: This represents the partition filesystem, for example, “ext3” on UNIX or “NTFS” on Windows.opts
: This represents a comma-separated string indicating different mount options for the drive/partition. This attribute is platform-dependent.maxfile
: This represents the maximum length a file name can have.maxpath
: This represents the maximum length a path name (including the directory name and the base filename) can have.psutil.disk_partitions(all=False)
all
: If this is False
, the method tries to differentiate and return only physical devices (such as hard discs, CD-ROM drives, and USB keys). It ignores everything else (e.g., pseudo, memory, duplicate, inaccessible filesystems).import psutilprint("All disk partitions: ")print(psutil.disk_partitions())
psutil
module.psutil.disk_partitions()
method.