Skip to main content

GitHub tag (latest by date) PyPI PyPI - Downloads Ruff mypy coverage pyversions License

Cross-platform wakelock / keep-awake / stay-awake written in Python.

What is wakepy?

Wakepy is a package with an Python API and a CLI tool for keeping a system awake. It has two main modes:

⌛ Keeping CPU awake: For long running tasks. Inhibit the automatic, timer based sleep or suspend action, but allow screenlock and screensaver turning on and monitor turning off. E.g. for training machine learning models, video encoding and web scraping. (See: keep.running)

🖥️ Keeping screen awake: For long running tasks which require also the screen on and screenlock and screensaver inhibited. E.g. for showing a video and dashboard / monitoring apps. (See: keep.presenting)

Supported runtime environments

Wakepy may keep the following systems awake. ⌛: keep.running mode, 🖥️:keep.presenting mode.

Runtime environment Methods Modes
Windows[1] SetThreadExecutionState ⌛ 🖥️
macOS[2] caffeinate ⌛ 🖥️
Unix + GNOME[3] org.gnome.SessionManager
org.freedesktop.ScreenSaver
⌛ 🖥️
Unix + KDE Plasma[4] org.freedesktop.PowerManagement
org.freedesktop.ScreenSaver
⌛ 🖥️
Unix + Freedesktop.org DE[5] org.freedesktop.PowerManagement
org.freedesktop.ScreenSaver
⌛ 🖥️

Unix above refers to any Unix-like systems which might use such DEs, e.g. Linux or FreeBSD. See also: Wakepy roadmap.

Installing

Wakepy supports CPython 3.7 to 3.15 (including the free-threaded versions) and PyPy 3.8 to 3.11, and may be installed from PyPI with

pip install wakepy

Wakepy can also be installed from conda-forge with

conda install wakepy

For more details and install options, see: Installing documentation.

[!NOTE] To get the wakepy CLI command working, you might need to restart the shell / terminal application.

Why wakepy?

Here's some reasons why you might want to consider using wakepy:

🙅🏼‍♂️ Non-disruptive methods ✅
No mouse wiggling or pressing random keys like F15. Wakepy is completely non-disruptive. It uses the APIs and programs the system provides for keeping a system awake.
🛡️ Safe to crash 💥
No changing of any system settings; killing the process abruptly will not leave the keepawake on, and will not require any manual clean-up.
🚨 For security reasons 🔒
With keep.running mode you can disable just the automatic suspend and keep the automatic screen lock untouched.
🌐 You need a cross-platform solution 🦸
Same code works on Windows, macOS and Linux on multiple different Desktop Environments.
💪 You want to have more control ⚙️
It is possible to whitelist or blacklist the used wakepy Methods. It is also possible to prioritize them and define a on-fail action in case activating a wakepy mode fails.
✂️ You want to keep the amount of dependencies low 📦
If you're running wakepy on Linux, jeepney (a dependency free package) is required for D-Bus based methods. On Python 3.9 and earlier, typing-extensions is needed for typing. Otherwise: wakepy has no python dependencies.
⚖️ Package needs to have a permissive licence ✔️
Wakepy is licenced under permissive MIT License.

Command line interface (CLI)

To keep system from sleeping and prevent screen lock, run

wakepy

For keep.running mode (allows screen lock), add -r flag. See also: CLI API.

Basic usage within Python

In the simplest case, keeping a system running long running task with wakepy would be in python (See: keep.running):

from wakepy import keep

@keep.running
def long_running_task():
    # Do something that takes a long time

If you want to also prevent screen lock and screen blank, use the keep.presenting mode:

from wakepy import keep

@keep.presenting
def long_running_task():
    # Do something that takes a long time AND requires the display to stay on

[!NOTE] The decorator syntax was added in wakepy version 1.0.0

It's also possible to use the keep.running() and keep.presenting() as context managers, like this:

from wakepy import keep

with keep.running()
    ...

[!TIP] See the User Guide and the available wakepy Modes and Methods

Where wakepy is used?

AI & Machine Learning

  • aTrain — transcription of speech recordings utilizing machine learning models.
  • UCSD-E4E/baboon-tracking — In pipelines of a Computer Vision project tracking baboons
  • pysimai — A Python wrapper for Ansys SimAI

Media Processing & Conversion

Hardware Control, Automation & Instrumentation

Data Preservation, Archival & Extraction

Misc

  • mpc-autofill — Automating MakePlayingCards' online ordering system
  • LiveboxMonitor — Graphical user interface for routers (French project)
  • FOLON-FO4Downgrader — Tool for reverting to a previous version of a game (Fallout 4)

Links

Wakepy roadmap

Wakepy vision is to support any† environment which runs Python. The following runtime environments will get support in the future†. Please vote or comment on the issue to raise them towards top of priorities. I'm also happy to receive PRs or comments explaining how it could be implemented.

†: if technically possible.

Runtime environment Issue
WSL wakepy/#36
cygwin wakepy/#363
Unix + Cinnamon wakepy/#312
Unix + Xfce wakepy/#311
Unix + Mate wakepy/#314
Unix + LXQt wakepy/#313
Unix + systemd wakepy/#335
ChromeOS wakepy/#364
Android wakepy/#358
Jupyter Notebook (hosted on eg. Google Colab) wakepy/#195
Browser (Pyodide, PyPy.js, Brython, Transcrypt, Skulpt) wakepy/#362

If you have ideas or comments, please post yours on wakepy/#317.

Licenses

The contents of this repository are licensed with MIT License, which is permissive and allows you to use the code as part of any application or library, commercial or not, with the following exception: The GitHub Invertocat logo used in the social share image is property of GitHub, downloaded from github.com/logos and is used under the terms specified by GitHub.


Footnotes

[1] Windows XP or higher. Windows Server 2003 or higher.
[2] Mac OS X 10.8 Mountain Lion (July 2012) or newer.
[3] GNOME 2.24 (Sept 2008) onwards.
[4] KDE Plasma 5.12.90 (May 2018) onwards.
[5] Freedesktop.org compliant Desktop Environments on Unix-like (Linux/BSD) system which implements the listed D-Bus interfaces.

Metadata

Release files for wakepy 1.0.0

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

Source distribution (sdist)

Source distribution for wakepy 1.0.0
File Size Uploaded
wakepy-1.0.0.tar.gz 323.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wakepy 1.0.0
File Interpreter ABI Platform
wakepy-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 394.0 kB

Release files / wakepy-1.0.0.tar.gz

Download URL wakepy-1.0.0.tar.gz
Size 323.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a9425e8e77e89bccfe24a70f33ecd8596b474c75ddac79310cd54f2bc92210e3
BLAKE2b-256 checksum
How to use checksums
d61378e45a3d2cd754f95d2fca5aece046676da559b8e34e294e69bb441f18fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 7, 2026.

Transparency log

Release files / wakepy-1.0.0-py3-none-any.whl

Download URL wakepy-1.0.0-py3-none-any.whl
Size 70.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5497640791517982cf66d894c502e9fa5133dc75c4a45d3b18a3495d1cf8afb
BLAKE2b-256 checksum
How to use checksums
5233e692c64d00b7a0d203191b1a20c81c32dca93da38345f6f1ad91426e36fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

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