Declarative HID protocol framework for Linux
Project description
hidproto
Declarative HID protocol framework for Linux. Define device protocols as pure data, the framework handles transport, discovery, effects, caching, and state tracking.
Why
Every HID device project (OpenRGB, keyRGB, rivalcfg, openrazer) rewrites the same boilerplate: open hidraw, build reports, send ioctl, manage state. hidproto lets you define a protocol in ~50 lines of pure data and get a working device driver.
Install
pip install hidproto
Or from source:
git clone https://github.com/Chocapikk/hidproto
cd hidproto
pip install -e .
Quick start
from hidproto import HIDDevice, HIDProtocol, command, effect
class MyKeyboard(HIDProtocol):
vendor_id = 0x048D
product_id = 0x8910
report_id = 0xCC
report_size = 6
rows = 6
cols = 20
preset_base = 0x71
custom_base = 0xA1
color_custom = 0xAA
animation_mode = command(0x00, args=1, doc="Animation mode")
set_led = command(0x01, args=4, doc="Per-key color")
brightness_speed = command(0x09, args=4, doc="Brightness + speed")
wave_slot = command(0x15, args=4, doc="Wave slot")
effects = {
"off": effect("off", animation=0x0C, needs_clear=True),
"wave": effect("wave", animation=0x04, slot_cmd="wave_slot",
directions=("up", "down", "left", "right")),
}
Keyboard = HIDDevice.for_protocol(MyKeyboard)
with Keyboard() as kb:
kb.brightness(8)
kb.speed(5)
kb.effect("wave", direction="right", color=(255, 0, 0))
That's it. No boilerplate, no subclassing, no transport code.
Features
Protocol definition - command() descriptor auto-generates report builders from opcode + arg count. No methods to write.
Effect dispatch - effect() declaratively maps names to animation modes, color slots, directional slots. One kb.effect("wave", direction="right") call handles everything.
Device discovery - auto-finds devices via /sys/class/hidraw by VID/PID.
Transport - hidraw ioctl for feature reports, os.write for output reports, select for reads with timeout.
State caching - send_if_changed() skips redundant HID sends. invalidate() forces resync (suspend/resume).
Checksums - xor_checksum(), sum_checksum(), and _with_checksum() for protocols that need them (Razer, Corsair).
Sequence numbers - _next_seq() for transactional protocols (Logitech, Corsair).
Architecture
hidproto/
command.py CommandSpec + @command descriptor
effect.py EffectSpec + declarative effect dispatch
protocol.py HIDProtocol base class (report building, transport)
device.py HIDDevice wrapper (effects, caching, brightness/speed)
transport.py HidrawTransport (ioctl, read, write)
discovery.py sysfs device discovery
checksum.py xor/sum checksum helpers
Examples
See examples/ite8910.py for a complete ITE 8910 keyboard RGB implementation: 9 commands, 11 effects, 8 wave directions, 4 snake diagonals, per-key color. All in ~70 lines of data.
License
MIT
Project details
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 hidproto-0.1.1.tar.gz.
File metadata
- Download URL: hidproto-0.1.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cddebee83896776bb86cfa42afd1ae828d5dae01340194057ce3ea446298bbe7
|
|
| MD5 |
2b0dd18af2a913b193638c8895543afc
|
|
| BLAKE2b-256 |
64f29f25c2fc0c22dc14ae24cbc4160f268489f82bbdadf5b17b4692300fcd52
|
Provenance
The following attestation bundles were made for hidproto-0.1.1.tar.gz:
Publisher:
publish.yml on Chocapikk/hidproto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hidproto-0.1.1.tar.gz -
Subject digest:
cddebee83896776bb86cfa42afd1ae828d5dae01340194057ce3ea446298bbe7 - Sigstore transparency entry: 1195471153
- Sigstore integration time:
-
Permalink:
Chocapikk/hidproto@b633b30fd0faf3b2dffa0e0aa4d066bba5a56022 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Chocapikk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b633b30fd0faf3b2dffa0e0aa4d066bba5a56022 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hidproto-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hidproto-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f4904ca58e474f73035f9bbb10fd21ba81c86e3a1ba142c7ac032fef220ace2
|
|
| MD5 |
f07a9543947f6a9c08bc247eab7dc730
|
|
| BLAKE2b-256 |
f1a8c2f0a0e417c45ce0d041feacf844652721ce7f77baf8fb2d1c60e6ea1f82
|
Provenance
The following attestation bundles were made for hidproto-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Chocapikk/hidproto
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hidproto-0.1.1-py3-none-any.whl -
Subject digest:
8f4904ca58e474f73035f9bbb10fd21ba81c86e3a1ba142c7ac032fef220ace2 - Sigstore transparency entry: 1195471154
- Sigstore integration time:
-
Permalink:
Chocapikk/hidproto@b633b30fd0faf3b2dffa0e0aa4d066bba5a56022 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Chocapikk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b633b30fd0faf3b2dffa0e0aa4d066bba5a56022 -
Trigger Event:
push
-
Statement type: