Skip to content

Paginators

paginators

Fancy paginators with a large amount of useful methods.

Modules:

  • api –

    Base paginators made specifically for interaction with the api.

  • base –

    Base paginators.

Classes:

BufferedPaginator

BufferedPaginator(*, limit: Optional[int] = None)

Paginator with a support for buffers.

Methods:

  • next_page –

    Get the next page of the paginator.

Attributes:

exhausted property

exhausted: bool

Whether all pages have been fetched.

limit instance-attribute

limit: Optional[int] = limit

Limit of items to be yielded.

next_page abstractmethod async

next_page() -> Optional[Iterable[T]]

Get the next page of the paginator.

CursorPaginator

CursorPaginator(
    getter: GetterCallback[UniqueT],
    *,
    limit: Optional[int] = None,
    end_id: int = 0,
    page_size: Optional[int] = 20,
)

Paginator based on end_id cursors.

Methods:

  • next_page –

    Get the next page of the paginator.

Attributes:

  • end_id (Optional[int]) –

    Current end id. If none then exhausted.

  • getter (GetterCallback[UniqueT]) –

    Underlying getter that yields the next page.

end_id instance-attribute

end_id: Optional[int] = end_id

Current end id. If none then exhausted.

getter instance-attribute

getter: GetterCallback[UniqueT] = getter

Underlying getter that yields the next page.

next_page async

next_page() -> Optional[Iterable[UniqueT]]

Get the next page of the paginator.

MergedPaginator

MergedPaginator(
    iterables: Collection[AsyncIterable[T]],
    *,
    key: Optional[Callable[[T], Any]] = None,
    limit: Optional[int] = None,
)

A paginator merging a collection of iterators.

Methods:

  • flatten –

    Flatten the paginator.

Attributes:

iterators instance-attribute

iterators: Sequence[AsyncIterator[T]] = [
    (__aiter__()) for iterable in iterables
]

Entry iterators.

Only used as pointers to a heap.

limit instance-attribute

limit: Optional[int] = limit

Limit of items to be yielded

flatten async

flatten(*, lazy: bool = False) -> Sequence[T]

Flatten the paginator.

PagedPaginator

PagedPaginator(
    getter: GetterCallback[T],
    *,
    limit: Optional[int] = None,
    page_size: Optional[int] = None,
)

Paginator for resources which only require a page number.

Due to ratelimits the requests must be sequential.

Methods:

  • next_page –

    Get the next page of the paginator.

Attributes:

current_page instance-attribute

current_page: Optional[int] = 1

Current page counter..

getter instance-attribute

getter: GetterCallback[T] = getter

Underlying getter that yields the next page.

next_page async

next_page() -> Optional[Iterable[T]]

Get the next page of the paginator.

Paginator

Base paginator.

Methods:

  • flatten –

    Flatten the paginator.

  • next –

    Return the next element.

flatten async

flatten() -> Sequence[T]

Flatten the paginator.

next async

next() -> T

Return the next element.

TokenPaginator

TokenPaginator(
    getter: TokenGetterCallback[T],
    *,
    limit: Optional[int] = None,
    page_size: Optional[int] = None,
)

Paginator for resources which require a token.

Methods:

  • next_page –

    Get the next page of the paginator.

Attributes:

getter instance-attribute

getter: TokenGetterCallback[T] = getter

Underlying getter that yields the next page.

token instance-attribute

token: Optional[str] = ''

next_page async

next_page() -> Optional[Iterable[T]]

Get the next page of the paginator.