Skip to main content

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 the send_message method.

send

Send a message to a device. See FCM documentation for more details.

Parameters

  • data: dict - Data to send to FCM service.

Returns

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

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

Metadata

Release files for fcm-adapter 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fcm-adapter 0.1.2
File Size Uploaded
fcm_adapter-0.1.2.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fcm-adapter 0.1.2
File Interpreter ABI Platform
fcm_adapter-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / fcm_adapter-0.1.2.tar.gz

Download URL fcm_adapter-0.1.2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
efc162be86285ba1b20ea9f69d11773283e5c6d3588a9e69143c0916e3897980
BLAKE2b-256 checksum
How to use checksums
e9f2b30cc0f03421fdd008e332e103d9f3985bba3ed589145c2d82b5571df5f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.3 Darwin/22.2.0

Release files / fcm_adapter-0.1.2-py3-none-any.whl

Download URL fcm_adapter-0.1.2-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa9a6aa3bf597c76da694b72ef8a8a77b1c53380d8ab1202c66da89f3f5af1b0
BLAKE2b-256 checksum
How to use checksums
1753a8df676a96379629c1d1b097af8378527496c0914afe7206cf0f8533a2ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.3 Darwin/22.2.0

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page