hidbridge (Python)
The Python side of hidbridge -- a Linux toolbox that presents a Bluetooth-LE HID keyboard + relative pointer to any BLE-HID (HOG) host and drives it programmatically: type text, press keys, move/click the pointer, and enter a lock-screen passcode.
Two backends, one report layer:
- dongle -- the host's own BlueZ stack (a USB Bluetooth adapter). A small daemon
(
ble_hid) exports the HID-over-GATT peripheral; the CLI talks to it over a Unix socket. Needsdbus+PyGObject(system python) and usually root. - mcu -- a Raspberry Pi Pico 2 W or an ESP32 running the firmware in
../firmware/, reached over USB serial. The MCU owns its own BLE stack + bond database, so it sidesteps the HID-over-GATT CCCD/Report-Reference subscription quirk that trips BlueZ with some hosts. Needs onlypyserial; no dbus, no daemon, no root. - net -- an Ethernet/WiFi ESP32 running that same firmware, reached over TCP (no USB
cable):
--backend net --host hidbridge-<nick>.local. TLS-PSK encrypted and fails closed -- the provisioned token is the pre-shared key; set it on the board over USB once withhidbridge net-provision. Needs Python 3.13+ (ssl PSK). Stdlib-only (sockets + ssl); no pyserial, dbus, daemon, or root. See../docs/bt-hid-network-backend.md.
Both backends emit the exact same report bytes via hidbridge.reports (the single source of
truth for the HID report descriptor), so behaviour is identical regardless of transport.
Install
As a consumer (released wheels are on PyPI):
pip install "hidbridge[mcu]" # + pyserial for the Pico/ESP32 serial backend
pip install hidbridge # core only: reports + the net (TCP) backend
Source, issues and firmware releases: https://github.com/martinmunk/hidbridge. The release flow
(wheel and firmware version independently; the git tag is the version):
docs/releasing.md.
From source (this checkout):
# from this directory (hidbridge/python)
pip install -e ".[mcu]" # Pico / ESP32 serial backend (pyserial)
pip install -e ".[dongle]" # BlueZ backend (dbus-python + PyGObject; system python)
pip install -e ".[dev]" # + pytest, ruff, build
The dongle backend must run under the system python (/usr/bin/python3) because
dbus + AF_BLUETOOTH sockets are only available there. On Debian/Ubuntu install the system
deps with apt instead of pip:
sudo apt install python3-dbus python3-gi
For a venv that still sees them, create it with --system-site-packages
(uv venv --system-site-packages or python3 -m venv --system-site-packages).
Quick start
# MCU backend (a Pico on /dev/ttyACM0) -- no root, no daemon
hidbridge --backend pico type "hello world"
hidbridge --backend pico move 40 0
hidbridge --backend pico click left
# dongle backend (BlueZ) -- needs the daemon up + root
sudo hidbridge pair-mode # advertise as a keyboard; pair from the host's Bluetooth settings
sudo hidbridge connect mini5 # (re)connect a bonded target
sudo hidbridge type "hello"
sudo hidbridge unlock # types the passcode from ~/.config/bt_hid/idevice.pin (never logged)
# named targets (device -> backend map in ~/.config/bt_hid/targets.json)
hidbridge targets add labpad pico:/dev/ttyACM0 AA:BB:CC:DD:EE:FF
hidbridge --target labpad type "hi"
Run hidbridge --help for the full subcommand list.
Python API
The driving surface is two context managers that mirror the hardware: a HidBridge is the board
channel; bridge.connect(name) advertises a bonded identity, waits until it is ready, and hands
back a HidSession you drive. You pass a location ("/dev/ttyUSB3", a net host, "hci1", or
nothing to autodetect) -- never a board type; the board self-identifies into bridge.info /
bridge.capabilities.
from hidbridge import HidBridge
with HidBridge("/dev/ttyUSB3") as bridge, bridge.connect("laptop3") as s:
s.type("hello world")
s.key("enter")
s.move(40, 0) # relative pointer
s.click("left")
s.scroll(-3)
# leaving the `with` disconnects but keeps the bond -- no idle connections
The session verbs are the whole vocabulary: type(text), key(name, mod=0), move(dx, dy),
click(button="left"), scroll(clicks). Who builds the report bytes is a backend detail -- an MCU
board delegates each verb to the firmware (the target slot's keyboard layout applies board-side); a
dongle builds the bytes host-side. Either way the surface is identical. "Unlock an iPad" is just
typing the passcode: s.type(pin); s.key("enter").
For the single-host case, hidbridge.session(location, device) opens the board, connects the one
device, and yields the session (tearing both down on exit):
from hidbridge import session
with session("/dev/ttyUSB3", "laptop3") as s:
s.type("hi")
Errors are typed under HidbridgeError: NotBonded, ConnectTimeout, Unsupported,
CapacityError, IncompatibleFirmware. Multiple sessions can be open at once on a board that
supports it (the ESP32 holds several identities); otherwise a second connect() raises. The wheel
version is hidbridge.__version__.
The passcode PIN (secret, external)
hidbridge unlock (and the trust-overlay helper) read the device passcode from
~/.config/bt_hid/idevice.pin -- a 0600 file that lives outside this repo and is never
committed or logged. Create it yourself:
mkdir -p ~/.config/bt_hid && umask 077 && printf '%s' 1234 > ~/.config/bt_hid/idevice.pin
The passcode is expanded to HID frames locally; only frames are ever sent, never the string.
Layout
python/
pyproject.toml PEP 621 metadata, console_script `hidbridge`, ruff + pytest config
src/hidbridge/ the package
reports.py PURE HID report layer (stdlib only) -- the report-byte source of truth
controller.py backend-agnostic report driver (type/key/move/click/unlock/timeline)
conn.py HidSession: connect-on-demand context manager, readiness gate
targets.py device -> backend registry + per-bond identity slots
naming.py per-adapter runtime names (multi-daemon isolation) + slot names
adapter.py BlueZ adapter discovery / dongle selection (sysfs + dbus)
ble_hid.py the HID-over-GATT peripheral daemon (dongle backend)
central.py / central_core.py on-host BLE-central HID self-test (dongle/MCU parity)
transport_pico.py / link_pico.py Pico serial transport + link backend
transport_esp32.py / link_esp32.py ESP32 serial transport + link backend
dismiss_trust.py hands-free "Trust This Computer" overlay dismissal
cli.py the `hidbridge` command
_scripts/ reference launcher + systemd unit + pair-mode/service shell helpers
tests/ pytest suite (offline by default; hardware tests skip)
Tests
pytest # offline suite (hardware/live tests skip automatically)
Hardware-gated tests opt in via env vars, e.g. BT_HID_LOOPBACK=1 (on-host BLE loopback,
needs two adapters + root) or BT_HID_CENTRAL=1 (central self-test, needs the built-in adapter
- an MCU).
*_live.pytests need a real bonded host.
Lint
ruff check .
The ruleset is deliberately scoped (see pyproject.toml): it enforces the pyflakes correctness
rules but tolerates this codebase's dense one-liner report/parser style.
Metadata
Release files for hidbridge 1.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hidbridge-1.2.3.tar.gz | 220.2 kB | With provenance | Details for hidbridge-1.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hidbridge-1.2.3-py3-none-any.whl | Python 3 | none | any | Details for hidbridge-1.2.3-py3-none-any.whl |
Total release size: 367.6 kB
Release files / hidbridge-1.2.3.tar.gz
| Download URL | hidbridge-1.2.3.tar.gz |
|---|---|
| Size | 220.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8329fb514378e9039cdd458f85b936f6d93466cd1345a9c21379f990584032a6
|
|
BLAKE2b-256 checksum How to use checksums |
6930f4cd65d56ea722fa1dd3e245b0ee8b9d24ac308bfdd1a34bcf68855c04e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / hidbridge-1.2.3-py3-none-any.whl
| Download URL | hidbridge-1.2.3-py3-none-any.whl |
|---|---|
| Size | 147.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a50c1dcf50ef3190085064d1514db69500efcd127970cb87aef5a7ab0148f0b
|
|
BLAKE2b-256 checksum How to use checksums |
79583406e0a5e2947356e7e0219b28f59f847efa4dcb9825fe0b4af10769da2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for hidbridge 1.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hidbridge-1.2.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.