PyFCM is an active Python client library for Firebase Cloud Messaging (FCM), currently at version 2.1.0. It provides a convenient interface for sending push notifications and data messages to Android, iOS, and web clients. The library's release cadence is tied to significant FCM API changes, ensuring compatibility with the latest Firebase services.
pip install pyfcmVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to send both notification and data messages to a single FCM device using PyFCM's `FCMNotification` class. It leverages the FCM v1 API, requiring a Firebase service account JSON file (specified via `GOOGLE_APPLICATION_CREDENTIALS` environment variable) and your Firebase project ID for authentication. The `notify()` method is the unified entry point for sending messages.
Update your code to use the new `notify()` method and configure `FCMNotification` with `service_account_file` and `project_id` (or `credentials`). Consult the `README.md` for `2.x` for updated usage patterns. Ensure your Firebase project uses the FCM v1 API and relevant permissions.
Review the `README.md` or release notes for your specific `1.x` version to understand the exact response structure and adjust parsing logic accordingly.
Obtain a service account JSON key file from your Firebase project settings (Project settings -> Service accounts -> Generate new private key). Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of this file and pass your `project_id` to `FCMNotification` initializer. Ensure the associated service account has the necessary FCM permissions.
For Django projects, evaluate if `fcm-django` is a better fit. If using `fcm-django`, note that it replaces `pyfcm` and requires `firebase-admin` credentials (e.g., `GOOGLE_APPLICATION_CREDENTIALS` for service account path) instead of `pyfcm`'s direct API key or service account file parameters.
For PyFCM v2.x, ensure you are using a valid Firebase service account JSON key file, that the `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to it, and you've provided the correct `project_id` to `FCMNotification`. Verify the service account has the 'Firebase Cloud Messaging API' enabled and 'Firebase Cloud Messaging Sender' role. If you are on an older PyFCM version, ensure your legacy Server Key is correct.
First, check the Firebase status dashboard for any ongoing service outages. If the service is operational, ensure you have upgraded PyFCM to version 2.x to utilize the FCM v1 HTTP API, as the legacy APIs began deprecation and shutdown in 2024.
Migrate your code to use the unified `push_service.notify()` method. All previous functionality is now accessed via parameters to this single method (e.g., `fcm_token` for single device, `registration_ids` for multiple, `topic_name` for topics).
Install the library using pip: `pip install pyfcm`. If using a virtual environment, ensure it's activated before installation.