Skip to main content

A simple Python module to retrieve battery information on Linux-based operating system. No ACPI or external software is needed. Only the Linux kernel and its /sys/class/power_supply folder.

A simple example says more than thousand words:

In [1]: import batinfo In [2]: bat = batinfo.Batteries() In [3]: bat Out[3]: <batinfo.Battery.Batteries at 0x31c87d0> In [4]: bat.stat Out[4]: [{“status”: “Full”, “capacity”: 50, “name”: “CMB1”, “uevent”: “POWER_SUPPLY_NAME=CMB1nPOWER_SUPPLY_STATUS=FullnPOWER_SUPPLY_PRESENT=1nPOWER_SUPPLY_TECHNOLOGY=Li-ionnPOWER_SUPPLY_CYCLE_COUNT=0nPOWER_SUPPLY_VOLTAGE_MIN_DESIGN=10800000nPOWER_SUPPLY_VOLTAGE_NOW=12496000nPOWER_SUPPLY_CURRENT_NOW=0nPOWER_SUPPLY_CHARGE_FULL_DESIGN=5800000nPOWER_SUPPLY_CHARGE_FULL=5800000nPOWER_SUPPLY_CHARGE_NOW=3900000nPOWER_SUPPLY_CAPACITY=100nPOWER_SUPPLY_MODEL_NAME=CP293550-01nPOWER_SUPPLY_MANUFACTURER=FujitsunPOWER_SUPPLY_SERIAL_NUMBER=01A-Z100320001158Z”, “alarm”: 0, “charge_full”: 5800000, “voltage_now”: 12496000, “serial_number”: “01A-Z100320001158Z”, “cycle_count”: 0, “current_now”: 0, “charge_now”: 3900000, “voltage_min_design”: 10800000, “path”: “/sys/class/power_supply/CMB1”, “technology”: “Li-ion”, “manufacturer”: “Fujitsu”, “type”: “Battery”, “model_name”: “CP293550-01”, “present”: 1, “charge_full_design”: 5800000}] In [6]: bat.stat[0] Out[6]: {“status”: “Full”, “capacity”: 100, “name”: “CMB1”, “uevent”: “POWER_SUPPLY_NAME=CMB1nPOWER_SUPPLY_STATUS=FullnPOWER_SUPPLY_PRESENT=1nPOWER_SUPPLY_TECHNOLOGY=Li-ionnPOWER_SUPPLY_CYCLE_COUNT=0nPOWER_SUPPLY_VOLTAGE_MIN_DESIGN=10800000nPOWER_SUPPLY_VOLTAGE_NOW=12496000nPOWER_SUPPLY_CURRENT_NOW=0nPOWER_SUPPLY_CHARGE_FULL_DESIGN=5800000nPOWER_SUPPLY_CHARGE_FULL=5800000nPOWER_SUPPLY_CHARGE_NOW=3900000nPOWER_SUPPLY_CAPACITY=100nPOWER_SUPPLY_MODEL_NAME=CP293550-01nPOWER_SUPPLY_MANUFACTURER=FujitsunPOWER_SUPPLY_SERIAL_NUMBER=01A-Z100320001158Z”, “alarm”: 0, “charge_full”: 5800000, “voltage_now”: 12496000, “serial_number”: “01A-Z100320001158Z”, “cycle_count”: 0, “current_now”: 0, “charge_now”: 3900000, “voltage_min_design”: 10800000, “path”: “/sys/class/power_supply/CMB1”, “technology”: “Li-ion”, “manufacturer”: “Fujitsu”, “type”: “Battery”, “model_name”: “CP293550-01”, “present”: 1, “charge_full_design”: 5800000} In [7]: bat.stat[0].capacity Out[7]: 50 In [8]: print bat.stat[0] 100 In [9]: bat.stat[0].manufacturer Out[9]: ‘Fujitsu’ In [9]: bat.stat[0].technology Out[9]: ‘Li-ion’ In [11]: bat.stat[0].charge_full Out[11]: 5800000 In [12]: bat.stat[0].charge_now Out[12]: 3900000 In [12]: bat.update() > Refresh the stats

Have fun…

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batinfo-0.4.2.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file batinfo-0.4.2.tar.gz.

File metadata

  • Download URL: batinfo-0.4.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for batinfo-0.4.2.tar.gz
Algorithm Hash digest
SHA256 497e29efc9353ec52e71d43bd040bdfb6d685137ddc2b9143cded4583af572f5
MD5 6657b6893afa4fead478844aeefca09c
BLAKE2b-256 a351a0a9ad2d19bb498f2779754209ca80b7ea53f948995367a2bf408b2bef7c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.2 This release

1 file

0.4.1

1 file

0.4

1 file

0.3

1 file

0.2

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

0.1.2

0.1.1

0.1

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page