stinger-python-utils 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl
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.
- stinger_python_utils/message_creator.py +5 -4
- stinger_python_utils-0.1.4.dist-info/METADATA +84 -0
- stinger_python_utils-0.1.4.dist-info/RECORD +7 -0
- stinger_python_utils-0.1.2.dist-info/METADATA +0 -13
- stinger_python_utils-0.1.2.dist-info/RECORD +0 -7
- {stinger_python_utils-0.1.2.dist-info → stinger_python_utils-0.1.4.dist-info}/WHEEL +0 -0
- {stinger_python_utils-0.1.2.dist-info → stinger_python_utils-0.1.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -32,7 +32,7 @@ class MessageCreator:
|
|
|
32
32
|
cls,
|
|
33
33
|
topic: str,
|
|
34
34
|
return_code: int,
|
|
35
|
-
correlation_id: Union[str, bytes],
|
|
35
|
+
correlation_id: Union[str, bytes, None] = None,
|
|
36
36
|
debug_info: Optional[str] = None,
|
|
37
37
|
) -> Message:
|
|
38
38
|
"""
|
|
@@ -60,9 +60,9 @@ class MessageCreator:
|
|
|
60
60
|
def response_message(
|
|
61
61
|
cls,
|
|
62
62
|
response_topic: str,
|
|
63
|
-
response_obj: BaseModel
|
|
63
|
+
response_obj: Union[BaseModel, str, bytes],
|
|
64
64
|
return_code: int,
|
|
65
|
-
correlation_id: Union[str, bytes],
|
|
65
|
+
correlation_id: Union[str, bytes, None] = None,
|
|
66
66
|
) -> Message:
|
|
67
67
|
"""
|
|
68
68
|
This could be used for a successful response to a request.
|
|
@@ -99,6 +99,7 @@ class MessageCreator:
|
|
|
99
99
|
payload=state_obj.model_dump_json(by_alias=True).encode("utf-8"),
|
|
100
100
|
qos=1,
|
|
101
101
|
retain=True,
|
|
102
|
+
content_type="application/json",
|
|
102
103
|
)
|
|
103
104
|
if state_version is not None:
|
|
104
105
|
msg_obj.user_properties = {"PropertyVersion": str(state_version)}
|
|
@@ -138,7 +139,7 @@ class MessageCreator:
|
|
|
138
139
|
property_obj: BaseModel,
|
|
139
140
|
version: str,
|
|
140
141
|
return_code: int,
|
|
141
|
-
correlation_id: Union[str, bytes],
|
|
142
|
+
correlation_id: Union[str, bytes, None] = None,
|
|
142
143
|
debug_info: Optional[str] = None,
|
|
143
144
|
) -> Message:
|
|
144
145
|
"""
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stinger-python-utils
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Common utilities for Stinger Python services.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.7
|
|
8
|
+
Requires-Dist: pydantic>=2.5.3
|
|
9
|
+
Requires-Dist: pyqttier>=0.2.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# stinger-python-utils
|
|
13
|
+
|
|
14
|
+
Shared utilities for Stinger Python services, providing convenient message creation for MQTT communication.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
uv add stinger-python-utils
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## MessageCreator
|
|
25
|
+
|
|
26
|
+
`MessageCreator` is a utility class for creating MQTT messages with standardized properties and payloads.
|
|
27
|
+
|
|
28
|
+
### Basic Usage
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from pydantic import BaseModel
|
|
32
|
+
from stinger_python_utils.message_creator import MessageCreator
|
|
33
|
+
|
|
34
|
+
class MyPayload(BaseModel):
|
|
35
|
+
name: str
|
|
36
|
+
value: int
|
|
37
|
+
|
|
38
|
+
payload = MyPayload(name="test", value=42)
|
|
39
|
+
message = MessageCreator.signal_message("my/topic", payload)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Methods
|
|
43
|
+
|
|
44
|
+
| Method | Purpose | Return Code |
|
|
45
|
+
|--------|---------|-------------|
|
|
46
|
+
| `signal_message(topic, payload)` | Send a signal with one-time delivery | QoS 1, no retain |
|
|
47
|
+
| `status_message(topic, payload, expiry_seconds)` | Send status that expires | QoS 1, retained, with expiry |
|
|
48
|
+
| `error_response_message(topic, return_code, correlation_id, debug_info)` | Error response to a request | QoS 1, user properties: `ReturnCode` |
|
|
49
|
+
| `response_message(topic, payload, return_code, correlation_id)` | Successful response to a request | QoS 1, user properties: `ReturnCode` |
|
|
50
|
+
| `property_state_message(topic, payload, state_version)` | Publish property state | QoS 1, retained, JSON content type |
|
|
51
|
+
| `property_update_request_message(topic, payload, version, response_topic, correlation_id)` | Request property update | QoS 1, user property: `PropertyVersion` |
|
|
52
|
+
| `property_response_message(topic, payload, version, return_code, correlation_id, debug_info)` | Respond to property update | QoS 1, user properties: `ReturnCode`, `PropertyVersion` |
|
|
53
|
+
| `request_message(topic, payload, response_topic, correlation_id)` | Send a request (auto-generates UUID if no correlation_id) | QoS 1, auto correlation ID |
|
|
54
|
+
|
|
55
|
+
### Example: Request/Response Pattern
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from pydantic import BaseModel
|
|
59
|
+
from stinger_python_utils.message_creator import MessageCreator
|
|
60
|
+
|
|
61
|
+
class Request(BaseModel):
|
|
62
|
+
action: str
|
|
63
|
+
|
|
64
|
+
request = Request(action="start")
|
|
65
|
+
msg = MessageCreator.request_message(
|
|
66
|
+
"devices/cmd",
|
|
67
|
+
request,
|
|
68
|
+
response_topic="devices/response"
|
|
69
|
+
)
|
|
70
|
+
# Returns a Message with auto-generated correlation ID
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Example: Error Response
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
msg = MessageCreator.error_response_message(
|
|
77
|
+
"devices/response",
|
|
78
|
+
return_code=500,
|
|
79
|
+
correlation_id="req-123",
|
|
80
|
+
debug_info="Device not found"
|
|
81
|
+
)
|
|
82
|
+
# User properties include: ReturnCode=500, DebugInfo=Device not found
|
|
83
|
+
```
|
|
84
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
stinger_python_utils/__init__.py,sha256=IjHRV0k2DNwvFrEHebmsXiBvmITE8nQUnsR07h9tVkU,7
|
|
2
|
+
stinger_python_utils/message_creator.py,sha256=tsGmcw5-iC58lBq4aJQrI3IDZ3cE88C5FOT_5lHLvn0,6160
|
|
3
|
+
stinger_python_utils/return_codes.py,sha256=AAwshvHu3SBoctwMX35k3j666J4a7DQ3V8AnR7QBjC8,5114
|
|
4
|
+
stinger_python_utils-0.1.4.dist-info/METADATA,sha256=Ces8NRPz6g4Vuo2UYlG_3yMSmciZF9XuaAcJqfMHYFA,2769
|
|
5
|
+
stinger_python_utils-0.1.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
+
stinger_python_utils-0.1.4.dist-info/licenses/LICENSE,sha256=_T-8ExmblJbhv-1AxC6XDVEHg1JdJA-126NvRiMqS-I,1070
|
|
7
|
+
stinger_python_utils-0.1.4.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: stinger-python-utils
|
|
3
|
-
Version: 0.1.2
|
|
4
|
-
Summary: Common utilities for Stinger Python services.
|
|
5
|
-
License-Expression: MIT
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Requires-Python: >=3.7
|
|
8
|
-
Requires-Dist: pydantic>=2.5.3
|
|
9
|
-
Requires-Dist: pyqttier>=0.2.0
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
|
|
12
|
-
# stinger-python-utils
|
|
13
|
-
Common code needed for stinger python generations
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
stinger_python_utils/__init__.py,sha256=IjHRV0k2DNwvFrEHebmsXiBvmITE8nQUnsR07h9tVkU,7
|
|
2
|
-
stinger_python_utils/message_creator.py,sha256=ZR4FOhkmJ5R_X5QS-c-QAIpcN-7htIOiHtO40QUS35Y,6071
|
|
3
|
-
stinger_python_utils/return_codes.py,sha256=AAwshvHu3SBoctwMX35k3j666J4a7DQ3V8AnR7QBjC8,5114
|
|
4
|
-
stinger_python_utils-0.1.2.dist-info/METADATA,sha256=LxgDU_LYLjt9F5FMBkIsiK_XR61DL1tOEVOxI0glX78,364
|
|
5
|
-
stinger_python_utils-0.1.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
-
stinger_python_utils-0.1.2.dist-info/licenses/LICENSE,sha256=_T-8ExmblJbhv-1AxC6XDVEHg1JdJA-126NvRiMqS-I,1070
|
|
7
|
-
stinger_python_utils-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
{stinger_python_utils-0.1.2.dist-info → stinger_python_utils-0.1.4.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|