Lightweight Python UNS MQTT client (pub/sub + infra topics)
Project description
uns-kit (Python)
Lightweight UNS MQTT client for Python. Provides:
- Topic builder compatible with UNS infra topics (
uns-infra/<package>/<version>/<process>/). - Async publish/subscribe via MQTT v5 (using
asyncio-mqtt). - Infra status topics (
alive,uptime) with MQTT will. - Minimal UNS packet builder/parser (data/table).
Install (editable)
cd packages/uns-py
poetry install
CLI
After poetry install, a uns-kit command is available:
poetry run uns-kit publish --host localhost:1883 --topic raw/data/ --value 1
poetry run uns-kit subscribe --host localhost:1883 --topic 'uns-infra/#'
poetry run uns-kit write-config --path config.json
Quick start
import asyncio
from uns_kit import UnsMqttClient, TopicBuilder, UnsPacket
async def main():
tb = TopicBuilder(package_name="uns-kit", package_version="0.0.1", process_name="py-demo")
client = UnsMqttClient(host="mqtt-broker", topic_builder=tb, reconnect_interval=1)
await client.connect()
# Subscribe
async with client.messages("uns-infra/#") as messages:
await client.publish_packet("raw/data/", UnsPacket.data(value=1, uom="count"))
msg = await messages.__anext__()
print(msg.topic, msg.payload.decode())
await client.close()
asyncio.run(main())
Resilient subscriber
async for msg in client.resilient_messages("uns-infra/#"):
print(msg.topic, msg.payload.decode())
Examples
examples/publish.py— publish 5 data packets.examples/subscribe.py— resilient subscription with auto-reconnect.
Notes
- Default QoS is 0; will message is retained on
<statusTopic>alive. - Uptime is published every 10 seconds on
<statusTopic>uptime. - Packet shape mirrors the TypeScript core:
{"version":1,"message":{"data":{...}},"sequenceId":0}.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
uns_kit-0.0.2.tar.gz
(5.2 kB
view details)
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 uns_kit-0.0.2.tar.gz.
File metadata
- Download URL: uns_kit-0.0.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.1 CPython/3.14.2 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3345dd20f432e79721960cc2283c61c0969b7870838886d83a73dd95560b4469
|
|
| MD5 |
61134151f46034f2b55d18061682182a
|
|
| BLAKE2b-256 |
bcdbd476cd3e8ff6acd360d029173f3c143f4ed7800e7c60c843cc68c55052cf
|
File details
Details for the file uns_kit-0.0.2-py3-none-any.whl.
File metadata
- Download URL: uns_kit-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.1 CPython/3.14.2 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c448be8523a42d76a21a84eea0460b55ced3ce9c3d4c8ede122b57ae7a1e355
|
|
| MD5 |
c7ba20890dc91ce45dcd056ce7846382
|
|
| BLAKE2b-256 |
502d74076029f444144016fc96e6fd0e6f3861c8b8f2ce6b7b4c4ca6b30f74a9
|