Skip to main content

Prevent your computer from going to sleep.

Project description

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 a bool indicating success.
  • allow_sleep() is safe to call multiple times or without a prior prevent_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

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

keep_awake-1.1.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

keep_awake-1.1.3-cp314-cp314-macosx_26_0_arm64.whl (7.3 kB view details)

Uploaded CPython 3.14macOS 26.0+ ARM64

File details

Details for the file keep_awake-1.1.3.tar.gz.

File metadata

  • Download URL: keep_awake-1.1.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for keep_awake-1.1.3.tar.gz
Algorithm Hash digest
SHA256 8bb8366fa156ad479bec9d25e569b1530c9c26de75c794192dae7215769957a1
MD5 2ea1e8dc63f2ddb0aaf68653ba2f4b9d
BLAKE2b-256 d401d71a89ee927f997dd49bd3aa96f6667029256e0dfcb10431e2026b0d7a0e

See more details on using hashes here.

File details

Details for the file keep_awake-1.1.3-cp314-cp314-macosx_26_0_arm64.whl.

File metadata

  • Download URL: keep_awake-1.1.3-cp314-cp314-macosx_26_0_arm64.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: CPython 3.14, macOS 26.0+ ARM64
  • Uploaded using 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}

File hashes

Hashes for keep_awake-1.1.3-cp314-cp314-macosx_26_0_arm64.whl
Algorithm Hash digest
SHA256 0029def70eef5e323a6ecb44ada9b9c2db134c582dcd836b47473ec652e6314c
MD5 00a220c8ac6669990932fb98d10c0f49
BLAKE2b-256 255efc5e5557a41c7bc1bf1b9bedf6b3a9e86febd3dad0b1236e3d6c38ea0be6

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