lunalink (Python node)
A LunaLink node for Python 3.9+: it connects to a LunaLink master, publishes tag values with durable, ordered, duplicate-free delivery, answers remote writes idempotently and speaks revision 2.0 of the LunaLink protocol. It is meant for Raspberry Pi gateways, quick integrations and protocol test tooling.
pip install lunalink
Dependencies: msgpack, lz4. Everything else is the standard library (asyncio, ssl, sqlite3).
Quick start
import asyncio, uuid
from lunalink import LunaLinkNode, DataType
TEMP = uuid.UUID("00112233-4455-6677-8899-aabbccddeeff")
async def main():
node = LunaLinkNode("master.example", 7788, node_id="pi-1", db_path="lunalink.db",
auth_token="secret")
await node.start() # connects in the background, reconnects forever
node.publish(TEMP, 21.5, DataType.FLOAT32, tag_name="Temperature") # durable when it returns
await node.wait_delivered(30) # until the master acknowledged everything
await node.close() # Goodbye (if negotiated), then close
asyncio.run(main())
A complete example is in examples/node_example.py.
API
| Item | Purpose |
|---|---|
LunaLinkNode(host, port, node_id=, db_path=, ...) |
The node. endpoints=[(host, port), ...] enables master failover order. |
await node.start() / await node.close() |
Start the connection task / send Goodbye and stop. |
node.publish(tag_id, value, data_type=None, ...) |
Persist one value as a batch. Returns its NodeSequence. Thread safe. |
node.publish_batch([TagValue, ...]) |
Several values, one NodeSequence. |
node.publish_event(message, severity=, ...) |
Event delivered through the outbox (needs events-v1). |
await node.wait_delivered(timeout) |
Wait until the outbox is empty. |
on_write= |
Callback (WriteRequest) -> bool. Called at most once per CommandId. Raise WriteOutcomeUnknown when the result cannot be determined. |
on_remote_values=, on_event_ack=, on_error= |
Master to node values (TagDelta, SnapshotResp), EventAck, Error. |
browse_tags= |
Callable returning TagInventory items; answers BrowseReq. |
Features(...) |
What to offer in Hello (compression, max-payload, window, goodbye, events-v1, ...). |
TlsConfig(ca_file=, cert_file=, key_file=) |
TLS 1.3, optional client certificate (mutual TLS). verify=False is for testing only. |
Value types: pass a DataType (0 to 13) or let it be inferred (bool, int, float, str, bytes,
lists). GUIDs are uuid.UUID, their text form, or the 16 wire bytes; they are converted to .NET byte order.
Delivery
State lives in one SQLite file (synchronous=FULL): the outbox, the persistent NodeSequence, the last value
of every tag, queued events and the result of every write command. A batch is deleted only after
TagDeltaAck with Accepted = true. With window=<n> granted by the master, up to n batches are in
flight with go-back-N on rejection. If the master expects a sequence the outbox no longer holds (or the
backlog reaches 1024 batches) the node sends a resync baseline that also carries the events of the batches
it replaces. Without a granted window it uses stop-and-wait.
Tests
pip install -e ".[test]"
pytest # unit tests, scripted-master tests, interop (if dotnet is present)
dotnet build interop/Harness -c Release -o interop/Harness/bin # once, for the interop tests
tests/test_vectors.py: Appendix A vectors byte for byte (CRC, GUID, Float32, Ping frame, Hello, TagDelta, Ack, TagWriteAck, compression containers) plus codec edge cases.tests/test_node.py: the node against an in-process scripted master (tests/fake_master.py).tests/test_interop.py: the node against a real .NET master.interop/Harnessis a small console program that references the NuGet packageLunaLink1.2.0, runsLunaLinkServerand prints every received data point. The tests check that values arrive in order without loss across forced reconnects and a master restart.
What is only unit-tested until the 2.0 master is released
The released master (1.2.0) negotiates only no-compression and max-payload. It ignores every other
token, so these 2.0 features are covered by tests against the scripted master only, not against the
.NET reference:
lz4-block compression in both directions, window=<n> and go-back-N, goodbye, events-v1
(EventItem, EventAck), browse-v1, arrays-v1 (types 10 to 13), master-delta, no-crc, the
Error code names beyond what 1.2.0 sends, the SupportedVersions field, leased-by-other-master
failover. K4os LZ4Pickler decompression is unit-tested with containers built to the spec (Appendix A.8
layout), not yet against compressed frames from a real master. The 1.x behaviours (stop-and-wait,
TagDeltaAck, heartbeat, scalar types 0 to 9, reconnect, master restart) are tested against the real
1.2.0 master. Writes (TagWriteCmd) are tested against the scripted master only, because the 1.2.0 server
has no public API to send them from the harness.
TLS 1.3 with a client certificate is implemented with the standard ssl module but has no automated test yet.
License
MIT, see LICENSE.
Metadata
Release files for lunalink 0.1.0
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 |
|---|---|---|---|---|
| lunalink-0.1.0.tar.gz | 34.5 kB | With provenance | Details for lunalink-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lunalink-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for lunalink-0.1.0-py3-none-any.whl |
Total release size: 60.6 kB
Release files / lunalink-0.1.0.tar.gz
| Download URL | lunalink-0.1.0.tar.gz |
|---|---|
| Size | 34.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71f65b09157a79eeb87cc45a293d20dd499a97e3b8839f6f640b12f5883aabde
|
|
BLAKE2b-256 checksum How to use checksums |
f744210d01ccfbb437ebc5b3c5cfc37d54f68637bddaeecd9f1d1c1e15ae61c1
|
| 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 Dec 3, 2026.
Transparency logRelease files / lunalink-0.1.0-py3-none-any.whl
| Download URL | lunalink-0.1.0-py3-none-any.whl |
|---|---|
| Size | 26.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe1e772dbd80c32c4fb0cf2a4f9b47a54002d9b203654f40d2d0644c23560886
|
|
BLAKE2b-256 checksum How to use checksums |
1786be6a4d590bac072a41f0bcd05d56cea6dd2ca65b274d043785374f147c17
|
| 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 Dec 3, 2026.
Transparency logSecurity for lunalink 0.1.0
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 lunalink-0.1.0.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 Dec 3, 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.