Paginator¶
- class pydelfini.delfini_core.paginator.Paginator(mod, client)[source]¶
Bases:
Generic
[T
]A utility that helps with dealing with paginated API responses.
Paginated API responses have the property
pagination
of typePagination
. This model has an attributenext_page_url
which holds the URL of the next response page; since thedelfini_core
library does not allow you to directly interact with URLs, this helper assists with making these additional page requests.This class takes as arguments the module containing the desired API endpoint and the appropriate
client
. Since this is a generic class, it is also encouraged for type safety to specify the expected return type in brackets. The actual API request is done by calling thepaginate()
method.Example usage:
from pydelfini.delfini_core.paginator import Paginator from pydelfini.delfini_core.api.collections import collections_get_collections from pydelfini.delfini_core.models import CollectionsGetCollectionsCollectionList pager = Paginator[CollectionsGetCollectionsCollectionList]( collections_get_collections, client ) for page in pager.paginate(public=True): # Note that you still need to iterate through each item # in each page for collection in page.collections: print(collection.name)
Warning
While the return type of
paginate()
is set according to the generic class definition, the static type checker cannot verify that the provided module’ssync()
method actually returns the provided type. Additionally, the arguments to thepaginate()
method are not type checked to align with thesync()
method.- Parameters:
mod (ModuleType)
client (Client | AuthenticatedClient)