Secure device pairing and messaging for your local network, in a few lines of Python. Scan a QR code once; after that, every message is encrypted, signed and checked for replays before your code sees it.
pip install "lanpair[all]"
A host (a front desk, a hub) and a device (a room PC, a Raspberry Pi). Each pairs on its first run and remembers the other across restarts and address changes.
from lanpair import Host with Host("Front desk") as host: if not host.devices: # first run host.pairing_offer().print_qr() host.wait_for_pairing(timeout=300) for msg in host.messages(): print(msg.sender.name, msg.body) host.send(msg.sender.device_id, {"type": "ok"})
from lanpair import Device with Device("Room 3") as dev: if dev.host is None: # first run dev.pair(input("Scanned code: ")) dev.send({"type": "checkout"}) for msg in dev.messages(): print(msg.body)
Need your own transport? The building blocks underneath, Sealer and
Opener, turn any bytes into safe envelopes.
See the recipe →
The parts you would otherwise spend a week getting right, against an attacker on the same network who can read, inject, replay and drop traffic.
The code carries the host's keys and a one-time secret. One device per code, five minutes, five tries. Nobody on the network can join or pose as the host.
X25519 and ChaCha20-Poly1305 with a fresh key per message. Others on the network see who talks to whom, not what they say.
Ed25519 signatures over every message, bound to one recipient. Forged, changed or redirected messages never reach your code.
Increasing sequence numbers and timestamps, kept on disk. A recorded message stays useless tomorrow, and after either side restarts.
mDNS discovery and a signed hello on start, so changing IP addresses and restarts don't break anything. Discovery is never trusted on its own.
macOS Keychain, Windows Credential Manager or the Secret Service on Linux. Messages up to 1 MiB, over UDP or TCP, chosen for you.
A security library should be tested like one. Every change and every release goes through:
Know what lanpair does not do yet:
Host / Device 1.3+.Found a problem? Report it privately; see the security policy.