有没有办法监听python中的Firebase数据库更改? [英] Is there a way to listen for firebase database changes in python?

查看:77
本文介绍了有没有办法监听python中的Firebase数据库更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python应用程序,它使用Pyrebase监听我的firebase数据库中的put(add)事件,但是不推荐使用pyrebase的流功能,并在30分钟后停止监听.该库不再受支持.

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.

我发现firebase有一个用于python的库,名为firebase-admin,但是它没有针对python的流/侦听功能,仅针对Java.还有其他方法吗?

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()

我想为python提供firebase数据库侦听器功能,因为这是处理新数据库输入所必需的.

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

推荐答案

Firebase-Admin就是一个很好的解决方案,它真的很容易转换为pyrebase.

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

基本上,我只是将".stream"替换为".listen",并且不得不更改此事件"的处理方式

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

这篇关于有没有办法监听python中的Firebase数据库更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆