Push Notifications¶
Web Push notification subscription management.
This module handles push notification subscriptions from client browsers using the Web Push protocol (RFC 8030). Subscriptions include endpoint URLs and encryption keys for secure message delivery.
Warning
Subscriptions are currently stored in-memory and will be lost on restart. Production deployment should use PostgreSQL or Redis for persistence.
Example
Client subscribes: POST /push/subscribe {"endpoint": "https://...", "keys": {"p256dh": "...", "auth": "..."}}
SUBSCRIPTIONS
module-attribute
¶
SUBSCRIPTIONS = []
List of active push subscriptions. WARNING: In-memory storage only.
PushKeys ¶
Bases: BaseModel
Encryption keys for Web Push messages.
Attributes:
| Name | Type | Description |
|---|---|---|
p256dh |
str
|
Public key for message encryption (Base64). |
auth |
str
|
Authentication secret for message encryption (Base64). |
Source code in app/push.py
29 30 31 32 33 34 35 36 37 38 | |
PushSubscription ¶
Bases: BaseModel
Web Push subscription from a client browser.
Attributes:
| Name | Type | Description |
|---|---|---|
endpoint |
str
|
Push service endpoint URL (browser-specific). |
expirationTime |
int | None
|
Optional subscription expiry timestamp. |
keys |
PushKeys
|
Encryption keys for secure message delivery. |
Source code in app/push.py
41 42 43 44 45 46 47 48 49 50 51 52 | |
subscribe ¶
subscribe(sub)
Register a new push notification subscription.
De-duplicates by endpoint URL to prevent duplicate subscriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub
|
PushSubscription
|
Push subscription from browser's Push API. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, bool | int]
|
Status with ok=True and total subscription count. |
Source code in app/push.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |