Pagination¶
The API provides a paginated response to requests, encapsulated in the Python client, returning an object that you can use to iterate over and explore the data.
from mbed_cloud import ConnectAPI
api = ConnectAPI()
paginator = api.list_connected_devices()
print(paginator.count())
print(paginator.first())
print(len(paginator))
for d in paginator:
print(d)
Reference¶
Pagination
-
class
mbed_cloud.pagination.
PaginatedResponse
(func, lwrap_type=None, _results_cache=True, page_size=None, max_results=None, **kwargs)¶ Initialize wrapper by passing in object with metadata structure.
Parameters: - func – API function called to obtain a page of results
- lwrap_type – Wrapper class called for each returned result object
- _results_cache – Retains a copy of all returned results to reduce API calls Set to None to disable (for use as a pure generator, and to reduce memory usage)
- page_size – Number of results to request per page
- max_results – Total maximum number of results to retrieve
-
all
()¶ All results
-
count
()¶ Approximate number of results, according to the API
-
data
¶ Deprecated. Returns the data as a list
-
first
()¶ Returns the first item from the query, or None if there are no results
-
next
()¶ Next item in sequence (Python 2 compatibility)
-
to_dict
()¶ Internal state