Skip to main content

Prevent your computer from going to sleep.

Project description

Keep Awake

Keep your system on and screen on, it will not fall asleep. It is useful in some long term calculations.

How to use?

pip install keep_awake

This module exposes only two methods: prevent_sleep and allow_sleep, both of them taks no arguments.

prevent_sleep returns a boolean value that indicates whether the operation is successful. After you call this method, your system and screen will keep working until you invoke allow_sleep.

You won't have any exceptions by calling any methods twice, or calling allow_sleep without calling prevent_sleep, they have built-in protection.

If you forget to call allow_sleep before exiting your program, it doesn't matter, it will back to usual once the module is released.

We also provide a context manager for you to manage the state automatically, just like this:

from keep_awake import KeepAwakeGuard

with KeepAwakeGuard():
    # do your work here

Supported platforms

macOS✅

Both arm64 and x64 are OK, this code only depends on IOKit and CoreFoundation, which is built-in macOS Framework.

Methods on macOS are concurrent safe.

Windows✅

We didn't test widely on various versions of Windows because I have no more Windows computer :(

But basically, it can work fine on Windows 10 x64 and Windows 11 x64. I have already tested.

Methods on Windows are concurrent safe.

Linux⚠️

Linux distros are various, we can only support Gnome and KDE. They have dbus api so this part is implemented in pure python. If you need this feature, please install with this command:

pip install keep_awake[linux]

If you failed to install, try to use your package manager to install cmake, pkg-config, libdbus-1-dev and libglib2.0-dev.

Methods on Linux are concurrent safe.

Building & Debugging

We use uv to manage the project, so it is very easy to build and test it.

For building:

uv build

For testing

uv run pytest

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.2.tar.gz (7.4 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.2-cp314-cp314-macosx_26_0_arm64.whl (8.0 kB view details)

Uploaded CPython 3.14macOS 26.0+ ARM64

File details

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

File metadata

  • Download URL: keep_awake-1.1.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.2.tar.gz
Algorithm Hash digest
SHA256 7783d4244b89a9c646a5d150d20640e902ffe514a8bf49c7946e129ed1eaab60
MD5 ced03857e61ca554f582f7e8e33147ca
BLAKE2b-256 6dfd613bbca99c5b28723f8df3090c594171df0b449398f51f1698931e6a910c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: keep_awake-1.1.2-cp314-cp314-macosx_26_0_arm64.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: CPython 3.14, macOS 26.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.2-cp314-cp314-macosx_26_0_arm64.whl
Algorithm Hash digest
SHA256 d018b6411da57111e0822f128be8ce7efaf8cbc01ad787f243d6a1940079b452
MD5 ed4ff13c584a64d3d18a399c17eb2e68
BLAKE2b-256 addb0291938f149752e597342376dad53bfac4bc8c939e7a64a9e7a886ebaffd

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