Reputation: 180
I'm using the python firebase admin sdk for my flask app. Is it possible to listen to realtime events on collections (like document addded)?
Some documentation indicates that it's possible, yet other documentation and my own testing indicates else wise.
The documentation for CollectionReference indicates that on_snapshot
can be used to register event listeners on collections.
However, this firestore tutorial is saying that "Note: Realtime listeners are not supported in Python and PHP."
. So there are two contradictory sources
Furthermore, in my own tests I'm getting that on_snapshot
is not an attribute of an CollectionReference
, suggestion that this feature is not possible.
Can you confirm whether realtime listening in python firestore admin sdk is possible or not ?
The documentation for on_snapshot
says this code should work
from google.cloud import firestore
db = firestore.Client()
collection_ref = db.collection(u'users')
def on_snapshot(collection_snapshot):
for doc in collection_snapshot.documents:
print(u'{} => {}'.format(doc.id, doc.to_dict()))
collection_watch = collection_ref.on_snapshot(on_snapshot)
However it's giving me an error
AttributeError: 'CollectionReference' object has no attribute 'on_snapshot'
Upvotes: 0
Views: 1468
Reputation: 7438
This hasn't been released yet. The last release is from October 2018, and the on_snapshot
method has been added in a November PR: https://github.com/googleapis/google-cloud-python/pull/6191
I think the API reference is auto-generated from the GitHub master branch, which is why it appears there.
Upvotes: 1