Skip to content
WhiteApfelPublic

About

Like Pushkin, but subscribe to FCM (GCM) and receive notifications in Python

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Repository files navigation

Pullkin

Tests Docs PyPI - Version PyPI - Python Version PyPI - Downloads License

Asynchronous Python client for receiving Firebase Cloud Messaging (FCM / GCM) push notifications directly over Google's MCS protocol.

Like Alexander Pushkin — except instead of pushing notifications, Pullkin pulls them in.

Pullkin emulates an Android/Chrome MCS client without requiring a headless browser. It is a clean asynchronous redesign inspired by push_receiver and push-receiver.


Features

  • Fully asyncio-native — built on asyncio TLS streams (mtalk.google.com:5228) and httpx.AsyncClient.
  • Multi-app support — attach multiple independent sender_id connections on one Pullkin instance.
  • Resilient by default — configurable MCS heartbeats, ACK timeouts, exponential-backoff reconnects, and persistent_id deduplication.
  • Encrypted & unencrypted payloads — handles Web Push http-ece payloads and direct Android GCM/FCM data messages seamlessly.
  • Typed Pydantic models — validate and auto-convert incoming notifications directly via handler type annotations (Message, NotificationData, generics, Optional/unions).
  • Flexible execution modes — blocking run(), non-blocking background start(), or pull-based listen_coroutine().

Who Is Pullkin For?

  • End-to-end push testing in CI: Verify that your backend actually delivers real Firebase notifications without maintaining emulators or Appium farms.
  • Headless automation & OTP/2FA bots: Receive confirmation codes or status pushes from mobile-first services on a Linux server without Chromium or Electron.
  • Multi-app push gateways & monitoring: Listen to multiple Firebase sender_ids from a single Python process and measure real delivery latency.
  • When NOT to use Pullkin: If you only want to send push notifications from a backend, use firebase-admin. Pullkin is specifically for receiving pushes as a client device.

Documentation

Full documentation (and LLM-friendly llms.txt) is hosted on Read the Docs:

Installation

pip install pullkin

Requires Python 3.10–3.15.

Quickstart

import asyncio
from pathlib import Path

from pullkin import Pullkin
from pullkin.models import AppCredentials, Message
from pullkin.proto.mcs_proto import DataMessageStanza

SENDER_ID = "123456789012"
APP_ID = "1:123456789012:android:abcdef1234567890"
API_KEY = "AIzaSyExampleApiKey"
FIREBASE_PROJECT_ID = "my-firebase-project"
ANDROID_CERT = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
APP_NAME = "com.example.app"
CREDS_FILE = Path("credentials.json")

pullkin = Pullkin()


@pullkin.on_notification()
async def handle_notification(message: Message, data_message: DataMessageStanza):
    print("Notification:", message.notification)
    print("Data:", message.data)


@pullkin.on_persistent_id()
async def save_persistent_id(sender_id: str, persistent_id: str):
    # Persist IDs to avoid re-receiving already processed messages after restart
    print(f"[{sender_id}] persistent_id={persistent_id}")


async def get_credentials() -> AppCredentials:
    if CREDS_FILE.exists():
        return AppCredentials.model_validate_json(CREDS_FILE.read_text(encoding="utf-8"))

    credentials = await pullkin.register(
        sender_id=SENDER_ID,
        app_id=APP_ID,
        api_key=API_KEY,
        firebase_project_id=FIREBASE_PROJECT_ID,
        android_cert=ANDROID_CERT,
        app_name=APP_NAME,
    )
    CREDS_FILE.write_text(credentials.model_dump_json(indent=2), encoding="utf-8")
    return credentials


async def main():
    credentials = await get_credentials()
    print("Device token:", credentials.token)

    await pullkin.add_app(sender_id=SENDER_ID, credentials=credentials)
    try:
        await pullkin.run()
    finally:
        await pullkin.stop()


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

Note on tokens: Always read the device registration token via credentials.token (not credentials.fcm.token). By default, register(..., web_push=False) skips Web Push registration and returns an Android GCM token, so credentials.fcm is None. See Registration & Tokens for details.

About

Like Pushkin, but subscribe to FCM (GCM) and receive notifications in Python

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages