Skip to main content

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

Project description

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.

Quickstart

Install using pip:

pip install pyfcm

PyFCM supports Android and iOS.

Example

Send notifications using the FCMNotification class:

# Send to single device.
from pyfcm import FCMNotification

push_service = FCMNotification(api_key="<api-key>")

registration_id = "<device registration_id>"
message = "Hi john, your Uber driver is around"
result = push_service.notify_single_device(registration_id=registration_id, message_body=message)

# Send to multiple devices by passing a list of ids.
registration_ids = ["<device registration_id 1>", "<device registration_id 2>", ...]
message = "Have you checked for cool Uber drivers around lately?"
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_body=message)

print result

Send a low priority message.

# The default is low_priority == False
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_body=message, low_priority=True)

Access response data.

# Response from FCM Server.
print result['multicast_id'] #Unique ID (number) identifying the multicast message.
print result['success'] #Number of messages that were processed without an error.
print result['failure'] #Number of messages that could not be processed.
print result['canonical_ids'] #Number of results that contain a canonical registration token.
print result['results'] #Array of objects representing the status of the messages processed.
#The result objects are listed in the same order as the request (i.e., for each registration ID in the request, its result is listed in the same index in the response).
#message_id: String specifying a unique ID for each successfully processed message.
#registration_id: Optional string specifying the canonical registration token for the client app that the message was processed and sent to. Sender should use this value as the registration token for future requests. Otherwise, the messages might be rejected.
#error: String specifying the error that occurred when processing the message for the recipient

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfcm-0.0.1.tar.gz (6.4 kB view details)

Uploaded Source

File details

Details for the file pyfcm-0.0.1.tar.gz.

File metadata

  • Download URL: pyfcm-0.0.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyfcm-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4ec4515d4831a6ef212d2c6b2e4348f2cea80ec72c39cbf2a12e55c940be7bcf
MD5 25edd922f50043f83f8b1a2fa8ce8893
BLAKE2b-256 e7fa07d562476d099c865056025107c7c2c558058603df0bbae78800263bfbdd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page