lnc-client 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lnc_client-0.1.0/.gitignore +207 -0
- lnc_client-0.1.0/LICENSE +21 -0
- lnc_client-0.1.0/PKG-INFO +230 -0
- lnc_client-0.1.0/README.md +179 -0
- lnc_client-0.1.0/pyproject.toml +65 -0
- lnc_client-0.1.0/src/lnc_client/__init__.py +95 -0
- lnc_client-0.1.0/src/lnc_client/client.py +167 -0
- lnc_client-0.1.0/src/lnc_client/config.py +93 -0
- lnc_client-0.1.0/src/lnc_client/connection.py +248 -0
- lnc_client-0.1.0/src/lnc_client/consumer.py +248 -0
- lnc_client-0.1.0/src/lnc_client/errors.py +93 -0
- lnc_client-0.1.0/src/lnc_client/producer.py +229 -0
- lnc_client-0.1.0/src/lnc_client/protocol.py +346 -0
- lnc_client-0.1.0/src/lnc_client/py.typed +0 -0
- lnc_client-0.1.0/src/lnc_client/tlv.py +138 -0
- lnc_client-0.1.0/tests/__init__.py +0 -0
- lnc_client-0.1.0/tests/test_protocol.py +254 -0
- lnc_client-0.1.0/tests/test_tlv.py +138 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
lnc_client-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nitecon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lnc-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for the Lance Wire Protocol (LWP) — high-performance, low-latency data streaming
|
|
5
|
+
Project-URL: Homepage, https://github.com/nitecon/lnc-client-py
|
|
6
|
+
Project-URL: Documentation, https://github.com/nitecon/lnc-client-py#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/nitecon/lnc-client-py/issues
|
|
8
|
+
Author-email: Will Hattingh <nitecon@gmail.com>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Nitecon
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: data-ingestion,high-performance,lance,lwp,streaming
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
40
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
41
|
+
Classifier: Topic :: System :: Networking
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Requires-Dist: crc32c>=2.7
|
|
44
|
+
Requires-Dist: lz4>=4.3
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest-timeout>=2.3; extra == 'dev'
|
|
48
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
49
|
+
Requires-Dist: ruff>=0.9; extra == 'dev'
|
|
50
|
+
Description-Content-Type: text/markdown
|
|
51
|
+
|
|
52
|
+
# lnc-client
|
|
53
|
+
|
|
54
|
+
[](https://pypi.org/project/lnc-client/)
|
|
55
|
+
[](https://pypi.org/project/lnc-client/)
|
|
56
|
+
[](https://opensource.org/licenses/MIT)
|
|
57
|
+
|
|
58
|
+
Python client for the **Lance Wire Protocol (LWP)** — high-performance, low-latency data streaming.
|
|
59
|
+
|
|
60
|
+
[Lance](https://github.com/nitecon/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.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install lnc-client
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Requirements:** Python 3.10+
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
### Producer
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import asyncio
|
|
76
|
+
from lnc_client import Producer, ProducerConfig
|
|
77
|
+
|
|
78
|
+
async def main():
|
|
79
|
+
producer = await Producer.connect("localhost:1992", ProducerConfig())
|
|
80
|
+
|
|
81
|
+
# Send with ACK (guaranteed delivery)
|
|
82
|
+
batch_id = await producer.send(topic_id=1, data=b'{"price": 6942.25}')
|
|
83
|
+
|
|
84
|
+
# Send without waiting for ACK (pipelined, higher throughput)
|
|
85
|
+
batch_id = await producer.send_async(topic_id=1, data=b'fire and forget')
|
|
86
|
+
|
|
87
|
+
await producer.close()
|
|
88
|
+
|
|
89
|
+
asyncio.run(main())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Consumer
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import asyncio
|
|
96
|
+
from lnc_client import StandaloneConsumer, StandaloneConfig
|
|
97
|
+
|
|
98
|
+
async def main():
|
|
99
|
+
consumer = await StandaloneConsumer.connect(
|
|
100
|
+
"localhost:1992",
|
|
101
|
+
StandaloneConfig(consumer_name="my-app", topic_id=1),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
while True:
|
|
105
|
+
result = await consumer.poll()
|
|
106
|
+
if result is None:
|
|
107
|
+
await asyncio.sleep(0.05)
|
|
108
|
+
continue
|
|
109
|
+
|
|
110
|
+
for record in result.records:
|
|
111
|
+
print(f"Type={record.record_type}, Data={record.value}")
|
|
112
|
+
|
|
113
|
+
print(f"Lag: {result.lag} bytes")
|
|
114
|
+
|
|
115
|
+
asyncio.run(main())
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Topic Management
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import asyncio
|
|
122
|
+
from lnc_client import LanceClient, ClientConfig
|
|
123
|
+
|
|
124
|
+
async def main():
|
|
125
|
+
async with LanceClient(ClientConfig(host="localhost")) as client:
|
|
126
|
+
topics = await client.list_topics()
|
|
127
|
+
|
|
128
|
+
topic = await client.create_topic("my-events")
|
|
129
|
+
|
|
130
|
+
# Create with retention (7-day, 1GB max)
|
|
131
|
+
topic = await client.create_topic_with_retention(
|
|
132
|
+
"logs", max_age_secs=7*86400, max_bytes=1024**3
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
await client.set_retention(topic["id"], max_age_secs=86400)
|
|
136
|
+
|
|
137
|
+
asyncio.run(main())
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Configuration
|
|
141
|
+
|
|
142
|
+
### ProducerConfig
|
|
143
|
+
|
|
144
|
+
| Option | Default | Description |
|
|
145
|
+
|--------|---------|-------------|
|
|
146
|
+
| `batch_size` | `32768` | Max batch size in bytes |
|
|
147
|
+
| `linger_ms` | `5` | Max wait before sending partial batch |
|
|
148
|
+
| `compression` | `False` | Enable LZ4 compression |
|
|
149
|
+
| `max_pending_acks` | `64` | Max unacknowledged batches |
|
|
150
|
+
|
|
151
|
+
### StandaloneConfig
|
|
152
|
+
|
|
153
|
+
| Option | Default | Description |
|
|
154
|
+
|--------|---------|-------------|
|
|
155
|
+
| `consumer_name` | `""` | Consumer identifier |
|
|
156
|
+
| `topic_id` | `0` | Topic to consume from |
|
|
157
|
+
| `max_fetch_bytes` | `65536` | Max bytes per fetch |
|
|
158
|
+
| `start_offset` | `0` | Initial byte offset |
|
|
159
|
+
| `poll_interval_ms` | `50` | Polling interval when idle |
|
|
160
|
+
|
|
161
|
+
### ClientConfig
|
|
162
|
+
|
|
163
|
+
| Option | Default | Description |
|
|
164
|
+
|--------|---------|-------------|
|
|
165
|
+
| `host` | `"localhost"` | Lance server hostname |
|
|
166
|
+
| `port` | `1992` | Lance server port |
|
|
167
|
+
|
|
168
|
+
## TLV Record Types
|
|
169
|
+
|
|
170
|
+
Records use Type-Length-Value encoding:
|
|
171
|
+
|
|
172
|
+
| Type | Code | Description |
|
|
173
|
+
|------|------|-------------|
|
|
174
|
+
| RawData | `0x01` | Unstructured binary |
|
|
175
|
+
| JSON | `0x02` | JSON-encoded record |
|
|
176
|
+
| MessagePack | `0x03` | MessagePack-encoded |
|
|
177
|
+
| KeyValue | `0x10` | Key-value pair |
|
|
178
|
+
| Timestamped | `0x11` | Timestamp + data |
|
|
179
|
+
| Null | `0xFF` | Tombstone/empty |
|
|
180
|
+
|
|
181
|
+
## Error Handling
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from lnc_client import (
|
|
185
|
+
LanceError,
|
|
186
|
+
ConnectionError,
|
|
187
|
+
BackpressureError,
|
|
188
|
+
TopicNotFoundError,
|
|
189
|
+
InvalidFrameError,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
try:
|
|
193
|
+
await producer.send(topic_id=99, data=b"test")
|
|
194
|
+
except TopicNotFoundError:
|
|
195
|
+
print("Topic doesn't exist")
|
|
196
|
+
except BackpressureError:
|
|
197
|
+
print("Server is overloaded, slow down")
|
|
198
|
+
except ConnectionError:
|
|
199
|
+
print("Connection lost")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Protocol Details
|
|
203
|
+
|
|
204
|
+
This client implements the [Lance Wire Protocol (LWP)](https://github.com/nitecon/lance) v1.0:
|
|
205
|
+
|
|
206
|
+
- **44-byte fixed header** with CRC32C validation
|
|
207
|
+
- **Hardware-accelerated checksums** (SSE4.2 / ARM CRC)
|
|
208
|
+
- **Backpressure signaling** from server
|
|
209
|
+
- **Keepalive** with 30-second timeout
|
|
210
|
+
- **Batched production** with ACK tracking
|
|
211
|
+
- **Offset-based consumption** with seek/rewind
|
|
212
|
+
- **LZ4 compression** (optional, per-batch)
|
|
213
|
+
- **Reconnection** with exponential backoff (100ms base, 30s max, jitter)
|
|
214
|
+
|
|
215
|
+
## Development
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
git clone https://github.com/nitecon/lnc-client-py.git
|
|
219
|
+
cd lnc-client-py
|
|
220
|
+
python3 -m venv .venv
|
|
221
|
+
source .venv/bin/activate
|
|
222
|
+
pip install -e ".[dev]"
|
|
223
|
+
pytest -v
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
39 tests covering protocol parsing, CRC32C validation, TLV encoding/decoding, and frame builders.
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# lnc-client
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/lnc-client/)
|
|
4
|
+
[](https://pypi.org/project/lnc-client/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
Python client for the **Lance Wire Protocol (LWP)** — high-performance, low-latency data streaming.
|
|
8
|
+
|
|
9
|
+
[Lance](https://github.com/nitecon/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.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install lnc-client
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Requirements:** Python 3.10+
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Producer
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import asyncio
|
|
25
|
+
from lnc_client import Producer, ProducerConfig
|
|
26
|
+
|
|
27
|
+
async def main():
|
|
28
|
+
producer = await Producer.connect("localhost:1992", ProducerConfig())
|
|
29
|
+
|
|
30
|
+
# Send with ACK (guaranteed delivery)
|
|
31
|
+
batch_id = await producer.send(topic_id=1, data=b'{"price": 6942.25}')
|
|
32
|
+
|
|
33
|
+
# Send without waiting for ACK (pipelined, higher throughput)
|
|
34
|
+
batch_id = await producer.send_async(topic_id=1, data=b'fire and forget')
|
|
35
|
+
|
|
36
|
+
await producer.close()
|
|
37
|
+
|
|
38
|
+
asyncio.run(main())
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Consumer
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import asyncio
|
|
45
|
+
from lnc_client import StandaloneConsumer, StandaloneConfig
|
|
46
|
+
|
|
47
|
+
async def main():
|
|
48
|
+
consumer = await StandaloneConsumer.connect(
|
|
49
|
+
"localhost:1992",
|
|
50
|
+
StandaloneConfig(consumer_name="my-app", topic_id=1),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
while True:
|
|
54
|
+
result = await consumer.poll()
|
|
55
|
+
if result is None:
|
|
56
|
+
await asyncio.sleep(0.05)
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
for record in result.records:
|
|
60
|
+
print(f"Type={record.record_type}, Data={record.value}")
|
|
61
|
+
|
|
62
|
+
print(f"Lag: {result.lag} bytes")
|
|
63
|
+
|
|
64
|
+
asyncio.run(main())
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Topic Management
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import asyncio
|
|
71
|
+
from lnc_client import LanceClient, ClientConfig
|
|
72
|
+
|
|
73
|
+
async def main():
|
|
74
|
+
async with LanceClient(ClientConfig(host="localhost")) as client:
|
|
75
|
+
topics = await client.list_topics()
|
|
76
|
+
|
|
77
|
+
topic = await client.create_topic("my-events")
|
|
78
|
+
|
|
79
|
+
# Create with retention (7-day, 1GB max)
|
|
80
|
+
topic = await client.create_topic_with_retention(
|
|
81
|
+
"logs", max_age_secs=7*86400, max_bytes=1024**3
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
await client.set_retention(topic["id"], max_age_secs=86400)
|
|
85
|
+
|
|
86
|
+
asyncio.run(main())
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
### ProducerConfig
|
|
92
|
+
|
|
93
|
+
| Option | Default | Description |
|
|
94
|
+
|--------|---------|-------------|
|
|
95
|
+
| `batch_size` | `32768` | Max batch size in bytes |
|
|
96
|
+
| `linger_ms` | `5` | Max wait before sending partial batch |
|
|
97
|
+
| `compression` | `False` | Enable LZ4 compression |
|
|
98
|
+
| `max_pending_acks` | `64` | Max unacknowledged batches |
|
|
99
|
+
|
|
100
|
+
### StandaloneConfig
|
|
101
|
+
|
|
102
|
+
| Option | Default | Description |
|
|
103
|
+
|--------|---------|-------------|
|
|
104
|
+
| `consumer_name` | `""` | Consumer identifier |
|
|
105
|
+
| `topic_id` | `0` | Topic to consume from |
|
|
106
|
+
| `max_fetch_bytes` | `65536` | Max bytes per fetch |
|
|
107
|
+
| `start_offset` | `0` | Initial byte offset |
|
|
108
|
+
| `poll_interval_ms` | `50` | Polling interval when idle |
|
|
109
|
+
|
|
110
|
+
### ClientConfig
|
|
111
|
+
|
|
112
|
+
| Option | Default | Description |
|
|
113
|
+
|--------|---------|-------------|
|
|
114
|
+
| `host` | `"localhost"` | Lance server hostname |
|
|
115
|
+
| `port` | `1992` | Lance server port |
|
|
116
|
+
|
|
117
|
+
## TLV Record Types
|
|
118
|
+
|
|
119
|
+
Records use Type-Length-Value encoding:
|
|
120
|
+
|
|
121
|
+
| Type | Code | Description |
|
|
122
|
+
|------|------|-------------|
|
|
123
|
+
| RawData | `0x01` | Unstructured binary |
|
|
124
|
+
| JSON | `0x02` | JSON-encoded record |
|
|
125
|
+
| MessagePack | `0x03` | MessagePack-encoded |
|
|
126
|
+
| KeyValue | `0x10` | Key-value pair |
|
|
127
|
+
| Timestamped | `0x11` | Timestamp + data |
|
|
128
|
+
| Null | `0xFF` | Tombstone/empty |
|
|
129
|
+
|
|
130
|
+
## Error Handling
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from lnc_client import (
|
|
134
|
+
LanceError,
|
|
135
|
+
ConnectionError,
|
|
136
|
+
BackpressureError,
|
|
137
|
+
TopicNotFoundError,
|
|
138
|
+
InvalidFrameError,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
await producer.send(topic_id=99, data=b"test")
|
|
143
|
+
except TopicNotFoundError:
|
|
144
|
+
print("Topic doesn't exist")
|
|
145
|
+
except BackpressureError:
|
|
146
|
+
print("Server is overloaded, slow down")
|
|
147
|
+
except ConnectionError:
|
|
148
|
+
print("Connection lost")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Protocol Details
|
|
152
|
+
|
|
153
|
+
This client implements the [Lance Wire Protocol (LWP)](https://github.com/nitecon/lance) v1.0:
|
|
154
|
+
|
|
155
|
+
- **44-byte fixed header** with CRC32C validation
|
|
156
|
+
- **Hardware-accelerated checksums** (SSE4.2 / ARM CRC)
|
|
157
|
+
- **Backpressure signaling** from server
|
|
158
|
+
- **Keepalive** with 30-second timeout
|
|
159
|
+
- **Batched production** with ACK tracking
|
|
160
|
+
- **Offset-based consumption** with seek/rewind
|
|
161
|
+
- **LZ4 compression** (optional, per-batch)
|
|
162
|
+
- **Reconnection** with exponential backoff (100ms base, 30s max, jitter)
|
|
163
|
+
|
|
164
|
+
## Development
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
git clone https://github.com/nitecon/lnc-client-py.git
|
|
168
|
+
cd lnc-client-py
|
|
169
|
+
python3 -m venv .venv
|
|
170
|
+
source .venv/bin/activate
|
|
171
|
+
pip install -e ".[dev]"
|
|
172
|
+
pytest -v
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
39 tests covering protocol parsing, CRC32C validation, TLV encoding/decoding, and frame builders.
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lnc-client"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python client for the Lance Wire Protocol (LWP) — high-performance, low-latency data streaming"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Will Hattingh", email = "nitecon@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["lance", "lwp", "streaming", "data-ingestion", "high-performance"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries",
|
|
26
|
+
"Topic :: System :: Networking",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"crc32c>=2.7",
|
|
30
|
+
"lz4>=4.3",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=8.0",
|
|
36
|
+
"pytest-asyncio>=0.24",
|
|
37
|
+
"pytest-timeout>=2.3",
|
|
38
|
+
"ruff>=0.9",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.urls]
|
|
42
|
+
Homepage = "https://github.com/nitecon/lnc-client-py"
|
|
43
|
+
Documentation = "https://github.com/nitecon/lnc-client-py#readme"
|
|
44
|
+
Issues = "https://github.com/nitecon/lnc-client-py/issues"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["src/lnc_client"]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist]
|
|
50
|
+
include = ["src/", "tests/", "LICENSE", "README.md", "pyproject.toml"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
asyncio_mode = "auto"
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
target-version = "py310"
|
|
58
|
+
line-length = 100
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint]
|
|
61
|
+
select = ["E", "F", "W", "I", "UP", "B", "SIM"]
|
|
62
|
+
ignore = ["E501"]
|
|
63
|
+
|
|
64
|
+
[tool.ruff.format]
|
|
65
|
+
quote-style = "double"
|