Skip to main content

Utilities for storing, retrieving, and monitoring Firebase Realtime Database objects in Python.

Project description

Build Status Coverage Status

Utilities for storing, retrieving, and monitoring Firebase Realtime Database objects in Python.

This builds on Pyrebase by providing turnkey support for database push updates throughout the Python stack. It works by linking together Pyrebase streams with the venerable blinker package, through a custom data structure. It allows arbitrary Python code to subscribe to notifications whenever data in your Firebase Realtime Database changes.

Q: Can’t I just use Pyrebase

A: Sure, but if you want to be notified in realtime when your data changes, you’ll need to set up thread-based stream handlers, and manage their lifecycles. In addition, the format of events from Firebase can be tricky to parse (do you know the difference between Firebase PUT and PATCH events?)

Firebase Live Data abstracts these concepts into simple blinker signals that are easy to use.

Usage

import pyrebase

from firebasedata import LiveData

pyrebase_config = {
    # ...
}

app = pyrebase.initialize_app(pyrebase_config)
live = LiveData(app, '/my_data')

# Get a snapshot of all data at the path, `/my_data`.
#
# This also sets up a persistent push connection to the Firebase Realtime Database
# at that path. Any updates under this path will trigger `blinker` events.
#
# `data` is a local (greedy) cache of the data at the root path (`/my_data`). It behaves
# somewhat like a Python dictionary.
data = live.get_data()
all_data = data.get() #  this also works: data.get('/')
sub_data = data.get('my/sub/path')

The push connection is established lazily, after the first call to get_data.

To get notified if something changes within your LiveData connection, just connect to the signal at that database path.

def my_handler(data):
    print(data)


# Note that the root path (`/my_data` in this case) is omitted from the signal name.

live.signal('/some/key').connect(my_handler)

You can also set data:

live.set_data('my/sub/path', 'my_value')

blinker events will be dispatched whenever data is set, either locally, like the example above, or via server push events.

Compatibility

Firebase Live Data is tested against Python 3.4, 3.5, and 3.6. It is not compatible with Python 2.

Developing

  1. Install the development requirements (preferably into a virtualenv):

    pip install -r requirements.txt
  2. Run tests to ensure everything works:

    py.test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

FirebaseData-0.5.1.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

FirebaseData-0.5.1-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page