Python client for the Lance Wire Protocol (LWP) — high-performance, low-latency data streaming
Project description
lnc-client
Python client for the Lance Wire Protocol (LWP) — high-performance, low-latency data streaming.
Lance is an io_uring-based streaming server designed to saturate 100G NICs with minimal latency. This client implements the full LWP binary protocol for Python applications.
Installation
pip install lnc-client
Requirements: Python 3.10+
Quick Start
Producer
import asyncio
from lnc_client import Producer, ProducerConfig
async def main():
producer = await Producer.connect("localhost:1992", ProducerConfig())
# Send with ACK (guaranteed delivery)
batch_id = await producer.send(topic_id=1, data=b'{"price": 6942.25}')
# Send without waiting for ACK (pipelined, higher throughput)
batch_id = await producer.send_async(topic_id=1, data=b'fire and forget')
await producer.close()
asyncio.run(main())
Consumer
import asyncio
from lnc_client import StandaloneConsumer, StandaloneConfig
async def main():
consumer = await StandaloneConsumer.connect(
"localhost:1992",
StandaloneConfig(consumer_name="my-app", topic_id=1),
)
while True:
result = await consumer.poll()
if result is None:
await asyncio.sleep(0.05)
continue
for record in result.records:
print(f"Type={record.record_type}, Data={record.value}")
print(f"Lag: {result.lag} bytes")
asyncio.run(main())
Topic Management
import asyncio
from lnc_client import LanceClient, ClientConfig
async def main():
async with LanceClient(ClientConfig(host="localhost")) as client:
topics = await client.list_topics()
topic = await client.create_topic("my-events")
# Create with retention (7-day, 1GB max)
topic = await client.create_topic_with_retention(
"logs", max_age_secs=7*86400, max_bytes=1024**3
)
await client.set_retention(topic["id"], max_age_secs=86400)
asyncio.run(main())
Configuration
ProducerConfig
| Option | Default | Description |
|---|---|---|
batch_size |
32768 |
Max batch size in bytes |
linger_ms |
5 |
Max wait before sending partial batch |
compression |
False |
Enable LZ4 compression |
max_pending_acks |
64 |
Max unacknowledged batches |
StandaloneConfig
| Option | Default | Description |
|---|---|---|
consumer_name |
"" |
Consumer identifier |
topic_id |
0 |
Topic to consume from |
max_fetch_bytes |
65536 |
Max bytes per fetch |
start_offset |
0 |
Initial byte offset |
poll_interval_ms |
50 |
Polling interval when idle |
ClientConfig
| Option | Default | Description |
|---|---|---|
host |
"localhost" |
Lance server hostname |
port |
1992 |
Lance server port |
TLV Record Types
Records use Type-Length-Value encoding:
| Type | Code | Description |
|---|---|---|
| RawData | 0x01 |
Unstructured binary |
| JSON | 0x02 |
JSON-encoded record |
| MessagePack | 0x03 |
MessagePack-encoded |
| KeyValue | 0x10 |
Key-value pair |
| Timestamped | 0x11 |
Timestamp + data |
| Null | 0xFF |
Tombstone/empty |
Error Handling
from lnc_client import (
LanceError,
ConnectionError,
BackpressureError,
TopicNotFoundError,
InvalidFrameError,
)
try:
await producer.send(topic_id=99, data=b"test")
except TopicNotFoundError:
print("Topic doesn't exist")
except BackpressureError:
print("Server is overloaded, slow down")
except ConnectionError:
print("Connection lost")
Protocol Details
This client implements the Lance Wire Protocol (LWP) v1.0:
- 44-byte fixed header with CRC32C validation
- Hardware-accelerated checksums (SSE4.2 / ARM CRC)
- Backpressure signaling from server
- Keepalive with 30-second timeout
- Batched production with ACK tracking
- Offset-based consumption with seek/rewind
- LZ4 compression (optional, per-batch)
- Reconnection with exponential backoff (100ms base, 30s max, jitter)
Development
git clone https://github.com/nitecon/lnc-client-py.git
cd lnc-client-py
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest -v
39 tests covering protocol parsing, CRC32C validation, TLV encoding/decoding, and frame builders.
License
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 lnc_client-0.1.0.tar.gz.
File metadata
- Download URL: lnc_client-0.1.0.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e2abc1712a7f0766680f45c8cca9e712bd1ab6657ee22d870336736b543ea95
|
|
| MD5 |
defe43fd10b1852574f7999c3426c70c
|
|
| BLAKE2b-256 |
3289f839526fc718702c6206cd3270e340c5fd3c8f58bbc4401e9052f205a5ca
|
Provenance
The following attestation bundles were made for lnc_client-0.1.0.tar.gz:
Publisher:
release.yml on nitecon/lnc-client-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lnc_client-0.1.0.tar.gz -
Subject digest:
3e2abc1712a7f0766680f45c8cca9e712bd1ab6657ee22d870336736b543ea95 - Sigstore transparency entry: 927055038
- Sigstore integration time:
-
Permalink:
nitecon/lnc-client-py@11847b07d4d6ba789f50de31239a0446c2bf83d3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/nitecon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@11847b07d4d6ba789f50de31239a0446c2bf83d3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lnc_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lnc_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.4 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 |
82c7b891bf691749824972c2b0bfa695dec133d4f03edf50c3a3b79fc1aeaecf
|
|
| MD5 |
4fabea449616faeeaf30015af719ea97
|
|
| BLAKE2b-256 |
2e37accc4d8c4f2080cd7616167eaac2c85a7163e63c9054367ee6aa60e2972a
|
Provenance
The following attestation bundles were made for lnc_client-0.1.0-py3-none-any.whl:
Publisher:
release.yml on nitecon/lnc-client-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lnc_client-0.1.0-py3-none-any.whl -
Subject digest:
82c7b891bf691749824972c2b0bfa695dec133d4f03edf50c3a3b79fc1aeaecf - Sigstore transparency entry: 927055039
- Sigstore integration time:
-
Permalink:
nitecon/lnc-client-py@11847b07d4d6ba789f50de31239a0446c2bf83d3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/nitecon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@11847b07d4d6ba789f50de31239a0446c2bf83d3 -
Trigger Event:
push
-
Statement type: