Skip to main content

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.

Create a new project

uns-kit-py create my-uns-py-app
cd my-uns-py-app
poetry install
poetry run python src/main.py

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


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.4.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uns_kit-0.0.4-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file uns_kit-0.0.4.tar.gz.

File metadata

  • Download URL: uns_kit-0.0.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.14.2 Darwin/25.1.0

File hashes

Hashes for uns_kit-0.0.4.tar.gz
Algorithm Hash digest
SHA256 70d56b7237c0cd4a1b778318808946d0a48ca25ea94687bb408e41b8ebffdafc
MD5 f22007896c1115432fc0d303f1cdc021
BLAKE2b-256 c4abf1cbd2dca116eb4061197c1b0ed8013a72a1d72606cbb986705ea7d4c372

See more details on using hashes here.

File details

Details for the file uns_kit-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: uns_kit-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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

Hashes for uns_kit-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 65ce003dd46a7720a969686db16dc827312a429bfac46cc10f18bc7fdf863876
MD5 03a50454fd5646348a3800856006448f
BLAKE2b-256 202b5fbf2172cef47d4a80b86b440d4be4f82915f8300e6a99b3b5d7f0f4672e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page