Keep Awake
Prevent your system and screen from going to sleep. Useful for long-running computations, downloads, or any task that requires the system to stay active.
Installation
pip install keep_awake
On Linux, install with the linux extra to pull in the D-Bus dependency:
pip install keep_awake[linux]
Usage
from keep_awake import prevent_sleep, allow_sleep
prevent_sleep() # returns True if successful
# ... do your long-running work ...
allow_sleep()
Or use the context manager for automatic cleanup:
from keep_awake import KeepAwakeGuard
with KeepAwakeGuard():
# system stays awake within this block
pass
Notes
prevent_sleep()returns aboolindicating success.allow_sleep()is safe to call multiple times or without a priorprevent_sleep().- If the process exits without calling
allow_sleep(), the system will resume normal power management automatically. - All methods are thread-safe on every platform.
Supported Platforms
| Platform | Architecture | Implementation |
|---|---|---|
| macOS | arm64, x86_64 | IOKit + CoreFoundation (C extension) |
| Windows | x86_64 | SetThreadExecutionState (C extension) |
| Linux | any | D-Bus (org.freedesktop.ScreenSaver), supports GNOME & KDE |
Linux Prerequisites
If pip install keep_awake[linux] fails, install these system packages first:
# Debian / Ubuntu
sudo apt install cmake pkg-config libdbus-1-dev libglib2.0-dev
# Fedora
sudo dnf install cmake pkg-config dbus-devel glib2-devel
Development
This project uses uv for dependency management.
# Build
uv build
# Build C extension in-place (macOS / Windows only)
uv run setup.py build_ext --inplace
# Run tests
uv run pytest
License
MIT
Release files for keep-awake 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keep_awake-1.1.3.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keep_awake-1.1.3-cp314-cp314-macosx_26_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 26.0+ ARM64 | Details |
Total release size: 14.3 kB
Release files / keep_awake-1.1.3.tar.gz
| Download URL | keep_awake-1.1.3.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bb8366fa156ad479bec9d25e569b1530c9c26de75c794192dae7215769957a1
|
|
BLAKE2b-256 checksum How to use checksums |
d401d71a89ee927f997dd49bd3aa96f6667029256e0dfcb10431e2026b0d7a0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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 / keep_awake-1.1.3-cp314-cp314-macosx_26_0_arm64.whl
| Download URL | keep_awake-1.1.3-cp314-cp314-macosx_26_0_arm64.whl |
|---|---|
| Size | 7.3 kB |
| Tags | CPython 3.14 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0029def70eef5e323a6ecb44ada9b9c2db134c582dcd836b47473ec652e6314c
|
|
BLAKE2b-256 checksum How to use checksums |
255efc5e5557a41c7bc1bf1b9bedf6b3a9e86febd3dad0b1236e3d6c38ea0be6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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}
|