Async Firebase Client - a Python asyncio client to interact with Firebase Cloud Messaging in an easy way.
Project description
async-firebase is a lightweight asynchronous client to interact with Firebase Cloud Messaging for sending push notification to Android and iOS devices
- Free software: MIT license
- Requires: Python 3.7+
Features
- Extremely lightweight and does not rely on
firebase-admin
which is hefty - Send push notifications to Android and iOS devices
- Send Multicast push notification to Android and iOS devices
- Send Web push notifications
- Set TTL (time to live) for notifications
- Set priority for notifications
- Set collapse-key for notifications
- Dry-run mode for testing purpose
Installation
$ pip install async-firebase
Getting started
To send push notification to Android:
import asyncio
from async_firebase import AsyncFirebaseClient
async def main():
client = AsyncFirebaseClient()
client.creds_from_service_account_file("secret-store/mobile-app-79225efac4bb.json")
# or using dictionary object
# client.creds_from_service_account_info({...}})
device_token = "..."
android_config = client.build_android_config(
priority="high",
ttl=2419200,
collapse_key="push",
data={"discount": "15%", "key_1": "value_1", "timestamp": "2021-02-24T12:00:15"},
title="Store Changes",
body="Recent store changes",
)
response = await client.push(device_token=device_token, android=android_config)
print(response.success, response.message_id)
if __name__ == "__main__":
asyncio.run(main())
To send push notification to iOS:
import asyncio
from async_firebase import AsyncFirebaseClient
async def main():
client = AsyncFirebaseClient()
client.creds_from_service_account_file("secret-store/mobile-app-79225efac4bb.json")
# or using dictionary object
# client.creds_from_service_account_info({...}})
device_token = "..."
apns_config = client.build_apns_config(
priority="normal",
ttl=2419200,
apns_topic="store-updated",
collapse_key="push",
title="Store Changes",
alert="Recent store changes",
badge=1,
category="test-category",
custom_data={"discount": "15%", "key_1": "value_1", "timestamp": "2021-02-24T12:00:15"}
)
response = await client.push(device_token=device_token, apns=apns_config)
print(response.success)
if __name__ == "__main__":
asyncio.run(main())
This prints:
"projects/mobile-app/messages/0:2367799010922733%7606eb557606ebff"
To manual construct message:
import asyncio
from datetime import datetime
from async_firebase.messages import APNSConfig, APNSPayload, ApsAlert, Aps
from async_firebase import AsyncFirebaseClient
async def main():
apns_config = APNSConfig(**{
"headers": {
"apns-expiration": str(int(datetime.utcnow().timestamp()) + 7200),
"apns-priority": "10",
"apns-topic": "test-topic",
"apns-collapse-id": "something",
},
"payload": APNSPayload(**{
"aps": Aps(**{
"alert": ApsAlert(title="some-title", body="alert-message"),
"badge": 0,
"sound": "default",
"content_available": True,
"category": "some-category",
"mutable_content": False,
"custom_data": {
"link": "https://link-to-somewhere.com",
"ticket_id": "YXZ-655512",
},
})
})
})
device_token = "..."
client = AsyncFirebaseClient()
client.creds_from_service_account_info({...})
response = await client.push(device_token=device_token, apns=apns_config)
print(response.success)
if __name__ == "__main__":
asyncio.run(main())
License
async-firebase
is offered under the MIT license.
Source code
The latest developer version is available in a GitHub repository: https://github.com/healthjoy/async-firebase
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
async_firebase-2.7.0.tar.gz
(21.8 kB
view details)
Built Distribution
File details
Details for the file async_firebase-2.7.0.tar.gz
.
File metadata
- Download URL: async_firebase-2.7.0.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1035-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a9a823ad6a7382e6e3080eb4cf967ded9e17c2a202eabe270cec636f6193a8f |
|
MD5 | 4a1ddeba2ce26336eb516103acaa3532 |
|
BLAKE2b-256 | 00b561c24fe5356db01b8594d51f64f9d038d303732075d645c69ee2e1abac92 |
File details
Details for the file async_firebase-2.7.0-py3-none-any.whl
.
File metadata
- Download URL: async_firebase-2.7.0-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1035-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cc6217d6db41193cebbe6ed5e64e34e0af14c6ee2c0893b1037755f7b7765e1 |
|
MD5 | 661bde677180ebc43386150b29e1a827 |
|
BLAKE2b-256 | a9127a72aa052f764dad057ba0502a5ea2d9b323d7943ccc014d19809a833f11 |