Skip to main content

Firebase Persistence for python-telegram-bot

PyPI

This is an implementation of python-telegram-bot BasePersistence class that uses Google Firebase as persistence back-end. This has a very nice advantage of being able to look at your user_data, chat_data, bot_data and convesations real-time using the firebase web app.

Installation

The library obviously requires (but does not install) python-telegram-bot. It also requires and installs officeial library foor Google Firebase: firebase-admin

pip install ptb-firebase-persistence

Usage

Before you start: obtain credentials from firebase

First of all you need to obtain firebase credentials, that look like this:

{
  "type": "service_account",
  "project_id": "YOUR_ID",
  "private_key_id": "YOUR_PRIVATE_KEY",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMII...EwQ=\n-----END PRIVATE KEY-----\n",
  "client_email": "firebase-adminsdk-SOME_STRING@SOME_DOMAIN.iam.gserviceaccount.com",
  "client_id": "11743776666698009",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-SOMES_STRING.iam.gserviceaccount.com"
}

and the firebase database url that looks like this, something like https://YOUR_APP.firebaseio.com

Instantiation

Store the database URL in an environment variable FIREBASE_URL and the config as a json string in an environment variable FIREBASE_CREDENTIALS.

After that instantiation is as easy as:

from ptb_firebase_persistence import FirebasePersistence
from telegram.ext import Updater


my_persistence = FirebasePersistence.from_environment()

updater: Updater = Updater(
    'BOT_TOKEN',
    persistence=my_persistence,
    use_context=True,
)

Direct instantiation

You can also just pass the firebase credentials as URL as simple init params:

from ptb_firebase_persistence import FirebasePersistence
from telegram.ext import Updater


my_persistence = FirebasePersistence(database_url='YOUR_DATABASE_URL', credentials='YOUR_CREDENTIALS_DICT')

updater: Updater = Updater(
    'BOT_TOKEN',
    persistence=my_persistence,
    use_context=True,
)

That's it! You can now watch your data change live on Firebase.

Metadata

Release files for ptb-firebase-persistence 0.1.2

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

Source distribution (sdist)

Source distribution for ptb-firebase-persistence 0.1.2
File Size Uploaded Provenance Actions
ptb_firebase_persistence-0.1.2.tar.gz 3.3 kB Without provenance Details for ptb_firebase_persistence-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ptb-firebase-persistence 0.1.2
File Interpreter ABI Platform Actions
ptb_firebase_persistence-0.1.2-py3-none-any.whl Python 3 none any Details for ptb_firebase_persistence-0.1.2-py3-none-any.whl

Total release size: 6.7 kB

Release files / ptb_firebase_persistence-0.1.2.tar.gz

Download URL ptb_firebase_persistence-0.1.2.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
642a03302968a6a7dd9799ed6908f486451765c6fd55feb9de3056522cf8f5c6
BLAKE2b-256 checksum
How to use checksums
56db4bf8d99a2e40816257d138121f24ccb2d461d2acbf07bb42801e3830ad95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.7.7 Linux/5.3.0-1028-azure

Release files / ptb_firebase_persistence-0.1.2-py3-none-any.whl

Download URL ptb_firebase_persistence-0.1.2-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0131d4a1f5e481ef019839bfb3b708732132d20df5f1729142be8c090e34380b
BLAKE2b-256 checksum
How to use checksums
bd63726472a036fe9ab711ea4d9d7f703aff695e04777c05cbfa964d43a876e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.7.7 Linux/5.3.0-1028-azure

Security for ptb-firebase-persistence 0.1.2

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.

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