Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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

1. Install via pip (Python 3.11+) or download a standalone binary:

pip install powerrules

2. 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 and the current time is between 23:00 and 01:30
  - name: "Shutdown after nightly backup"
    enabled: true
    conditions:
      and:
        - process:
            name: "backup.exe"
            exists: false
        - datetime:
            between:
              start: "23"
              end: "1:30"
    action:
      type: shutdown

3. Validate and evaluate the policy once. Use --dry-run to see what would happen:

pwru policy validate --policy my-policy.yaml
pwru policy run --once --policy my-policy.yaml --dry-run

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 contains "fire"
- process:
    name: '.*fire.*'
    exists: true
    match:
      type: regex
      case_sensitive: true # This is the default behavior

# Match if window title starts with "firefox" (case insensitive)
- window:
    title: "Firefox.*"
    exists: true
    match:
      type: regex
      case_sensitive: false

Time-based Conditions

Match specific dates, time ranges, weekdays and months. If several of between, weekday and month are configured, all of them must match. The end of a range is always exclusive.

# Match every day from 23:00 until 1:30 the next morning
- datetime:
    between:
      start: "23"
      end: "1:30"

# Match on Mondays and Fridays
- datetime:
    weekday:
      - "Monday"
      - "Friday"

# Match in June, July and August
- datetime:
    month:
      - "June"
      - "July"
      - "August"

# Match on the whole days 2026-08-21 and 2026-08-22 (the end date 2026-08-23 is not included)
- datetime:
    between:
      start: "2026-08-21"
      end: "2026-08-23"

# Match from 2026-08-21 18:00 until 2026-08-23 6:00
- datetime:
    between:
      start: "2026-08-21 18:00"
      end: "2026-08-23 6:00"

# Match on Saturdays and Sundays from 2026-08-21 until the end of 2026
- datetime:
    between:
      start: "2026-08-21"
      end: "2027-01-01"
    weekday:
      - "Saturday"
      - "Sunday"

# Match on Saturday and Sunday nights in December from 22:00 until 6:00 the next morning
- datetime:
    between:
      start: "22"
      end: "6"
    weekday:
      - "Saturday"
      - "Sunday"
    month:
      - "December"

start and end must be of the same kind: both times, both dates or both dates with a time. All values use the local time of the computer, timezones are not supported.

If a time range crosses midnight, weekday and month refer to the day on which the range starts. For dates, they refer to the current day.

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 every 10 seconds. A matching rule is triggered only when it becomes the active match, avoiding repeated execution while the same rule remains matched.

pwru policy run

--stop-on-match can be used to stop the evaluation after the first match. The policy is loaded once at startup, so changes to the file require a restart.

Supported Platforms

Platform Standalone Binary Notes
Windows 10/11 powerrules-windows-x86_64.exe Window conditions only work when PowerRules runs in the logged-in user's session.
Linux powerrules-linux-x86_64 Window conditions require an X11 session (Wayland is not supported).
macOS powerrules-macos-arm64 Hibernation action is not supported.

Platform independent via pip:

pip install powerrules

Credits & License

  • Inkscape → program used to design the logo
  • Nuitka → standalone binaries
  • psutil → process information
  • Pydantic → configuration validation
  • PyYAML → YAML policy parsing
  • rich → console output formatting
  • Typer → command-line interface

This repository is licensed under the MIT License.

Metadata

Release files for powerrules 0.5.0b3

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

Source distribution (sdist)

Source distribution for powerrules 0.5.0b3
File Size Uploaded
powerrules-0.5.0b3.tar.gz 29.8 kB Details

Built distribution (wheel)

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

Total release size: 69.4 kB

Release files / powerrules-0.5.0b3.tar.gz

Download URL powerrules-0.5.0b3.tar.gz
Size 29.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ba20fd3a929a5717527d7b8d4109535b17977f32e73ffc05164a0938f2b76be3
BLAKE2b-256 checksum
How to use checksums
8cc912854ad37c0c4ea33b9da6db9e58d998f005289f1602ace3a956deaf8b66
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.5.0b3-py3-none-any.whl

Download URL powerrules-0.5.0b3-py3-none-any.whl
Size 39.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e21c4eda45630e7da4bf1dc3924068e83862bcd43784d99cffaa7c2f21493884
BLAKE2b-256 checksum
How to use checksums
d873f4ebac9c98bd20ca4707b1a6514b8ee0caf80f9bf2d3d251ef8cb9399007
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 history Release notifications | RSS feed

0.5.0

2 release files

This release

0.5.0b3 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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