feed

Module containing the Feed class which provides iterator support for consuming continuous and non-continuous feeds like _changes and _db_updates.

class cloudant.feed.Feed(source, raw_data=False, **options)

Bases: object

Provides an iterator for consuming client and database feeds such as _db_updates and _changes. A Feed object is constructed with a client or a database which it uses to issue HTTP requests to the appropriate feed endpoint. Instead of using this class directly, it is recommended to use the client APIs db_updates(), db_updates(), or the database API changes(). Reference those methods for a list of valid feed options.

Parameters:
  • source – Either a client object or a database object.
  • raw_data (bool) – If set to True then the raw response data will be streamed otherwise if set to False then JSON formatted data will be streamed. Default is False.
last_seq

Returns the last sequence identifier for the feed. Only available after the feed has iterated through to completion.

Returns:A string representing the last sequence number of a feed.
next()

Handles the iteration by pulling the next line out of the stream, attempting to convert the response to JSON if necessary.

Returns:Data representing what was seen in the feed
stop()

Stops a feed iteration.

class cloudant.feed.InfiniteFeed(source, **options)

Bases: cloudant.feed.Feed

Provides an infinite iterator for consuming client and database feeds such as _db_updates and _changes. An InfiniteFeed object is constructed with a Cloudant object or a database object which it uses to issue HTTP requests to the appropriate feed endpoint. An infinite feed is NOT supported for use with a CouchDB object and unlike a Feed which can be a normal, longpoll, or continuous feed, an InfiniteFeed can only be continuous and the iterator will only stream formatted JSON objects. Instead of using this class directly, it is recommended to use the client API infinite_db_updates() or the database API _infinite_changes(). Reference those methods for a valid list of feed options.

Note: The infinite iterator is not exception resilient so if an unexpected exception occurs, the iterator will terminate. Any unexpected exceptions should be handled in code outside of this library. If you wish to restart the infinite iterator from where it left off that can be done by constructing a new InfiniteFeed object with the since option set to the sequence number of the last row of data prior to termination.

Parameters:source – Either a Cloudant object or a database object.
next()

Handles the iteration by pulling the next line out of the stream and converting the response to JSON.

Returns:Data representing what was seen in the feed