Skip to content

Pagination

AsyncPaginator(http, path, model, *, params=None)

Async iterator over a paginated CTFd list endpoint.

Iterating yields parsed model instances one by one, transparently requesting the next page when the current one is exhausted.

Source code in ctfd/pagination.py
def __init__(
    self,
    http: AsyncHTTPClient,
    path: str,
    model: type[T],
    *,
    params: dict[str, Any] | None = None,
) -> None:
    self._http = http
    self._path = path
    self._model = model
    self._params: dict[str, Any] = dict(params or {})
    self._buffer: list[T] = []
    self._meta = PageMeta()
    self._exhausted = False
    self._loaded_once = False

meta property

Metadata of the most recently fetched page (empty before the first fetch).

all() async

Drain the paginator and return every remaining item as a list.

Source code in ctfd/pagination.py
async def all(self) -> list[T]:
    """Drain the paginator and return every remaining item as a list."""

    return [item async for item in self]

PageMeta(page=None, next=None, prev=None, pages=None, per_page=None, total=None) dataclass

Pagination metadata as exposed by the CTFd API.

The CTFd API returns these counters under the meta.pagination key on list endpoints. Any of them may be missing on legacy versions, in which case the field stays None.