Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python-Firebase listener implementation

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?

like image 428
Biplov Avatar asked Dec 05 '16 22:12

Biplov


1 Answers

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

like image 146
Frank van Puffelen Avatar answered Oct 21 '22 04:10

Frank van Puffelen