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 aclient
or adatabase
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 APIsdb_updates()
,db_updates()
, or the database APIchanges()
. Reference those methods for a list of valid feed options.Parameters: -
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 aCloudant
object or adatabase
object which it uses to issue HTTP requests to the appropriate feed endpoint. An infinite feed is NOT supported for use with aCouchDB
object and unlike aFeed
which can be anormal
,longpoll
, orcontinuous
feed, an InfiniteFeed can only becontinuous
and the iterator will only stream formatted JSON objects. Instead of using this class directly, it is recommended to use the client APIinfinite_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 adatabase
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
-