How to get battery percentage with python?

Black Thunder picture Black Thunder · Aug 11, 2017 · Viewed 13.8k times · Source

How to get battery percentage with python?
Maybe some win32api functions may help.

Answer

whackamadoodle3000 picture whackamadoodle3000 · Aug 11, 2017

Try this:

import psutil
battery = psutil.sensors_battery()
plugged = battery.power_plugged
percent = str(battery.percent)
plugged = "Plugged In" if plugged else "Not Plugged In"
print(percent+'% | '+plugged)

Library link is here. And check out this