Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator
psutil

How to get the hardware's fan speed in Python

abhilash

We can retrieve our hardware’s fan speed using the psutil module in Python.

What is the psutil module?

psutil (Python system and process utilities) is a Python 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

The sensors_fans method

The sensors_fans method returns the available fans and their respective speed in revolutions per minute (RPM).

Syntax

psutil.sensors_fans()

This method has no parameters.

Code

import psutil

print("The hardware fan speed is:")

print(psutil.sensors_fans())
# If there are no fan sensors in the machine,
# then the output would be an empty dictionary.
# If there are fan sensors, 
# then the fan speed would be displayed.
Calculating the speed of the hardware fan

Code explanation

  • Line 1: We import the psutil module.
  • Line 2: We display a “The hardware fan speed is:” message.
  • Line 5: We retrieve information about the fans and their speeds using the sensors_fans() method.

RELATED TAGS

python
communitycreator
psutil
RELATED COURSES

View all Courses

Keep Exploring