Client Side Auto-Pagination
In this example, we will show how to use the client side auto-pagination feature of the Peak-SDK. This feature allows you to iterate over a list of resources without having to worry about the pagination logic.
For this example we will use the
Press-App
client, but the same logic applies to all the other clients withlist
methods that accept apage_size
andpage_number
parameters, the feature can be toggled on or off by setting thereturn_iterator
parameter toTrue
orFalse
respectively.By default, the
return_iterator
parameter is set toTrue
, and usingpage_size
andpage_number
parameters will have no effect whenreturn_iterator
is set toTrue
.
Import the press app module and Instantiate a press-app
client
[ ]:
from collections.abc import Iterator
from typing import Any
from peak.press import apps
client: apps.App = apps.get_client()
List created app-spec
(s) and iterate over them using auto-pagination with return_iterator=True
[ ]:
spec_iterator: Iterator[dict[str, Any]] = client.list_specs(return_iterator=True)
existing_specs: dict[str, Any] = next(spec_iterator)
List created app-spec
(s) with auto-pagination disabled
[ ]:
spec_iterator: dict[str, Any] = client.list_specs(page_size=50, page_number=1, return_iterator=False)
first_50_specs: dict[str, Any] = spec_iterator