Python-Firebase listener implementation

匆匆过客 提交于 2021-01-02 08:31:47

问题


Is there a way where you can actively have a listener for a Firebase Database in Python?

For instance, I have a node user in the database, I want to be able to actively listen for any changes that immediately happens for a user and immediately make changes on it.

For now, I'm just using a for-loop. In my case, I have something like sync_state for user with the integer value 3. It gets changed to 4 when the session has been ended, I want to update value for that user.

Right now, I run the for-loop periodically, but it won't be efficient in the future when I have a lot of users in my database. Is there a way to do this in a python-ish way than using Node.JS?


回答1:


You can use Firebase's REST Streaming API: https://firebase.google.com/docs/database/rest/retrieve-data#section-rest-streaming.

The blog post that introduced that API, includes some samples for Python: https://firebase.googleblog.com/2014/03/announcing-streaming-for-firebase-rest.html

There are some Python libraries that wrap that API: https://www.google.nl/webhp#q=firebsae%20python%20streaming



来源:https://stackoverflow.com/questions/40984433/python-firebase-listener-implementation

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