Pair once.
Then every message is safe.

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]"
Demo: the host prints a QR code, the device pairs with it, and they exchange messages; after a restart they talk again without pairing

That is the whole setup

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.

host.py
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"})
device.py
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 →

What you get

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.

Pairing by QR code

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.

Encrypted to the recipient

X25519 and ChaCha20-Poly1305 with a fresh key per message. Others on the network see who talks to whom, not what they say.

Signed and bound

Ed25519 signatures over every message, bound to one recipient. Forged, changed or redirected messages never reach your code.

Replay-proof, even after restarts

Increasing sequence numbers and timestamps, kept on disk. A recorded message stays useless tomorrow, and after either side restarts.

Finds devices by itself

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.

Keys in the OS key store

macOS Keychain, Windows Credential Manager or the Secret Service on Linux. Messages up to 1 MiB, over UDP or TCP, chosen for you.

Built to be attacked

A security library should be tested like one. Every change and every release goes through:

  • A simulated LAN with an attacker before each release: four separate environments, a sniffing node that replays, tampers, redirects and forges.
  • Fuzzing of the code that reads untrusted input (Atheris, on every change), and property-based tests (Hypothesis).
  • Tests on Linux, macOS and Windows, Python 3.10 to 3.15, with strict type checking.
  • Code scanning with CodeQL, and the release pipeline checked by zizmor and OpenSSF Scorecard.
  • Trusted publishing to PyPI with attestations: no tokens, every upload approved by the maintainer.

Honest limits

Know what lanpair does not do yet:

  • No external security review so far.
  • Forward secrecy covers all but the last ~20 minutes, and only with Host / Device 1.3+.
  • Message sizes and who talks to whom stay visible.

Found a problem? Report it privately; see the security policy.

Documentation

Everything lives in the wiki.