Skip to main content

Pullkin

CodeFactor Build Status PyPI - Downloads GitHub GitHub last commit PyPI - Python Version

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

My alternative implementation of python implementation of JS implementation

Tested on python (3.6, 3.8, 3.10, pypy3.7-7.3.5)

I almost didn't write anything to consider it my intellectual property, just wrapped the code already written by Franc[e]sco in a design convenient for my own use

Note that for the listening part Franc[e]sco has to pull in http-ece which depends on a full-blown native crypto library rather than just oscrypto. it is an optional dependency, so you'll have to install it explicitly by depending on pullkin[listen]

Differences

  • Add async listener
  • Add async listener-coroutine
  • Replace functions with class of listener

Usage

Installation

pip install pullkin

How to use

import json
import os.path
import asyncio

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

SENDER_ID = '<<SENDER_ID>>'  # '1234567890'
# ANOTHER_SENDER_ID = '<<SENDER_ID>>'  # '1234567890'
APP_ID = '<<APP_ID>>'  # '1:1234567890:android:abcdef1234567890'
API_ID = '<<API_ID>>'  # 'AIzaSyDce4zFw4CqLqW2eCOqTbXfDx9a8mRnLpI'
FIREBASE_NAME = '<<FIREBASE_NAME'  # 'pullkin-example'
APP_NAME = '<<APP_NAME>>'  # 'cc.pullkin.example'

#
ANDROID_CERT = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'  
# 'da39a3ee5e6b4b0d3255bfef95601890afd80709' is default hash

pullkin = Pullkin()

if not os.path.exists('.persistent_ids.txt'):
    with open('.persistent_ids.txt', 'w+') as f:
        ...

with open(".persistent_ids.txt", "r") as f:
    received_persistent_ids = [x.strip() for x in f]


@pullkin.on_notification()
async def on_notification(message: Message, data_message: DataMessageStanza):
    idstr = data_message.persistent_id + "\n"
    with open(".persistent_ids.txt", "r") as f:
        if idstr in f:
            return
    with open(".persistent_ids.txt", "a") as f:
        f.write(idstr)
    print(message.notification)


async def main():
    if not os.path.exists('.pullkin_app_credentials'):
        with open('.pullkin_app_credentials', 'w+') as f:
            credentials = await pullkin.register(SENDER_ID, APP_ID, API_ID, FIREBASE_NAME, ANDROID_CERT,  APP_NAME)
            f.write(json.dumps(credentials.model_dump(mode="json")))
    else:
        with open('.pullkin_app_credentials', 'r') as f:
            credentials = AppCredentials.model_validate(json.loads(f.read()))
    
    await pullkin.add_app(sender_id=SENDER_ID, credentials=credentials, persistent_ids=received_persistent_ids)
    # await pullkin.add_app(sender_id=ANOTHER_SENDER_ID, credentials=another_credentials, persistent_ids=another_received_persistent_ids)
    
    
    await pullkin.run()


asyncio.run(main())

Metadata

Release files for pullkin 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pullkin 0.14.0
File Size Uploaded Provenance
pullkin-0.14.0.tar.gz 25.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pullkin 0.14.0
File Interpreter ABI Platform
pullkin-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 54.4 kB

Release files / pullkin-0.14.0.tar.gz

Download URL pullkin-0.14.0.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e7ea69f24936ef760ecff2bf9151710d5fda0c41ce944eb4cd793bb98f47deb6
BLAKE2b-256 checksum
How to use checksums
dfb876ecdffcaf823389496cc36bd5c23ef93de2c509498b69a4158a8bca6666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / pullkin-0.14.0-py3-none-any.whl

Download URL pullkin-0.14.0-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4959e9bd07338f968336148904a92032a6b81a9ef1a99a067cc5335e9574f214
BLAKE2b-256 checksum
How to use checksums
f4fa5e223f3a6039f21bbf9cacc4341e84b71fba3e9f59050ed0fbaead673993
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Security for pullkin 0.14.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page