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 type Pagination. This model has an attribute next_page_url which holds the URL of the next response page; since the delfini_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 the paginate() 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’s sync() method actually returns the provided type. Additionally, the arguments to the paginate() method are not type checked to align with the sync() method.

Parameters:
paginate(*args, **kwargs)[source]

Get an iterator over all pages from the response.

Parameters:
  • *args (Any) – Positional arguments to be passed to the module’s sync() function

  • **kwargs (Any) – Keyword arguments to be passed to the module’s sync() function.

Returns:

An iterator over each response page.

Return type:

Iterator[T]