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.
- Fully
asyncio-native — built onasyncioTLS streams (mtalk.google.com:5228) andhttpx.AsyncClient. - Multi-app support — attach multiple independent
sender_idconnections on onePullkininstance. - Resilient by default — configurable MCS heartbeats, ACK timeouts, exponential-backoff reconnects, and
persistent_iddeduplication. - Encrypted & unencrypted payloads — handles Web Push
http-ecepayloads 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 backgroundstart(), or pull-basedlisten_coroutine().
- 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.
Full documentation (and LLM-friendly llms.txt) is hosted on Read the Docs:
- Installation
- Quickstart
- Registration & Tokens
- Listening & Lifecycle
- Handlers & Typed Models
- Migration Guide & Breaking Changelog
- API Reference
pip install pullkinRequires Python 3.10–3.15.
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:
passNote on tokens: Always read the device registration token via
credentials.token(notcredentials.fcm.token). By default,register(..., web_push=False)skips Web Push registration and returns an Android GCM token, socredentials.fcmisNone. See Registration & Tokens for details.