Iterators¶
-
class
restfly.iterator.
APIIterator
(api, **kw)[source]¶ The API iterator provides a scalable way to work through result sets of any size. The iterator will walk through each page of data, returning one record at a time. If it reaches the end of a page of records, then it will request the next page of information and then continue to return records from the next page (and the next, and the next) until the counter reaches the total number of records that the API has reported.
Note that this Iterator is used as a base model for all of the iterators, and while the mechanics of each iterator may vary, they should all behave to the user in a similar manner.
-
_api
¶ The APISession object that will be used for querying for the data.
Type: restfly.session.APISession
-
page
¶ The current page of data being walked through. pages will be cycled through as the iterator requests more information from the API.
Type: list
-
_get_page
() → None[source]¶ A method to be overloaded in order to instruct the iterator how to retrieve the next page of data.
Example
>>> class ExampleIterator(APIIterator): ... def _get_page(self): ... self.total = 100 ... items = range(10) ... self.page = [{'id': i + self._offset} for i in items] ... self._offset += self._limit
-