Pagination — Python Kaos Utils documentation

# Pagination

py_kaos_utils.pagination.paginate_generator(generator: Generator[T, None, None], limit: int) → Generator[list[T], None, None]

  Paginate a generator by a given limit (page size).

  Example:

        >>> g = range(10000)
        >>> for page in paginate_generator(g, 100):
        >>>     print(page)

  Parameters

    - generator (Generator[T, None, None]) – the generator to be paginated

    - limit (int) – number of items per page

  Returns

    a generator of pages, where each page is a list of items

  Return type

    Generator[list[T], None, None]

  Note

    If limit is zero (or negative for that matter), it returns the whole generator as a list