uns-kit 0.0.3__tar.gz → 0.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uns-kit
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Lightweight Python UNS MQTT client (pub/sub + infra topics)
5
5
  License: MIT
6
6
  Author: Aljoša Vister
@@ -70,6 +70,14 @@ async for msg in client.resilient_messages("uns-infra/#"):
70
70
  - `examples/publish.py` — publish 5 data packets.
71
71
  - `examples/subscribe.py` — resilient subscription with auto-reconnect.
72
72
 
73
+ ### Create a new project
74
+ ```bash
75
+ uns-kit-py create my-uns-py-app
76
+ cd my-uns-py-app
77
+ poetry install
78
+ poetry run python src/main.py
79
+ ```
80
+
73
81
  ## Notes
74
82
  - Default QoS is 0; will message is retained on `<statusTopic>alive`.
75
83
  - Uptime is published every 10 seconds on `<statusTopic>uptime`.
@@ -51,6 +51,14 @@ async for msg in client.resilient_messages("uns-infra/#"):
51
51
  - `examples/publish.py` — publish 5 data packets.
52
52
  - `examples/subscribe.py` — resilient subscription with auto-reconnect.
53
53
 
54
+ ### Create a new project
55
+ ```bash
56
+ uns-kit-py create my-uns-py-app
57
+ cd my-uns-py-app
58
+ poetry install
59
+ poetry run python src/main.py
60
+ ```
61
+
54
62
  ## Notes
55
63
  - Default QoS is 0; will message is retained on `<statusTopic>alive`.
56
64
  - Uptime is published every 10 seconds on `<statusTopic>uptime`.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "uns-kit"
3
- version = "0.0.3"
3
+ version = "0.0.4"
4
4
  description = "Lightweight Python UNS MQTT client (pub/sub + infra topics)"
5
5
  authors = ["Aljoša Vister <aljosa.vister@gmail.com>"]
6
6
  license = "MIT"
@@ -2,6 +2,9 @@ from __future__ import annotations
2
2
 
3
3
  import asyncio
4
4
  import json
5
+ import os
6
+ import shutil
7
+ import importlib.resources
5
8
  from pathlib import Path
6
9
  from typing import Optional
7
10
 
@@ -120,6 +123,22 @@ async def _run_subscribe(
120
123
  print(f"{msg.topic} <binary {len(msg.payload)} bytes>")
121
124
 
122
125
 
126
+ @cli.command("create", help="Create a new UNS Python app (default template).")
127
+ @click.argument("dest")
128
+ def create(dest: str):
129
+ template_root = importlib.resources.files("uns_kit").joinpath("templates/default")
130
+ dest_path = os.path.abspath(dest)
131
+ if os.path.exists(dest_path):
132
+ raise click.ClickException(f"Destination already exists: {dest_path}")
133
+ shutil.copytree(template_root, dest_path)
134
+ click.echo(f"Created UNS Python app at {dest_path}")
135
+ click.echo("Next steps:")
136
+ click.echo(f" 1) cd {dest_path}")
137
+ click.echo(" 2) poetry install")
138
+ click.echo(" 3) poetry run python src/main.py")
139
+ click.echo(" 4) Edit config.json with your MQTT host/credentials")
140
+
141
+
123
142
  @cli.command("write-config", help="Write a minimal config.json scaffold.")
124
143
  @click.option("--path", default="config.json", show_default=True)
125
144
  def write_config(path: str):
@@ -0,0 +1,10 @@
1
+ # UNS Python App Template
2
+
3
+ ## Setup
4
+ ```bash
5
+ poetry install
6
+ poetry run python src/main.py
7
+ ```
8
+
9
+ ## Config
10
+ Edit `config.json` with your MQTT host/auth.
@@ -0,0 +1,17 @@
1
+ [tool.poetry]
2
+ name = "uns-py-app"
3
+ version = "0.1.0"
4
+ description = "Example UNS Python application"
5
+ authors = ["Your Name <you@example.com>"]
6
+ package-mode = false
7
+
8
+ [tool.poetry.dependencies]
9
+ python = "^3.10"
10
+ uns-kit = "*"
11
+
12
+ [tool.poetry.group.dev.dependencies]
13
+ pytest = "^8.3.3"
14
+
15
+ [build-system]
16
+ requires = ["poetry-core"]
17
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,27 @@
1
+ import asyncio
2
+ import json
3
+ from pathlib import Path
4
+ from uns_kit import UnsMqttClient, TopicBuilder, UnsPacket
5
+
6
+
7
+ async def main():
8
+ cfg = json.loads(Path("config.json").read_text())
9
+ tb = TopicBuilder(cfg["packageName"], cfg["packageVersion"], cfg["processName"])
10
+ client = UnsMqttClient(
11
+ cfg["host"],
12
+ port=cfg.get("port"),
13
+ username=cfg.get("username") or None,
14
+ password=cfg.get("password") or None,
15
+ tls=cfg.get("tls", False),
16
+ client_id=cfg.get("clientId"),
17
+ topic_builder=tb,
18
+ reconnect_interval=1,
19
+ )
20
+ await client.connect()
21
+ await client.publish_packet("raw/data/", UnsPacket.data(value=1, uom="count"))
22
+ async for msg in client.resilient_messages("uns-infra/#"):
23
+ print(msg.topic, msg.payload.decode())
24
+
25
+
26
+ if __name__ == "__main__":
27
+ asyncio.run(main())
File without changes
File without changes
File without changes
File without changes