Skip to content

Pagination classes

Async-aware paginators that drive the apaginate_queryset() hook on async views. See the Pagination guide for selection criteria and tuning.

BasePagination

Bases: BasePagination

All pagination classes should extend BasePagination. Adds an async apaginate_queryset hook that defaults to running the sync paginate_queryset in a thread.

apaginate_queryset async

apaginate_queryset(queryset, request, view=None)

Returns a list of items for a single page of the queryset, or None if pagination is disabled.

PageNumberPagination

Bases: BasePagination, PageNumberPagination

A simple page number based style that supports page numbers as query parameters. Adds an async apaginate_queryset that uses async ORM (acount, async iteration) instead of sync_to_async.

apaginate_queryset async

apaginate_queryset(queryset, request, view=None)

Returns a list of items for the requested page, or None if pagination is disabled.

LimitOffsetPagination

Bases: BasePagination, LimitOffsetPagination

A limit/offset based style. Adds an async apaginate_queryset that uses async ORM (acount, async iteration) instead of sync_to_async.

apaginate_queryset async

apaginate_queryset(queryset, request, view=None)

Returns a list of items for the current limit/offset window, or None if pagination is disabled.

CursorPagination

Bases: BasePagination, CursorPagination

The cursor pagination implementation is necessarily complex. Inherits DRF's sync paginate_queryset; the async surface defaults to sync_to_async.

FastPageNumberPagination

Bases: BasePagination

Page number pagination that skips the COUNT(*) query. Determines whether a next page exists by checking if the current page is full, and omits the count field from the response.

get_page_size

get_page_size(request)

Returns the page size for the current request.

get_page_number

get_page_number(request)

Returns the requested page number from the query string.

paginate_queryset

paginate_queryset(queryset, request, view=None)

Returns a list of items for the requested page without issuing a COUNT(*).

apaginate_queryset async

apaginate_queryset(queryset, request, view=None)

Async variant of paginate_queryset using async ORM iteration.

get_paginated_response

get_paginated_response(data)

Returns the paginated response with results, next, and previous links.