/PyFCM

Python client for FCM - Firebase Cloud Messaging (Android & iOS)

Primary LanguagePythonOtherNOASSERTION

PyFCM

Python client for FCM - Firebase Cloud Messaging (Android & iOS)

Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features. GCM users are strongly recommended to upgrade to FCM.

Using FCM, you can notify a client app that new email or other data is available to sync. You can send notifications to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.

For more information, visit: https://firebase.google.com/docs/cloud-messaging/

Quickstart

Install using pip:

pip install pyfcm

OR

pip install git+https://github.com/olucurious/PyFCM.git

PyFCM supports Android and iOS.

Examples

Send notifications using the FCMNotification class:

Send a data message.

# With FCM, you can send two types of messages to clients:
# 1. Notification messages, sometimes thought of as "display messages."
# 2. Data messages, which are handled by the client app.

# Client app is responsible for processing data messages. Data messages have only custom key-value pairs. (Python dict)
# Data messages let developers send up to 4KB of custom key-value pairs.

# Sending a notification with data message payload
data_message = {
    "Nick" : "Mario",
    "body" : "great match!",
    "Room" : "PortugalVSDenmark"
}
# To multiple devices
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_body=message_body, data_message=data_message)
# To a single device
result = push_service.notify_single_device(registration_id=registration_id, message_body=message_body, data_message=data_message)

# Sending a data message only payload, do NOT include message_body
# To multiple devices
result = push_service.notify_multiple_devices(registration_ids=registration_ids, data_message=data_message)
# To a single device
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message)

# Use notification messages when you want FCM to handle displaying a notification on your app's behalf.
# Use data messages when you just want to process the messages only in your app.
# PyFCM can send a message including both notification and data payloads.
# In such cases, FCM handles displaying the notification payload, and the client app handles the data payload.

Send a low priority message.

Sending a message to a topic.

Other argument options

:

collapse_key (str, optional): Identifier for a group of messages
    that can be collapsed so that only the last message gets sent
    when delivery can be resumed. Defaults to `None`.
delay_while_idle (bool, optional): If `True` indicates that the
    message should not be sent until the device becomes active.
time_to_live (int, optional): How long (in seconds) the message
    should be kept in FCM storage if the device is offline. The
    maximum time to live supported is 4 weeks. Defaults to ``None``
    which uses the FCM default of 4 weeks.
low_priority (boolean, optional): Whether to send notification with
    the low priority flag. Defaults to `False`.
restricted_package_name (str, optional): Package name of the
    application where the registration IDs must match in order to
    receive the message. Defaults to `None`.
dry_run (bool, optional): If `True` no message will be sent but
    request will be tested.

Access response data.

License

The MIT License (MIT). Please see LICENSE.rst for more information.

Copyright (c) 2015 Emmanuel Adegbite

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.