Python API for controlling keyboard backlight devices with notification blinking
Project description
backlit-kbd
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
What This Means
- 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.
Installation
Step 1: Install from PyPI
pip install backlit-kbd
Step 2 (optional): Install local editable version for development
pip install -e .
Step 3 (optional): Install dev dependencies
pip install -e .[dev]
Quick Start (Python)
Step 1: Import
from backlit_kbd import NotificationBlinker, create_controller
Step 2: Create a safe controller (mock fallback)
controller = create_controller(fallback_to_mock=True)
Step 3: Turn on brightness to 60%
controller.turn_on(60.0)
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)
CLI Guide (Beginner Friendly)
1) Check Current State
With mock backend:
backlit-kbd --mock info
With real hardware backend:
backlit-kbd info
2) Set Brightness by Raw Level
With mock backend:
backlit-kbd --mock set 2
With real hardware backend:
backlit-kbd set 2
3) Set Brightness by Percentage
With mock backend:
backlit-kbd --mock percent 75
With real hardware backend:
backlit-kbd percent 75
4) Increase and Decrease
Increase by default step (1):
backlit-kbd --mock inc
Increase by custom step:
backlit-kbd --mock inc 2
Decrease by custom step:
backlit-kbd --mock dec 2
Real hardware equivalents:
backlit-kbd inc
backlit-kbd inc 2
backlit-kbd dec 2
5) Turn On and Off
With mock backend:
backlit-kbd --mock on --percent 40
backlit-kbd --mock off
With real hardware backend:
backlit-kbd on --percent 40
backlit-kbd off
6) Blink Pattern (Synchronous)
With mock backend:
backlit-kbd --mock blink --count 4 --on-ms 100 --off-ms 100 --level-percent 100
With real hardware backend:
backlit-kbd blink --count 4 --on-ms 100 --off-ms 100 --level-percent 100
7) Notification Blink (Async-style Command)
With mock backend:
backlit-kbd --mock notify --name chat --count 5 --on-ms 80 --off-ms 120 --level-percent 100
With real hardware backend:
backlit-kbd notify --name chat --count 5 --on-ms 80 --off-ms 120 --level-percent 100
Full CLI Commands
Global 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]
Examples Folder
Scripts:
examples/blink_notification.pyexamples/brightness_wave.pyexamples/disco_light.py
Run them:
python examples/blink_notification.py
python examples/brightness_wave.py
python examples/disco_light.py
Testing
Run tests:
python -m pytest
If you are using the project virtual environment:
.venv/bin/pytest
Troubleshooting
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.
Release and Publish
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
Support
- Buy Me a Coffee: https://buymeacoffee.com/itsmeadarsh
- GitHub Sponsors (individual/company): https://github.com/sponsors/itsmeadarsh2008
Contributing
- Start with
examples/ - Check tests in
tests/ - Open issues and PRs
License
MIT License. Created by Adarsh Gourab Mahalik.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file backlit_kbd-0.1.0.tar.gz.
File metadata
- Download URL: backlit_kbd-0.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb387920c0fbea8ae951c075bc52a323422f96730e9d86909e53d28c0fcb38cf
|
|
| MD5 |
3f346d98478264644963091eface2a41
|
|
| BLAKE2b-256 |
eefad3fbdc565704700afa5485b64714a6340215f33b775736f91fdf28db24e5
|
Provenance
The following attestation bundles were made for backlit_kbd-0.1.0.tar.gz:
Publisher:
publish.yml on itsmeadarsh2008/backlit-kbd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backlit_kbd-0.1.0.tar.gz -
Subject digest:
fb387920c0fbea8ae951c075bc52a323422f96730e9d86909e53d28c0fcb38cf - Sigstore transparency entry: 1340275841
- Sigstore integration time:
-
Permalink:
itsmeadarsh2008/backlit-kbd@95b931d2c7b3c49eb7088024b4c2cc743cd07bd9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/itsmeadarsh2008
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95b931d2c7b3c49eb7088024b4c2cc743cd07bd9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file backlit_kbd-0.1.0-py3-none-any.whl.
File metadata
- Download URL: backlit_kbd-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
710052446abc155ac74e0fbb7e7d43d4850b306f4b8fe04a68d5c7b2f795f5d6
|
|
| MD5 |
a9ccb08c595008b511cf9d1dfc87b54e
|
|
| BLAKE2b-256 |
9e39d96ec72798a1474667f6669d04281bd7eca0ae376d79cd2cc5adc3ffd99d
|
Provenance
The following attestation bundles were made for backlit_kbd-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on itsmeadarsh2008/backlit-kbd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backlit_kbd-0.1.0-py3-none-any.whl -
Subject digest:
710052446abc155ac74e0fbb7e7d43d4850b306f4b8fe04a68d5c7b2f795f5d6 - Sigstore transparency entry: 1340275847
- Sigstore integration time:
-
Permalink:
itsmeadarsh2008/backlit-kbd@95b931d2c7b3c49eb7088024b4c2cc743cd07bd9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/itsmeadarsh2008
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95b931d2c7b3c49eb7088024b4c2cc743cd07bd9 -
Trigger Event:
push
-
Statement type: