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, an uns-kit-py command is available (renamed to avoid clashing with the Node CLI):
poetry run uns-kit-py publish --host localhost:1883 --topic raw/data/ --value 1
poetry run uns-kit-py subscribe --host localhost:1883 --topic 'uns-infra/#'
poetry run uns-kit-py 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.3.tar.gz
(5.3 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.3.tar.gz.
File metadata
- Download URL: uns_kit-0.0.3.tar.gz
- Upload date:
- Size: 5.3 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 |
ee08e69833e155b681727238d2f5bffcce9b5d29bc262000d84a07624f709f0b
|
|
| MD5 |
30d993d9d6e2d2cf5155b279f9f35724
|
|
| BLAKE2b-256 |
959b4ff3ff4f3d88a2515a716e156ab19b7602107603b89be4fc8b9c5da0ebff
|
File details
Details for the file uns_kit-0.0.3-py3-none-any.whl.
File metadata
- Download URL: uns_kit-0.0.3-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 |
13d48ec42a3257d6ff4e6feb14067aabec093188ff8b03a978c521f8f571ae60
|
|
| MD5 |
e315c7d5bd6071a2c3ab911467ae765f
|
|
| BLAKE2b-256 |
1b96e73c022e6aa1ee9692d7644223a58d44145f001ee82568ffc4eb4fa51804
|