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.
Metadata
Release files for battery 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| battery-1.0.4.tar.gz | 9.0 kB | Without provenance | Details for battery-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| battery-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for battery-1.0.4-py3-none-any.whl |
Total release size: 18.5 kB
Release files / battery-1.0.4.tar.gz
| Download URL | battery-1.0.4.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
258d89699c801248704be45f082b48786f03f7047462de9cbe75841cbec3e10d
|
|
BLAKE2b-256 checksum How to use checksums |
946bdd376155cb8c649573cb22c3cca2fb1b48d43b04f902e5d2cf397704721b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.12
|
Release files / battery-1.0.4-py3-none-any.whl
| Download URL | battery-1.0.4-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b01c685a77c799520dbf7b02343c197aa6fde8f989e6865e35fc5bebb8309333
|
|
BLAKE2b-256 checksum How to use checksums |
f255e7be023a6bacffd295ec88dfb266d90c847adf46053f80c57e619a26e37f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.12
|
Security for battery 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.