About
Define rules to control your computer's power state based on configurable conditions.
Rules are evaluated from top to bottom. The first matching rule executes its configured action.
Getting Started
Install with pip:
pip install powerrules
Create a policy file:
# yaml-language-server: $schema=https://raw.githubusercontent.com/LeoTN/PowerRules/main/assets/schema/powerrules_policy.schema.json
rules:
# Shut down when no backup process is running, a matching backup window is open, and the current time is between 23:00 and 01:30
- name: "Shutdown after nightly backup"
conditions:
and:
- process:
name: "backup.exe"
exists: false
- window:
title: "Backup Nr. [0-9]+ Completed"
exists: true
match:
type: regex
- datetime:
between:
start: "23"
end: "1:30"
action:
type: shutdown
Validate the policy:
pwru policy validate
Show configured rules:
pwru policy show
Evaluate the policy once:
pwru policy run --once
Use a different policy file with --policy or -p:
pwru policy run --policy my-policy.yaml
Features
Process & Window Matching
Match rules based on processes and window titles.
# Match if process "firefox.exe" is running
- process:
name: "firefox.exe"
exists: true
# Match if window with exact title "Firefox" exists
- window:
title: "Firefox"
exists: true
Regex Matching
Match process names and window titles using regular expressions with full-string matching.
# Match if process name ends with "firefox"
- process:
name: ".*firefox.exe"
match:
type: regex
# This is the default behavior
case_sensitive: true
# Match if window title starts with "firefox" (case insensitive)
- window:
title: "Firefox.*"
match:
type: regex
case_sensitive: false
Time-based Conditions
Match specific time ranges and weekdays.
# Match if the current time is between 23:00 and 1:30
- datetime:
between:
start: "23"
end: "1:30"
# Match on Monday or Friday
- datetime:
weekdays:
- "Monday"
- "Friday"
Logical Conditions
Combine multiple conditions using and, or, and not.
# Match if (condition_1 OR condition_2) AND NOT condition_3
- and:
- or:
- condition_1: ...
- condition_2: ...
- not:
condition_3: ...
Power Actions
Shutdown, sleep, hibernate, or reboot your computer.
# Shutdown on match
- action:
type: shutdown
# Reboot on match
- action:
type: reboot
Continuous Evaluation
Evaluate rules at a set interval.
pwru policy run
Supported Platforms
| Platform | Status |
|---|---|
| Windows 10/11 | ✅ |
| Linux | ✅ |
| macOS* | ✅ |
* Hibernation is not supported on macOS.
Credits & License
- Pydantic → configuration validation
- PyYAML → YAML policy parsing
- Typer → command-line interface
- psutil → process information
- PyWinCtl → window information
- Inkscape → program used to design the logo
This repository is licensed under the MIT License.
Release files for powerrules 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| powerrules-0.2.0.tar.gz | 14.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| powerrules-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.6 kB
Release files / powerrules-0.2.0.tar.gz
| Download URL | powerrules-0.2.0.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b26d78d00c27341709dc1e48a3bc9b7cd7b9448eab00ef346bea225f4012ab86
|
|
BLAKE2b-256 checksum How to use checksums |
e673b495416e2d0fef35eff475c6755116d9e933217dfe5cf2e4ae65d0eea276
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1022-azure
|
Release files / powerrules-0.2.0-py3-none-any.whl
| Download URL | powerrules-0.2.0-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44cae89b129d9a1260c524825e94b8d0db5afedacb7809ef3ad98d2e5bcfbeab
|
|
BLAKE2b-256 checksum How to use checksums |
56650136b18df9ed92ee4f02ec4ed51fc78964b4cdc4ce278dfd0f67133dda64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1022-azure
|