Pyrebase is a Firebase client library for Python.
Connecting to a Firebase location and adding data to it is easy. Here's how:
>>> import pyrebase
>>> f = pyrebase.Firebase('https://pyrebase.firebaseIO.com/')
>>> c = f.push({'foo': 'bar'})
>>> c.ref
u'https://pyrebase.firebaseIO.com/-JHFR_y14CzSOm8q86G1/'
>>> c.get()
{u'foo': u'bar'}
Traversing locations is simple with the parent
, child
, and root
methods:
>>> f = pyrebase.Firebase('https://pyrebase.firebaseIO.com/pokemon/bulbasaur')
>>> f.root.ref
'https://pyrebase.firebaseIO.com/'
>>> f.parent.ref
'https://pyrebase.firebaseIO.com/pokemon/'
>>> f.parent.parent.ref
'https://pyrebase.firebaseIO.com/'
>>> f.parent.child('squirtle').ref
'https://pyrebase.firebaseIO.com/pokemon/squirtle/'
Remember to use the official firebase-token-generator package for authentication:
>>> from firebase_token_generator import create_token
>>> custom_data = {'pokemon_master': True}
>>> options = {'admin': True}
>>> token = create_token('not-a-fake-firebase-secret', custom_data, options)
>>> f = pyrebase.Firebase('https://pyrebase.firebaseIO.com/', auth=token)
Pyrebase is tested with pytest. To run the tests, use this command:
$ make test
Copyright 2014 Justin Poliey