Cloudant database listener in python

210 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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.