The SDK offers two different ways of using API endpoints that support pagination. The first is to manually get each successive page. For example, the following will print each indicator for a given report:
page = None # get each successive page of indicators while page is None or page.has_more_pages(): # get next page of indicators page = ts.get_indicators_for_report_page(report_id="4d1fcaee-5009-4620-b239-2b22c3992b80", page_number=page_number) # print each indicator in the page for indicator in page.items: print(indicator) page_number += 1
Because this pattern is so common for paginated endpoints, there is a shorthand available:
indicators = ts.get_indicators_for_report(report_id="4d1fcaee-5009-4620-b239-2b22c3992b80") for indicator in indicators: print(indicator)
The two examples are completely equivalent. In the first example,
page is an instance of the Page class. It contains a field called
items, which is a list of Indicator objects. In the second example,
indicators is a generator, which is a Python object that can be iterated over using a for loop.
For every method that makes a request to a paginated endpoint and returns a Page object (get_reports_page, get_indicators_for_report_page, etc.), there is a corresponding method that returns a generator (get_reports, get_indicators_for_report, etc.).