A wrapper library for using firebase-admin-python to send data and notification messages.
Project description
push-den
A wrapper library for sending push notifications through Firebase Cloud Messaging (FCM) and Apple Push Notification service (APNs).
Requirements
- Python 3.8+
Installation
pip install push-den
For local build/install:
python -m build
pip install dist/push_den-<version>-py3-none-any.whl
Configuration
Create a .env file from .env.example and set the required values.
Minimal runtime configuration in code:
import os
from push_den.processor import NotificationProcessor
fcm_credential_path = os.getenv("FIREBASE_ADMIN_PRIVATE_KEY")
apns = {
"APNS_AUTH_KEY": os.getenv("APNS_AUTH_KEY"),
"TEAM_ID": os.getenv("TEAM_ID"),
"ALGORITHM": os.getenv("ALGORITHM", "ES256"),
"APNS_KEY_ID": os.getenv("APNS_KEY_ID"),
"BUNDLE_ID": os.getenv("BUNDLE_ID"),
"IOS_HTTP_URL": os.getenv("IOS_HTTP_URL", "api.push.apple.com:443"),
"IOS_HTTP_SANDBOX_URL": os.getenv("IOS_HTTP_SANDBOX_URL"),
}
notification_processor = NotificationProcessor(fcm=fcm_credential_path, apns=apns)
Usage
FCM single notification (single)
payload = {
"type": "fcm",
"send_mode": "single",
"device_token": "<fcm-device-token>",
"notification": {
"message_title": "Hello",
"message_body": "Welcome",
"priority": "high",
"ttl": 60,
},
}
response = notification_processor.process_message(payload)
print(response.message_id, response.success, response.exception)
FCM multicast data message (multiple_data)
payload = {
"type": "fcm",
"send_mode": "multiple_data",
"device_tokens": ["<token-1>", "<token-2>"],
"notification": {
"data": {
"event": "order.created",
"order_id": "1001",
},
"priority": "normal",
"ttl": 120,
},
}
response = notification_processor.process_message(payload)
print(response.success_count, response.failure_count)
APNs mutable alert (alert)
payload = {
"type": "apns",
"send_mode": "alert",
"device_token": "<apns-device-token>",
"notification": {
"title": "New Message",
"data": "You have a new notification",
"ttl": 3600,
},
}
response = notification_processor.process_message(payload)
print(response.status, response.read().decode("utf-8"))
APNs immutable alert (immutable_alert)
payload = {
"type": "apns",
"send_mode": "immutable_alert",
"device_tokens": ["<token-1>", "<token-2>"],
"notification": {
"title": "Account Notice",
"message_body": "Your profile has been updated.",
"ttl": 3600,
},
}
response = notification_processor.process_message(payload)
print(response)
Payload size helpers
You can estimate payload size before sending:
from push_den.notificationfactory.fcm_factory.fcm_notification import FcmNotification
from push_den.notificationfactory.apns_factory.apns_notification import ApnsNotification
fcm_size = FcmNotification.calculate_payload_size(payload)
apns_size = ApnsNotification.calculate_payload_size(payload)
print(fcm_size)
print(apns_size)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file push_den-1.3.3.tar.gz.
File metadata
- Download URL: push_den-1.3.3.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39c0cb96c47144f750a99d144108d3c2a0cac805e5c37ff98d1bc9fe3a64d2ce
|
|
| MD5 |
1e0432a217be9074266dd8b8a013d40b
|
|
| BLAKE2b-256 |
4b3f65629a002459c733883d5d10b2ac51c0a2836fa770041147a4bc37026b3f
|
Provenance
The following attestation bundles were made for push_den-1.3.3.tar.gz:
Publisher:
python-publish.yml on amtyf/push-den
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
push_den-1.3.3.tar.gz -
Subject digest:
39c0cb96c47144f750a99d144108d3c2a0cac805e5c37ff98d1bc9fe3a64d2ce - Sigstore transparency entry: 1566639740
- Sigstore integration time:
-
Permalink:
amtyf/push-den@b08705af52b23874b2abb19bc206d0f9d2c652d3 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/amtyf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b08705af52b23874b2abb19bc206d0f9d2c652d3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file push_den-1.3.3-py3-none-any.whl.
File metadata
- Download URL: push_den-1.3.3-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8200b914ccda9c8732a565cb6e9e357855a5703d7fc5177da316c8a3720f8ef
|
|
| MD5 |
3118b99d15e4aa4a82a7f1d024431021
|
|
| BLAKE2b-256 |
79b7cadd789842f9b0b42e4a9aa45b95891a55218a7c4e4522beeea73aa39903
|
Provenance
The following attestation bundles were made for push_den-1.3.3-py3-none-any.whl:
Publisher:
python-publish.yml on amtyf/push-den
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
push_den-1.3.3-py3-none-any.whl -
Subject digest:
c8200b914ccda9c8732a565cb6e9e357855a5703d7fc5177da316c8a3720f8ef - Sigstore transparency entry: 1566639794
- Sigstore integration time:
-
Permalink:
amtyf/push-den@b08705af52b23874b2abb19bc206d0f9d2c652d3 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/amtyf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b08705af52b23874b2abb19bc206d0f9d2c652d3 -
Trigger Event:
push
-
Statement type: