relayx-app-sdk 0.1.0__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.
- relayx_app_sdk-0.1.0/LICENSE +201 -0
- relayx_app_sdk-0.1.0/PKG-INFO +14 -0
- relayx_app_sdk-0.1.0/README.md +473 -0
- relayx_app_sdk-0.1.0/pyproject.toml +27 -0
- relayx_app_sdk-0.1.0/setup.cfg +4 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/__init__.py +3 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/alerts.py +556 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/app.py +97 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/commands.py +136 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/connection.py +317 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/context.py +83 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/device.py +148 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/ephemeral_alerting/__init__.py +3 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/ephemeral_alerting/engine.py +88 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/ephemeral_alerting/listener.py +136 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/ephemeral_alerting/owner.py +686 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/ephemeral_alerting/shared.py +137 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/events.py +102 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/heirarchy_group.py +259 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/logical_group.py +229 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/notifications.py +97 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/rpc.py +31 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/telemetry.py +307 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/utils.py +91 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk/validation.py +147 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk.egg-info/PKG-INFO +14 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk.egg-info/SOURCES.txt +43 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk.egg-info/dependency_links.txt +1 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk.egg-info/requires.txt +7 -0
- relayx_app_sdk-0.1.0/src/relayx_app_sdk.egg-info/top_level.txt +1 -0
- relayx_app_sdk-0.1.0/tests/test_alerts.py +577 -0
- relayx_app_sdk-0.1.0/tests/test_app.py +121 -0
- relayx_app_sdk-0.1.0/tests/test_commands.py +166 -0
- relayx_app_sdk-0.1.0/tests/test_connection.py +316 -0
- relayx_app_sdk-0.1.0/tests/test_context.py +126 -0
- relayx_app_sdk-0.1.0/tests/test_device.py +283 -0
- relayx_app_sdk-0.1.0/tests/test_ephemeral_alerting.py +707 -0
- relayx_app_sdk-0.1.0/tests/test_events.py +122 -0
- relayx_app_sdk-0.1.0/tests/test_heirarchy_group.py +243 -0
- relayx_app_sdk-0.1.0/tests/test_logical_group.py +218 -0
- relayx_app_sdk-0.1.0/tests/test_notifications.py +208 -0
- relayx_app_sdk-0.1.0/tests/test_rpc.py +110 -0
- relayx_app_sdk-0.1.0/tests/test_telemetry.py +365 -0
- relayx_app_sdk-0.1.0/tests/test_utils.py +71 -0
- relayx_app_sdk-0.1.0/tests/test_validation.py +413 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: relayx_app_sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: RelayX App SDK for Python
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: nats-py>=2.9.0
|
|
9
|
+
Requires-Dist: msgpack>=1.0.0
|
|
10
|
+
Requires-Dist: nkeys==0.2.1
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
13
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
14
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
# RelayX App SDK for Python
|
|
2
|
+
|
|
3
|
+
Official Python SDK for building applications on the RelayX platform.
|
|
4
|
+
|
|
5
|
+
> **[View Full Documentation →](https://docs.relay-x.io/app-sdk/overview)**
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install relayx_app_sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import asyncio
|
|
17
|
+
from relayx_app_sdk import RelayApp
|
|
18
|
+
|
|
19
|
+
app = RelayApp({
|
|
20
|
+
"api_key": "<YOUR_API_KEY>",
|
|
21
|
+
"secret": "<YOUR_SECRET>",
|
|
22
|
+
"mode": "production",
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
async def main():
|
|
26
|
+
app.connection.listeners(lambda event: print(f"[connection] {event}"))
|
|
27
|
+
await app.connect()
|
|
28
|
+
|
|
29
|
+
await app.telemetry.stream({
|
|
30
|
+
"device_ident": "sensor-1",
|
|
31
|
+
"metric": "temperature",
|
|
32
|
+
"callback": lambda data: print(f"temp: {data}"),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
# ... your application logic ...
|
|
36
|
+
|
|
37
|
+
await app.disconnect()
|
|
38
|
+
|
|
39
|
+
asyncio.run(main())
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
app = RelayApp({
|
|
46
|
+
"api_key": "<YOUR_API_KEY>", # JWT credential from RelayX console
|
|
47
|
+
"secret": "<YOUR_SECRET>", # Secret key
|
|
48
|
+
"mode": "production", # "production" | "test"
|
|
49
|
+
"debug": False, # Enable debug logging (default: False)
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Get your credentials at [console.relay-x.io](https://console.relay-x.io).
|
|
54
|
+
<!-- TODO: Link to sign-up tutorial -->
|
|
55
|
+
|
|
56
|
+
## Connection
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
await app.connect()
|
|
60
|
+
await app.disconnect()
|
|
61
|
+
|
|
62
|
+
# Connection lifecycle events
|
|
63
|
+
app.connection.listeners(lambda event: print(event))
|
|
64
|
+
# Events: "connected" | "disconnected" | "reconnecting" | "reconnected" | "auth_failed"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Presence
|
|
68
|
+
|
|
69
|
+
Subscribe to device connect/disconnect events.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
async def on_presence(data):
|
|
73
|
+
print(f"{data['device_ident']} {data['event']}")
|
|
74
|
+
# data["event"]: "connected" | "disconnected"
|
|
75
|
+
|
|
76
|
+
await app.connection.presence(on_presence)
|
|
77
|
+
|
|
78
|
+
# Unsubscribe
|
|
79
|
+
await app.connection.presence_off()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Devices
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
# List all devices
|
|
86
|
+
devices = await app.device.list()
|
|
87
|
+
|
|
88
|
+
# Get a single device
|
|
89
|
+
device = await app.device.get({"ident": "sensor-1"})
|
|
90
|
+
|
|
91
|
+
# Create a device
|
|
92
|
+
device = await app.device.create({
|
|
93
|
+
"ident": "sensor-1",
|
|
94
|
+
"schema": {
|
|
95
|
+
"temperature": {"type": "number", "unit": "Celsius", "unit_symbol": "°C"},
|
|
96
|
+
"humidity": {"type": "number", "unit": "Percentage", "unit_symbol": "%"},
|
|
97
|
+
},
|
|
98
|
+
"config": {},
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
# Update a device
|
|
102
|
+
device = await app.device.update({
|
|
103
|
+
"id": device["id"],
|
|
104
|
+
"config": {"interval": 5000},
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
# Delete a device
|
|
108
|
+
await app.device.delete("sensor-1")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Telemetry
|
|
112
|
+
|
|
113
|
+
### Live Streaming
|
|
114
|
+
|
|
115
|
+
Stream real-time telemetry from a device. The `metric` is validated against the device schema.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
# Stream a specific metric
|
|
119
|
+
await app.telemetry.stream({
|
|
120
|
+
"device_ident": "sensor-1",
|
|
121
|
+
"metric": "temperature",
|
|
122
|
+
"callback": lambda data: print(f"[{data['metric']}] {data['data']}"),
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
# Stream all metrics
|
|
126
|
+
await app.telemetry.stream({
|
|
127
|
+
"device_ident": "sensor-1",
|
|
128
|
+
"metric": "*",
|
|
129
|
+
"callback": lambda data: print(data),
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
# Unsubscribe from specific metrics
|
|
133
|
+
await app.telemetry.off({"device_ident": "sensor-1", "metric": ["temperature"]})
|
|
134
|
+
|
|
135
|
+
# Unsubscribe from all metrics for a device
|
|
136
|
+
await app.telemetry.off({"device_ident": "sensor-1"})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### History
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
history = await app.telemetry.history({
|
|
143
|
+
"device_ident": "sensor-1",
|
|
144
|
+
"fields": ["temperature", "humidity"],
|
|
145
|
+
"start": "2026-03-01T00:00:00.000Z",
|
|
146
|
+
"end": "2026-03-25T00:00:00.000Z",
|
|
147
|
+
})
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Latest
|
|
151
|
+
|
|
152
|
+
Fetches the most recent telemetry values (last 24 hours).
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
latest = await app.telemetry.latest({
|
|
156
|
+
"device_ident": "sensor-1",
|
|
157
|
+
"fields": ["temperature", "humidity"],
|
|
158
|
+
})
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Commands
|
|
162
|
+
|
|
163
|
+
Send one-way commands to devices.
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
# Send to one or more devices
|
|
167
|
+
result = await app.command.send({
|
|
168
|
+
"name": "set_interval",
|
|
169
|
+
"device_ident": ["sensor-1", "sensor-2"],
|
|
170
|
+
"data": {"interval": 5000},
|
|
171
|
+
})
|
|
172
|
+
# result: {"sensor-1": {"sent": True}, "sensor-2": {"sent": True}}
|
|
173
|
+
|
|
174
|
+
# Command history
|
|
175
|
+
history = await app.command.history({
|
|
176
|
+
"name": "set_interval",
|
|
177
|
+
"device_idents": ["sensor-1"],
|
|
178
|
+
"start": "2026-03-01T00:00:00.000Z",
|
|
179
|
+
"end": "2026-03-25T00:00:00.000Z",
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## RPC
|
|
184
|
+
|
|
185
|
+
Make request/reply calls to devices.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
response = await app.rpc.call({
|
|
189
|
+
"device_ident": "sensor-1",
|
|
190
|
+
"name": "get_status",
|
|
191
|
+
"data": {"verbose": True},
|
|
192
|
+
"timeout": 10, # seconds (default: 10)
|
|
193
|
+
})
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Events
|
|
197
|
+
|
|
198
|
+
Subscribe to device-published events.
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
await app.events.stream({
|
|
202
|
+
"name": "door_opened",
|
|
203
|
+
"callback": lambda data: print(f"Event: {data}"),
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
await app.events.off({"name": "door_opened"})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Alerts
|
|
210
|
+
|
|
211
|
+
### CRUD
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
# Create a threshold alert
|
|
215
|
+
alert = await app.alert.create({
|
|
216
|
+
"name": "high-temp",
|
|
217
|
+
"type": "THRESHOLD", # "THRESHOLD" | "RATE_CHANGE"
|
|
218
|
+
"metric": "temperature",
|
|
219
|
+
"config": {"threshold": 85, "duration": 5},
|
|
220
|
+
"notification_channel": ["ops-webhook"],
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
# Get, update, delete
|
|
224
|
+
alert = await app.alert.get("high-temp")
|
|
225
|
+
alert = await app.alert.update({"id": alert["id"], "config": {"threshold": 90}})
|
|
226
|
+
await app.alert.delete(alert["id"])
|
|
227
|
+
|
|
228
|
+
# List all alerts
|
|
229
|
+
alerts = await app.alert.list()
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Listening
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
alert = await app.alert.get("high-temp")
|
|
236
|
+
|
|
237
|
+
await alert.listen({
|
|
238
|
+
"on_fire": lambda data: print("FIRED:", data),
|
|
239
|
+
"on_resolved": lambda data: print("RESOLVED:", data),
|
|
240
|
+
"on_ack": lambda data: print("ACK:", data),
|
|
241
|
+
"on_ack_all": lambda data: print("ACK ALL:", data),
|
|
242
|
+
})
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### History
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
history = await app.alert.history({
|
|
249
|
+
"rule_type": "RULE", # "RULE" | "DEVICE"
|
|
250
|
+
"rule_id": alert["id"],
|
|
251
|
+
"rule_states": ["fire", "resolved"],
|
|
252
|
+
"start": "2026-03-01T00:00:00.000Z",
|
|
253
|
+
"end": "2026-03-25T00:00:00.000Z",
|
|
254
|
+
})
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Acknowledge
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
# Acknowledge for a specific device
|
|
261
|
+
await app.alert.ack({
|
|
262
|
+
"device_id": "<device_id>",
|
|
263
|
+
"alert_id": alert["id"],
|
|
264
|
+
"acked_by": "operator-1",
|
|
265
|
+
"ack_notes": "Investigating",
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
# Acknowledge all instances
|
|
269
|
+
await app.alert.ack_all({
|
|
270
|
+
"alert_id": alert["id"],
|
|
271
|
+
"acked_by": "operator-1",
|
|
272
|
+
})
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Mute / Unmute
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
await app.alert.mute({
|
|
279
|
+
"id": alert["id"],
|
|
280
|
+
"mute_config": {"type": "FOREVER"},
|
|
281
|
+
# or {"type": "TIME_BASED", "mute_till": "2026-04-01T00:00:00.000Z"}
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
await app.alert.unmute(alert["id"])
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Ephemeral Alerts
|
|
288
|
+
|
|
289
|
+
Ephemeral alerts let you define custom alert rules that are evaluated client-side with your own logic. See the full guide: [Ephemeral Alerting Guide](docs/ephemeral-alerting.md).
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
# Create an ephemeral alert
|
|
293
|
+
alert = await app.alert.create_ephemeral({
|
|
294
|
+
"name": "custom-temp-alert",
|
|
295
|
+
"config": {
|
|
296
|
+
"topic": {
|
|
297
|
+
"source": "TELEMETRY",
|
|
298
|
+
"device_ident": "sensor-1",
|
|
299
|
+
"last_token": "temperature",
|
|
300
|
+
},
|
|
301
|
+
"duration": 5,
|
|
302
|
+
"recovery_duration": 10,
|
|
303
|
+
"recovery_eval_type": "VALUE",
|
|
304
|
+
},
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
# Set your evaluator
|
|
308
|
+
alert.set_evaluator(
|
|
309
|
+
lambda state: state.get("sensor-1", {}).get("temperature", {}).get("value", 0) > 85
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
# Start monitoring
|
|
313
|
+
await alert.listen({
|
|
314
|
+
"on_fire": lambda data: print("ALERT:", data),
|
|
315
|
+
"on_resolved": lambda data: print("RESOLVED:", data),
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
# Stop
|
|
319
|
+
await alert.stop()
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Logical Groups
|
|
323
|
+
|
|
324
|
+
Group devices by tags for batch operations and streaming.
|
|
325
|
+
|
|
326
|
+
```python
|
|
327
|
+
# Create
|
|
328
|
+
group = await app.logical_group.create({
|
|
329
|
+
"name": "floor-1-sensors",
|
|
330
|
+
"tags": ["floor_1", "temperature"],
|
|
331
|
+
"device_idents": ["sensor-1", "sensor-2"],
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
# Update membership
|
|
335
|
+
group = await app.logical_group.update({
|
|
336
|
+
"id": group["id"],
|
|
337
|
+
"devices": {"add": ["sensor-3"], "remove": ["sensor-1"]},
|
|
338
|
+
"tags": {"add": ["humidity"], "remove": ["floor_1"]},
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
# List, get, delete
|
|
342
|
+
groups = await app.logical_group.list()
|
|
343
|
+
group = await app.logical_group.get(group["id"])
|
|
344
|
+
devices = await app.logical_group.list_devices(group["id"])
|
|
345
|
+
await app.logical_group.delete(group["id"])
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Group Streaming
|
|
349
|
+
|
|
350
|
+
Each group instance has `stream()` and `off()` methods.
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
group = await app.logical_group.get("<group_id>")
|
|
354
|
+
|
|
355
|
+
await group.stream({
|
|
356
|
+
"callback": lambda data: print(data),
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
await group.off()
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## Hierarchy Groups
|
|
363
|
+
|
|
364
|
+
Organize devices in a hierarchy path (e.g., `building_1.floor_2.zone_a`).
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
# Create
|
|
368
|
+
group = await app.heirarchy_group.create({
|
|
369
|
+
"name": "zone-a-sensors",
|
|
370
|
+
"heirarchy": "building_1.floor_2.zone_a",
|
|
371
|
+
"device_idents": ["sensor-1", "sensor-2"],
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
# Update
|
|
375
|
+
group = await app.heirarchy_group.update({
|
|
376
|
+
"id": group["id"],
|
|
377
|
+
"devices": {"add": ["sensor-3"], "remove": []},
|
|
378
|
+
"heirarchy": "building_1.floor_3.zone_a",
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
# List, get, delete
|
|
382
|
+
groups = await app.heirarchy_group.list()
|
|
383
|
+
group = await app.heirarchy_group.get(group["id"])
|
|
384
|
+
devices = await app.heirarchy_group.list_devices(group["id"])
|
|
385
|
+
await app.heirarchy_group.delete(group["id"])
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Hierarchy Group Streaming
|
|
389
|
+
|
|
390
|
+
Supports metric and hierarchy path filtering with wildcards.
|
|
391
|
+
|
|
392
|
+
```python
|
|
393
|
+
group = await app.heirarchy_group.get("<group_id>")
|
|
394
|
+
|
|
395
|
+
# Stream all data
|
|
396
|
+
await group.stream({"callback": lambda data: print(data)})
|
|
397
|
+
|
|
398
|
+
# Filter by metric
|
|
399
|
+
await group.stream({
|
|
400
|
+
"metric": "temperature",
|
|
401
|
+
"callback": lambda data: print(data),
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
# Filter by hierarchy path (supports * and > wildcards)
|
|
405
|
+
await group.stream({
|
|
406
|
+
"heirarchy": "building_1.*.zone_a",
|
|
407
|
+
"callback": lambda data: print(data),
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
await group.off()
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Notifications
|
|
414
|
+
|
|
415
|
+
Create webhook or email notification channels for alerts.
|
|
416
|
+
|
|
417
|
+
```python
|
|
418
|
+
# Webhook
|
|
419
|
+
notif = await app.notification.create({
|
|
420
|
+
"name": "ops-webhook",
|
|
421
|
+
"type": "WEBHOOK",
|
|
422
|
+
"config": {"endpoint": "https://hooks.example.com/alerts"},
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
# Email
|
|
426
|
+
notif = await app.notification.create({
|
|
427
|
+
"name": "ops-email",
|
|
428
|
+
"type": "EMAIL",
|
|
429
|
+
"config": {
|
|
430
|
+
"recipients": ["ops@example.com"],
|
|
431
|
+
"subject": "Alert Notification",
|
|
432
|
+
"template": "Alert {{alert_name}} fired on {{device_ident}}",
|
|
433
|
+
},
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
# Update, delete, list, get
|
|
437
|
+
notif = await app.notification.update({
|
|
438
|
+
"name": "ops-webhook",
|
|
439
|
+
"type": "WEBHOOK",
|
|
440
|
+
"config": {"endpoint": "https://new-url.com"},
|
|
441
|
+
})
|
|
442
|
+
await app.notification.delete(notif["id"])
|
|
443
|
+
notifs = await app.notification.list()
|
|
444
|
+
notif = await app.notification.get("<notif_id>")
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## Offline Behavior
|
|
448
|
+
|
|
449
|
+
- **Commands**: Buffered in memory while disconnected and flushed automatically on reconnect.
|
|
450
|
+
- **Subscriptions**: All active telemetry, event, presence, alert, and group stream subscriptions are automatically restored on reconnect.
|
|
451
|
+
- **Ephemeral Alerts**: Alert state events (fire, resolved, ack) are buffered and published on reconnect.
|
|
452
|
+
|
|
453
|
+
## Error Handling
|
|
454
|
+
|
|
455
|
+
The SDK raises standard Python exceptions:
|
|
456
|
+
|
|
457
|
+
- `ValueError` — Invalid arguments, missing required fields, schema validation failures
|
|
458
|
+
- `RuntimeError` — Operations attempted while disconnected
|
|
459
|
+
|
|
460
|
+
```python
|
|
461
|
+
try:
|
|
462
|
+
await app.telemetry.stream({
|
|
463
|
+
"device_ident": "sensor-1",
|
|
464
|
+
"metric": "nonexistent",
|
|
465
|
+
"callback": lambda d: None,
|
|
466
|
+
})
|
|
467
|
+
except ValueError as e:
|
|
468
|
+
print(f"Validation error: {e}")
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## License
|
|
472
|
+
|
|
473
|
+
Apache-2.0
|