opush-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.
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ htmlcov/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 All Right LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,370 @@
1
+ Metadata-Version: 2.5
2
+ Name: opush-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for Opush push notifications, monitors, and alerts
5
+ Project-URL: Homepage, https://opu.sh
6
+ Project-URL: Documentation, https://opu.sh/docs
7
+ Project-URL: Source, https://github.com/all-right-LLC/opush-python
8
+ Project-URL: Issues, https://github.com/all-right-LLC/opush-python/issues
9
+ Author-email: All Right LLC <support@allright.dev>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: alerts,apns,heartbeat,home-assistant,notifications,opush,push
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Communications
24
+ Classifier: Topic :: System :: Monitoring
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: httpx>=0.25
28
+ Requires-Dist: typing-extensions>=4.6; python_version < '3.11'
29
+ Provides-Extra: crypto
30
+ Requires-Dist: cryptography>=42; extra == 'crypto'
31
+ Requires-Dist: pyhpke>=0.6; extra == 'crypto'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # Opush Python SDK
35
+
36
+ The official Python SDK for [Opush](https://opu.sh): push notifications to your iPhone, Apple Watch, Mac, and Android devices, plus questions, escalating alerts, live progress cards, and heartbeat check-ins.
37
+
38
+ - Sync (`Opush`) and async (`AsyncOpush`) clients built on [httpx](https://www.python-httpx.org/)
39
+ - Fully typed (`py.typed`), Python 3.10+
40
+ - Shared-key (AES) and end-to-end (HPKE) encryption
41
+ - Works with the hosted service at `https://opu.sh` and with enterprise servers
42
+
43
+ Made by All Right LLC. Full documentation: [opu.sh/docs](https://opu.sh/docs).
44
+
45
+ ## Install
46
+
47
+ ```bash
48
+ pip install opush-sdk
49
+ ```
50
+
51
+ The package is called `opush-sdk` on PyPI and is imported as `opush`. For encryption, install the `crypto` extra:
52
+
53
+ ```bash
54
+ pip install 'opush-sdk[crypto]'
55
+ ```
56
+
57
+ ## Quick start
58
+
59
+ Find your push URL in the Opush app. The key is the 22-character part after `https://opu.sh/`. You can pass either the key or the whole URL.
60
+
61
+ ```python
62
+ from opush import Opush
63
+
64
+ with Opush("YOUR_KEY") as client:
65
+ client.push("42 GB in 12 minutes", title="Backup done")
66
+ ```
67
+
68
+ Async:
69
+
70
+ ```python
71
+ import asyncio
72
+ from opush import AsyncOpush
73
+
74
+
75
+ async def main() -> None:
76
+ async with AsyncOpush("YOUR_KEY") as client:
77
+ await client.push("42 GB in 12 minutes", title="Backup done")
78
+
79
+
80
+ asyncio.run(main())
81
+ ```
82
+
83
+ Every method of `Opush` has the same name and arguments on `AsyncOpush`, as a coroutine. Close an async client with `await client.aclose()` or use `async with`.
84
+
85
+ ## Creating a client
86
+
87
+ ```python
88
+ Opush("YOUR_KEY") # one device
89
+ Opush("https://opu.sh/YOUR_KEY") # the full push URL works too
90
+ Opush(keys=["KEY_ONE", "KEY_TWO"]) # several devices
91
+ Opush(channel="CHANNEL_KEY") # a team channel
92
+ Opush("https://opu.sh/c/CHANNEL_KEY") # channel URL
93
+ Opush() # reads OPUSH_KEY, OPUSH_CHANNEL, OPUSH_SERVER
94
+ ```
95
+
96
+ | Argument | Description |
97
+ |---|---|
98
+ | `key` | A device key or push URL. Defaults to `OPUSH_KEY`. |
99
+ | `keys` | Several device keys. Each push goes to all of them. |
100
+ | `channel` | A team channel key or URL. Defaults to `OPUSH_CHANNEL`. |
101
+ | `server` | Server URL, including the path prefix of an enterprise server. Defaults to the server in the push URL, then `OPUSH_SERVER`, then `https://opu.sh`. |
102
+ | `basic_auth` | `("user", "password")` or `"user:password"`, for enterprise servers with Basic Auth. |
103
+ | `timeout` | Request timeout in seconds. Default `30`. |
104
+ | `retries` | Retries after `429`, `503`, or a network error, following `Retry-After`. Default `0`. |
105
+ | `encrypt` | Default encryption for every push. See [Encryption](#encryption). |
106
+ | `http_client` | An existing `httpx.Client` (or `httpx.AsyncClient`) to reuse. You stay responsible for closing it. |
107
+
108
+ Retries are off by default because a push that timed out may still have been delivered, and retrying could deliver it twice. Use `id=` on your pushes if you turn retries on: a push with the same `id` replaces the earlier one.
109
+
110
+ ## Pushes
111
+
112
+ ```python
113
+ client.push(
114
+ "api v2.4.1 is live",
115
+ title="Deploy finished",
116
+ subtitle="production",
117
+ group="deploys",
118
+ level="timeSensitive",
119
+ sound="chime",
120
+ url="https://example.com/deploys/42",
121
+ icon="https://example.com/icon.png",
122
+ )
123
+ ```
124
+
125
+ `push()` takes the [push parameters](https://opu.sh/docs/push/parameters) as keyword arguments:
126
+
127
+ | Argument | Sent as | Notes |
128
+ |---|---|---|
129
+ | `body` (or the first positional argument), `title`, `subtitle`, `markdown` | same name | `markdown` replaces `body` in the app |
130
+ | `icon`, `image` | same name | URLs |
131
+ | `group`, `badge`, `sound`, `voice` | same name | |
132
+ | `level` | `level` | `"active"`, `"timeSensitive"`, `"passive"`, `"critical"` |
133
+ | `volume` | `volume` | 0 to 10, for `critical` |
134
+ | `call` | `call` | `True` repeats the sound for about 30 seconds, `"voice"` rings like a phone call |
135
+ | `url`, `copy`, `action` | same name | |
136
+ | `buttons` | `button1`, `button1_url`, … | Up to two `Button(title, url, method=None, style=None)` or dicts |
137
+ | `id` | `id` | Pushes with the same `id` replace each other |
138
+ | `archive` | `isArchive` | `True` saves to the inbox, `False` doesn't |
139
+ | `ttl` | `ttl` | Seconds or a `timedelta` |
140
+ | `at`, `delay`, `repeat`, `tz` | same name | `at` takes a string, Unix seconds, or a `datetime`; `delay` takes seconds or a `timedelta` |
141
+ | `sms`, `phone` | `1` | Text or call your verified numbers |
142
+ | `escalate`, `escalate_after`, `callback_url` | same name | `escalate=True` or a list such as `["push", "sms"]` |
143
+ | `attachments` | multipart `file` | Up to 5 files |
144
+ | `oncall` | `oncall=1` | Channels only |
145
+ | `encrypt` | `ciphertext`/`iv` or `sealed` | Overrides the client default; `None` turns it off for one push |
146
+ | `extra` | as given | Any other parameter, for forward compatibility |
147
+
148
+ The result is a `PushResult`:
149
+
150
+ ```python
151
+ result = client.push("Hello")
152
+ result.message # "success", "scheduled", or "queued: …"
153
+ result.schedule # Schedule(id, fire_at, repeat) for scheduled pushes
154
+ result.escalation # Escalation(alert_id, steps, …) when you used escalate
155
+ result.results # list[DeviceResult] when pushing to several keys
156
+ result.raw # the whole response
157
+ ```
158
+
159
+ ### Buttons
160
+
161
+ ```python
162
+ from opush import Button
163
+
164
+ client.push(
165
+ "Approve the release?",
166
+ buttons=[
167
+ Button("Approve", "https://example.com/approve", method="POST"),
168
+ Button("Reject", "https://example.com/reject", method="POST", style="destructive"),
169
+ ],
170
+ )
171
+ ```
172
+
173
+ ### Scheduling
174
+
175
+ ```python
176
+ from datetime import datetime, timedelta, timezone
177
+
178
+ client.push("Starts in 10 minutes", title="Standup", at="09:50", repeat="weekdays", id="standup")
179
+ client.push("Drink water", delay=timedelta(hours=1), id="water")
180
+ client.push("Report", at=datetime(2026, 12, 24, 9, tzinfo=timezone.utc))
181
+ client.recall("water") # cancels the scheduled push
182
+ ```
183
+
184
+ ### Attachments
185
+
186
+ Attachments can be file paths, `bytes`, open binary files, or `(filename, bytes)` / `(filename, bytes, content_type)` tuples:
187
+
188
+ ```python
189
+ client.push(
190
+ "Nightly report attached",
191
+ attachments=["report.pdf", ("errors.log", log_bytes, "text/plain")],
192
+ )
193
+ ```
194
+
195
+ Attachments work with one device key or a channel, not with `keys=[...]`. Plan limits on size apply.
196
+
197
+ ### Recall
198
+
199
+ ```python
200
+ client.push("Building…", id="build-7")
201
+ client.recall("build-7")
202
+ ```
203
+
204
+ Recalling also cancels a pending schedule and an escalating alert with that `id`.
205
+
206
+ ### Several devices and channels
207
+
208
+ ```python
209
+ team = Opush(keys=["KEY_ONE", "KEY_TWO"])
210
+ result = team.push("Release v2.0 is out")
211
+ for device in result.results or []:
212
+ print(device.device_key, device.ok, device.message)
213
+
214
+ ops = Opush(channel="CHANNEL_KEY")
215
+ ops.push("Database is down", level="timeSensitive", oncall=True, escalate=True)
216
+ ```
217
+
218
+ ## Live progress
219
+
220
+ ```python
221
+ client.progress.start("deploy-7", "Deploy api", status="Building", progress=10)
222
+ client.progress.update("deploy-7", status="Uploading", progress=60)
223
+ client.progress.end("deploy-7", status="Done")
224
+ # or: client.progress.end("deploy-7", state="failed", status="Tests failed")
225
+ ```
226
+
227
+ Progress cards are never encrypted. See [Live progress](https://opu.sh/docs/push/live-progress).
228
+
229
+ ## Questions
230
+
231
+ ```python
232
+ question = client.ask(
233
+ "Merge PR #42?",
234
+ options=["Merge", "Close"],
235
+ allow_text=True,
236
+ timeout=3600,
237
+ )
238
+ state = question.wait(timeout=300) # polls until answered, expired, or cancelled
239
+ if state.answered and state.answer:
240
+ print(state.answer.option, state.answer.text)
241
+ else:
242
+ question.cancel()
243
+ ```
244
+
245
+ `client.get_question(question_id)` and `client.cancel_question(question_id)` work with a stored question ID or `answer_url`. See [Ask endpoints](https://opu.sh/docs/api/ask).
246
+
247
+ ## Escalating alerts
248
+
249
+ ```python
250
+ result = client.push("Database down", escalate=["voice", "sms", "phone"], escalate_after=3, voice="down")
251
+ alert_id = result.escalation.alert_id
252
+
253
+ alert = client.alerts.get(alert_id) # status: active, acked, done, cancelled
254
+ client.alerts.cancel(alert_id)
255
+ ```
256
+
257
+ `alerts.get` and `alerts.cancel` also accept the `status_url`. See [Alert endpoints](https://opu.sh/docs/api/alerts).
258
+
259
+ ## Callback signatures
260
+
261
+ Questions and alerts with `callback_url` POST a signed body to your server. Check it with the `callback_secret` from the original response:
262
+
263
+ ```python
264
+ from opush import verify_signature
265
+
266
+ ok = verify_signature(raw_body, request.headers["X-Opush-Signature"], callback_secret)
267
+ ```
268
+
269
+ Pass the raw body bytes, before any JSON parsing. The comparison runs in constant time.
270
+
271
+ ## Heartbeats
272
+
273
+ ```python
274
+ hb = client.heartbeat("CHECK_ID") # or the full URL https://opu.sh/hb/CHECK_ID
275
+ hb.start()
276
+ try:
277
+ run_backup()
278
+ except Exception as exc:
279
+ hb.fail(str(exc)) # the first 1,000 characters show in the push
280
+ raise
281
+ else:
282
+ hb.ok()
283
+ ```
284
+
285
+ Heartbeats don't need a push key: `Opush().heartbeat("https://opu.sh/hb/CHECK_ID").ok()`. See [Heartbeat endpoints](https://opu.sh/docs/api/heartbeats).
286
+
287
+ ## Encryption
288
+
289
+ Install `opush-sdk[crypto]` first. Encryption covers `title`, `subtitle`, `body`, `markdown`, `url`, `copy`, `icon`, `image`, `action`, and button fields. Everything the server needs to deliver the push (`id`, `level`, `group`, `sound`, schedules, calls, texts, escalation) stays outside.
290
+
291
+ ### Shared key (AES)
292
+
293
+ Use the algorithm and key from the app's encryption settings. GCM and CBC with 128, 192, or 256-bit keys are supported. Each push gets a new random IV.
294
+
295
+ ```python
296
+ from opush import AesEncryption, Opush
297
+
298
+ client = Opush("YOUR_KEY", encrypt=AesEncryption("your-32-character-key-goes-here!", "aes-256-gcm"))
299
+ client.push("381920", title="Login code")
300
+ ```
301
+
302
+ ### End-to-end (HPKE)
303
+
304
+ Create a key pair in the app and copy the public key (base64 of the 65-byte point, or PEM). Only the device holding the private key can read the push.
305
+
306
+ ```python
307
+ from opush import HpkeEncryption
308
+
309
+ client.push("381920", title="Login code", encrypt=HpkeEncryption("BASE64_PUBLIC_KEY"))
310
+ ```
311
+
312
+ The suite is DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-256-GCM with `info = "opush v1"`. See [Encryption](https://opu.sh/docs/push/encryption).
313
+
314
+ ## Errors
315
+
316
+ Every failed request raises `OpushError`:
317
+
318
+ ```python
319
+ from opush import OpushError
320
+
321
+ try:
322
+ client.push("Hello")
323
+ except OpushError as err:
324
+ print(err.status, err.message, err.code, err.retry_after)
325
+ ```
326
+
327
+ | Attribute | Description |
328
+ |---|---|
329
+ | `status` | HTTP status, or `None` for network errors |
330
+ | `message` | The server's message |
331
+ | `code` | Machine-readable code such as `not_found` from the ask and alert endpoints. `None` for push endpoints. |
332
+ | `retry_after` | Seconds from `Retry-After` on `429` and `503` |
333
+
334
+ Invalid arguments (for example three buttons, or attachments with several keys) raise `ValueError` or `TypeError` before anything is sent.
335
+
336
+ ## Enterprise servers
337
+
338
+ Pass the push URL of your server, or set `server` explicitly. Path prefixes and Basic Auth are supported:
339
+
340
+ ```python
341
+ client = Opush("https://push.example.com/api/YOUR_KEY", basic_auth=("user", "password"))
342
+ # same as
343
+ client = Opush("YOUR_KEY", server="https://push.example.com/api", basic_auth="user:password")
344
+ ```
345
+
346
+ ## Home Assistant and other async apps
347
+
348
+ `AsyncOpush` never blocks the event loop on network I/O. Reuse a shared client instead of creating one per call:
349
+
350
+ ```python
351
+ from homeassistant.helpers.httpx_client import get_async_client
352
+
353
+ client = AsyncOpush(key, http_client=get_async_client(hass))
354
+ ```
355
+
356
+ Reading attachment files from disk happens synchronously when the request is built. In an event loop, pass `bytes` or read the files in an executor first.
357
+
358
+ ## Development
359
+
360
+ ```bash
361
+ python -m venv .venv
362
+ .venv/bin/pip install -e '.[crypto]' pytest pytest-asyncio respx ruff mypy build
363
+ .venv/bin/pytest
364
+ .venv/bin/ruff check . && .venv/bin/ruff format --check .
365
+ .venv/bin/mypy
366
+ ```
367
+
368
+ ## License
369
+
370
+ MIT © 2026 All Right LLC