Skip to main content

battery-guard

A Python library to pause work until the battery is charged enough to continue

Designed for power-hungry laptops connected to slow chargers.

Use it as a decorator on your methods. In the example below, each call to process first checks the battery. If it is below 25%, execution is paused until it is back at or above that same 25%.

from battery_guard import battery_guard

@battery_guard(minimum=25)
def process(item):
    ...  # a power hungry task probably

for item in items:
    process(item)

The battery is only checked when the decorated function is called, a call that is already running is never paused. It therefore works best on a function that is called repeatedly, like the body of a loop, rather than on one long-running function.

To pause when the battery dips below 20%, and only continue once it has charged back up to 30%, pass resume as well:

@battery_guard(minimum=20, resume=30)

When there is no function to decorate, for example in a notebook cell, block directly:

from battery_guard import wait_for_battery

wait_for_battery(minimum=25)

Logging

Messages are emitted through the standard logging module, under the battery_guard logger. Warnings (such as failing to read the battery status) are shown by default. To also see when execution pauses and resumes, enable INFO level, or DEBUG to see every battery check:

import logging

logging.basicConfig(level=logging.INFO)

Metadata

Release files for battery-guard 2026.10.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for battery-guard 2026.10.19
File Size Uploaded Provenance Actions
battery_guard-2026.10.19.tar.gz 3.7 kB Without provenance Details for battery_guard-2026.10.19.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for battery-guard 2026.10.19
File Interpreter ABI Platform Actions
battery_guard-2026.10.19-py3-none-any.whl Python 3 none any Details for battery_guard-2026.10.19-py3-none-any.whl

Total release size: 8.2 kB

Release files / battery_guard-2026.10.19.tar.gz

Download URL battery_guard-2026.10.19.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3472a182e1186473f548c999f4772710f934b135c7f3d0b685ca296ea11ab3db
BLAKE2b-256 checksum
How to use checksums
6ad12b169b728bf86ec4518e26effbb7cb2d03f0cd289190408d01e09133474b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / battery_guard-2026.10.19-py3-none-any.whl

Download URL battery_guard-2026.10.19-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94832da11486989ad9bf9b10b818546664b7c6f35df0a01ce223e2e655c5dbdc
BLAKE2b-256 checksum
How to use checksums
4c7046743eb8aef1092632576bdb492d94da391032abac7f4b89faef2355a817
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for battery-guard 2026.10.19

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.

Release history Release notifications | RSS feed

This release

2026.10.19 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page