Skip to main content

Cross-platform battery status

Project description

Cross-platform, Python battery status

Simply pip install battery and use like:

import battery
source = 'battery' if battery.is_discharging() else 'AC power'
print(f'On {source} at {battery.percent()}%')
health = battery.capacity() / battery.design_capacity()
print(f'Battery is at {health*100:4.1f}% health.')

The CLI always returns a JSON value:

$ python -m battery
{"is_discharging": true, "percent": 92, "minutes_to_empty": 215, "minutes_to_full": null, "capacity": 2388, "design_capacity": 4381}
$ python -m battery percent
92

Functions

The following functions are available:

  • is_discharging: True iff battery is discharging.
  • is_charging: True iff battery is charging.
  • percent: Integer percentage charge of battery.
  • minutes_to_empty: Minutes of battery life left. May be empty.
  • minutes_to_full: Minutes until the battery is charged. May be empty (or 0 if full).
  • capacity: The present capacity in mWh. mAh on macOS; on Apple Silicon this may be a percentage.
  • design_capacity: The factory capacity in mWh. mAh on macOS.

The following minimum OS versions are supported:

  • macOS 10.2 and later
  • Linux 2.6.24 and later
  • Windows Vista and later

A NotImplementedError is raised for unsupported OSes.

Pull requests and issues are always welcome for better compatibility!

Other notes

Also check out psutil!

The whole package is public domain.

Project details


Download files

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

Source Distribution

battery-1.0.4.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

battery-1.0.4-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file battery-1.0.4.tar.gz.

File metadata

  • Download URL: battery-1.0.4.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.12

File hashes

Hashes for battery-1.0.4.tar.gz
Algorithm Hash digest
SHA256 258d89699c801248704be45f082b48786f03f7047462de9cbe75841cbec3e10d
MD5 76a2ef21d9481d0e900e475fadaaa508
BLAKE2b-256 946bdd376155cb8c649573cb22c3cca2fb1b48d43b04f902e5d2cf397704721b

See more details on using hashes here.

File details

Details for the file battery-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: battery-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.12

File hashes

Hashes for battery-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b01c685a77c799520dbf7b02343c197aa6fde8f989e6865e35fc5bebb8309333
MD5 38b4c00e7f3185150e6034bfb31d3e22
BLAKE2b-256 f255e7be023a6bacffd295ec88dfb266d90c847adf46053f80c57e619a26e37f

See more details on using hashes here.

Supported by

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