Firebase request using python-firebase

How can I request Firebase using Python? I am using python-firebase and can do simple queries (like all entities), but you need to query a subset of objects. Any pointers would be helpful. I have successfully done this using BTW JavaScript.

+4
source share
3 answers

To request a specific node from firebase, you need to specify it in your URL, in the following example I will load a specific node (-KeuhkMH8SQcYJHatRnD) from the main "news" node:

def load_news():

    try:
        loader = urllib.request.urlopen("https://<YOUR-PROJECT-ID>.firebaseio.com/news/-KeuhkMH8SQcYJHatRnD.json")
    except urllib.error.URLError as e:
        message = json.loads(e.read())
        print(message["error"])
    else:
        print(loader.read())  
+1
source

use Pyrebase, it's simple and easy to understand (in my opinion)

data = db.child("sensor").order_by_child("temp").limit_to_last(10).get()
print(data.val())

result:

0
source

Firebase Admin Python API

https://firebase.googleblog.com/2017/07/accessing-database-from-python-admin-sdk.html?m=1

from firebase_admin import db

root = db.reference()
x = db.reference('users/{0}'.format(new_user.key)).get()
print 'Name:', x['name']
print 'Since:', x['since']

python-firebase api firebase

2

0
source

All Articles