Firebase Cloud Messaging Adapter
Project description
FCM Adapter
This is a simple adapter for the FCM (Firebase Cloud Messaging) service.
Installation
pip install fcm_adapter
poetry add fcm_adapter
Usage
from fcm_adapter import FCMAdapter
import json
async def main(token: str):
with open('key.json') as f:
key = json.load(f)
fcm_adapter = FCMAdapter(key)
await fcm_adapter.send_message(
{
"token": token,
"notification": {"title": "Hello World"},
}
)
FCMAdapter initialization
Parameters
key: dict- Google key. You can get it from the Firebase Console. Documentation here.client: Union[httpx.AsyncClient, None] = None- httpx.AsyncClient instance. If not provided, a new instance will be created.send_message_url: Union[str, None] = None- FCM send message url. If not provided, the default value will be used.validate_only: bool = False- Flag for testing the request without actually delivering the message. Works only with thesend_messagemethod.
send
Send a message to a device. See FCM documentation for more details.
Parameters
data: dict- Data to send to FCM service.
Returns
- Response from FCM service. See FCM documentation for more details.
Example
from fcm_adapter import FCMAdapter
async def main(fcm_adapter: FCMAdapter, token: str):
response = await fcm_adapter.send(
{
"validate_only": False,
"message": {
"token": token,
"notification": {"title": "Hello World"},
},
}
)
send_message
Send a message to a device. The function is a wrapper around the send method,
but it expects to receive only inner message data.
If fcm_adapter.validate_only is set to True,
the request to FCM will be sent with "validate_only": true.
Parameters
message: dict- Message data to send to FCM service.
Returns
- Response from FCM service. See FCM documentation for more details.
Example
from fcm_adapter import FCMAdapter
async def main(fcm_adapter: FCMAdapter, token: str):
response = await fcm_adapter.send_message(
{
"token": token,
"notification": {"title": "Hello World"},
}
)
Development
First, install poetry.
Then, install dependencies:
poetry install
Formatting
poetry run black .
Testing
poetry run pytest
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 fcm_adapter-0.1.2.tar.gz.
File metadata
- Download URL: fcm_adapter-0.1.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.3 Darwin/22.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efc162be86285ba1b20ea9f69d11773283e5c6d3588a9e69143c0916e3897980
|
|
| MD5 |
b12388b60785682d60fbc97bbfda1074
|
|
| BLAKE2b-256 |
e9f2b30cc0f03421fdd008e332e103d9f3985bba3ed589145c2d82b5571df5f1
|
File details
Details for the file fcm_adapter-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fcm_adapter-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.3 Darwin/22.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa9a6aa3bf597c76da694b72ef8a8a77b1c53380d8ab1202c66da89f3f5af1b0
|
|
| MD5 |
363bc648e203b98c8672c7c1e56dd01f
|
|
| BLAKE2b-256 |
1753a8df676a96379629c1d1b097af8378527496c0914afe7206cf0f8533a2ca
|