psutil is a cross-platform library for retrieving information on running processes and system utilization(CPU, memory, disks, networks, sensors) in Python. The Python script below can be run in both Windows and Linux. Install psutil in windows by :
pip install psutil
Install psutil in Linux by:
sudo apt-get install gcc python3-dev sudo pip3 install psutil
Battery percentage : 57 Power plugged in : False Battery left : 1:58:32
psutil.sensors.battery() returns a named tuple consisting of following values. If no battery is installed or metrics can’t be determined None is returned.
- percent: Power left in percentage.
- secsleft: Approx seconds left before the power runs out. It is set to psutil.POWER_TIME_UNLIMITED if it is on charging. If this value can’t be determined it is set to psutil.POWER_TIME_UNKNOWN .
- power_plugged: True if power is plugged in, False if it isn’t charging or None if it can’t be determined.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Create Battery Notifier for Laptop using Python
- How to Control Laptop Screen Brightness using Python?
- Python | Sort a list of percentage
- Python | Percentage occurrence at index
- Python | Percentage similarity of lists
- Python | Percentage increase in the total surface area of the cuboid
- Python | Percentage increase in hemisphere volume if radius is increased
- Python - Maximum consecutive elements percentage change
- Cumulative percentage of a column in Pandas - Python
- Calulate Bodyfat Percentage with skinfold measurements using Python
- Python - Calculate the percentage of positive elements of the list
- PyQt5 | How to set percentage indicator in middle of Progress Bar ?
- PyQt5 - How to get percentage of Progress Bar ?
- PyQt5 - How to remove the percentage symbol from the Progress Bar ?
- How to calculate the Percentage of a column in Pandas ?
- Stacked Percentage Bar Plot In MatPlotLib
- Python | Add Logging to a Python Script
- Python script to open a Google Map location on clipboard
- Run Python script from Node.js using child process spawn() method
- Autorun a Python script on windows startup
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.