Is there a way to listen for firebase database changes in python?

荒凉一梦 提交于 2019-12-25 01:49:02

问题


I have a python application that listens for put(add) events in my firebase database using Pyrebase but the stream feature of pyrebase is deprecated and stops listening after 30 minutes. The library is not supported anymore.

I figured out that firebase has a library for python called firebase-admin, however this does not have a streaming/listener capability for python, only for java. Is there any other way to do this?

#  get database instance
conn_instance = Database()
db = conn_instance.get_database()
storage = conn_instance.get_storage()
main_queue = Queue()


def stream_handler(message):
    # Reads stream input 
    print(message)

# Stream is created to firebase database using Pyrebase
request_stream = db.child("requests").stream(stream_handler)  

def close_application():
    #  Closes stream 
    request_stream.close()

I would like to have firebase database listener functionality for python as this is needed to process new database inputs.


回答1:


Firebase-Admin was the answer it works like a charm and is really not so hard to convert to from pyrebase.

basically i just replaced ".stream" with ".listen" and had to change how this "Event" was processed



来源:https://stackoverflow.com/questions/55996384/is-there-a-way-to-listen-for-firebase-database-changes-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!