Beginner-friendly Python package to control keyboard backlight brightness.
It supports:
- Real Linux keyboard backlight devices (auto-discovered from sysfs)
- A mock backend for safe testing without touching laptop hardware
- If you use
--mock, commands run in memory only (safe for learning). - If you do not use
--mock, the package tries real hardware automatically. - You usually do not need
--device-path.
Step 1: Install from PyPI
Step 2 (optional): Install local editable version for development
Step 3 (optional): Install dev dependencies
Step 1: Import
from backlit_kbd import NotificationBlinker, create_controllerStep 2: Create a safe controller (mock fallback)
controller = create_controller(fallback_to_mock=True)Step 3: Turn on brightness to 60%
Step 4: Blink for a notification
controller.blink(count=3, on_ms=120, off_ms=120, level_percent=100.0)Step 5: Use async notification manager
blinker = NotificationBlinker(controller)
blinker.start("chat-message", count=5, on_ms=80, off_ms=120)With mock backend:
With real hardware backend:
With mock backend:
With real hardware backend:
With mock backend:
backlit-kbd --mock percent 75With real hardware backend:
Increase by default step (1):
Increase by custom step:
Decrease by custom step:
Real hardware equivalents:
backlit-kbd inc
backlit-kbd inc 2
backlit-kbd dec 2With mock backend:
backlit-kbd --mock on --percent 40
backlit-kbd --mock offWith real hardware backend:
backlit-kbd on --percent 40
backlit-kbd offWith mock backend:
backlit-kbd --mock blink --count 4 --on-ms 100 --off-ms 100 --level-percent 100With real hardware backend:
backlit-kbd blink --count 4 --on-ms 100 --off-ms 100 --level-percent 100With mock backend:
backlit-kbd --mock notify --name chat --count 5 --on-ms 80 --off-ms 120 --level-percent 100With real hardware backend:
backlit-kbd notify --name chat --count 5 --on-ms 80 --off-ms 120 --level-percent 100Global options:
--mockUse in-memory backend (safe, no hardware writes)--device-path PATHOptional advanced override for a specific sysfs device
Commands:
infoset <value>percent <value>inc [step]dec [step]on [--percent N]offblink [--count N --on-ms N --off-ms N --level-percent N]notify [--name NAME --count N --on-ms N --off-ms N --level-percent N]
Scripts:
examples/blink_notification.pyexamples/brightness_wave.pyexamples/disco_light.py
Run them:
python examples/blink_notification.pypython examples/brightness_wave.pypython examples/disco_light.pyRun tests:
If you are using the project virtual environment:
Permission deniedon Linux real hardware mode:
- You may need proper privileges/udev rules to write to sysfs.
- No device found in real hardware mode:
- Use
--mockfor learning/testing. - Or use
create_controller(fallback_to_mock=True)in Python.
- Want safe practice mode always:
- Use
--mockin CLI, orforce_mock=True/fallback_to_mock=Truein code.
This repo has GitHub Actions workflows:
CIruns tests on push and pull requestPublishbuilds and publishes to PyPI- Uses
astral-sh/setup-uv - Uses PyPI Trusted Publishing (OIDC)
To publish a new version:
- Update version in
pyproject.toml - Create and push a tag like
v0.1.1 - Or publish a GitHub release
- Start with
examples/ - Check tests in
tests/ - Open issues and PRs
MIT License. Created by Adarsh Gourab Mahalik.