Skip to main content

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 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 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.3.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 powerrules 0.3.0
File Size Uploaded
powerrules-0.3.0.tar.gz 19.1 kB Details

Built distribution (wheel)

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

Total release size: 45.7 kB

Release files / powerrules-0.3.0.tar.gz

Download URL powerrules-0.3.0.tar.gz
Size 19.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e5a259ecfa52ec23a2b2b7f68c21cba8d471c0f1c8e31555491e037eb083447a
BLAKE2b-256 checksum
How to use checksums
abb2d125127165af0c32f15d4b37d1ee9a5522d34f24c8f66a2f060df2079c77
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.3.0-py3-none-any.whl

Download URL powerrules-0.3.0-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c14fc08930d54e9ef10f51a44f46a079e1efb4a97d90ef514432a533a38ed6b
BLAKE2b-256 checksum
How to use checksums
9aab2ba08e4ada4dd7f265b38ebc19fe7f5072140e9e41f48ff61c35a6669727
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
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