2

I'm trying to create a listener in python that automatically retrieve changes on a Cloudant database as they occur. When a change occurs I want to call a specific function.

I have read through the documentation and the API-specifications but couldn't find anything.

Is there a way to do this?

Johan
  • 55
  • 5

1 Answers1

2

Here's a basic streaming changes feed reader (disclaimer: I wrote it):

https://github.com/xpqz/pylon/blob/master/pylon.py#L165

The official Cloudant Python client library also contains a changes feed follower:

https://python-cloudant.readthedocs.io/en/latest/feed.html

It's pretty easy to get a basic changes feed reader going as the _changes endpoint with a feed=continuous parameter does quite a lot off the bat for you, including passing the results back as self-contained json-objects per line. The hard bit is dealing with quite a non-obvious set of failure conditions.

xpqz
  • 3,617
  • 10
  • 16
  • Thanks for the answer! I succeeded with the listener by using the python client library and cloudant.feed.Feed. However, I am not able to get my flask application running while the listener code is "listening". I think the problem is where it iterates through the changes and is getting "stuck" in the for loop. Do you know any solution to this? – Johan Aug 02 '18 at 16:09