跳转到主要内容

FCM/GCM推送通知客户端

项目描述

PyPI Version Build Status Coverage Documentation Status Py Versions

一个用于订阅GCM/FCM并在Python应用程序内接收通知的库。

何时使用firebase-messaging ?

  • 我想在Python应用程序中接收使用Firebase Cloud Messaging发送的推送通知。

何时不使用firebase-messaging ?

  • 我想发送推送通知(请使用Firebase SDK代替)

  • 我的应用程序运行在FCM支持的平台上(Android、iOS、Web)。

安装

PyPi

$ pip install firebase-messaging

需求

  • 用于接收通知的Firebase配置

用法

必须在asyncio事件循环内运行。

python

from firebase_messaging import FcmPushClient, FcmRegisterConfig

def on_notification(obj, notification, data_message):
    # Do something with the notification
    pass

credentials = None  # Start off with none or load from previous save
def on_credentials_updated(creds):
    # save the credentials to a file here for future use

fcm_config = FcmRegisterConfig(fcm-project-id, fcm-app-id, fcm-api-key, fcm-message-sender-id)
pc = FcmPushClient(on_notification, fcm_config, credentials, on_credentials_updated)
fcm_token = await pc.checkin_or_register()

await pc.start()

# Adapt the following for your usage
while some_condition_to_keep_listening:
    asyncio.sleep(2)

归属

代码最初基于Matthieu Lemoine的typescript/node实现。更多详情请参阅这篇博客文章

lolisamurai转换为Python。

decrypt.py中的http解密逻辑由Martin Thomson提供。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

firebase_messaging-0.4.4.tar.gz (39.4 kB 查看哈希值)

上传时间

构建分布

firebase_messaging-0.4.4-py3-none-any.whl (40.0 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面