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 (using aiomqtt).
  • Process + instance status topics (active/heap/uptime/alive + stats).
  • Minimal UNS packet builder/parser (data/table) aligned with TS core.

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/#'

Quick start

import asyncio
from pathlib import Path
from uns_kit import UnsConfig, UnsPacket, UnsProxyProcess

async def main():
    config = UnsConfig.load(Path("config.json"))
    process = UnsProxyProcess(config.infra_host, config=config)
    await process.start()
    mqtt = await process.create_mqtt_proxy("py")

    # Subscribe
    async with mqtt.client.messages("uns-infra/#") as messages:
        await mqtt.publish_packet("raw/data/", UnsPacket.data(value=1, uom="count"))
        msg = await messages.__anext__()
        print(msg.topic, msg.payload.decode())

    await mqtt.close()
    await process.stop()

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.
  • examples/load_test.py — interactive publish burst.

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

Create a sandbox app in this repo

From the monorepo root:

pnpm run py:sandbox

This creates sandbox-app-py/ using the default Python template.

Notes

  • Default QoS is 0.
  • Instance status topics are published every 10 seconds; stats every 60 seconds.
  • Packet shape mirrors the TypeScript core: {"version":"1.3.0","message":{"data":{...}},"sequenceId":0}.

TODO (parity with TS core)

  • Handover manager (cross-version active detection + handover_* messages).
  • Publish throttling/queue.
  • Status parity (publisher/subscriber active flags everywhere, richer metrics).
  • API endpoints registry (to mirror @uns-kit/api produced endpoints).
  • Optional: dictionary/measurement helpers + CLI wrapper.

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.25.tar.gz (23.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.25-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for uns_kit-0.0.25.tar.gz
Algorithm Hash digest
SHA256 ec2411b017ffd4ddcc87d6c29d8f21f5d97c6e481ba5dce1427c34680d36de7c
MD5 d7ec215927e25a959a6de5d90d3d9c51
BLAKE2b-256 e96c3a59102147d10d571a1f4b855f292b0290ed6fb076bacadd1b8a33b0d7c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uns_kit-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.14.2 Darwin/25.3.0

File hashes

Hashes for uns_kit-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 fa76d705ba6c9dcc4ac8d6921c7f849d52a9c4c2d845cb859b289b871101f238
MD5 89e16e17323fc07c5f67850021c8be16
BLAKE2b-256 8af0583c645c8ae90b48a25dafa7c942f1b91e808cf133db9da64ea00b7aeb9a

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