Zero-boilerplate pagination helpers for Django REST Framework.
This package provides a single factory function, paginate, that returns a
DRF pagination class based on a short type string.
pip install simple-drf-paginationfrom simple_drf_pagination import paginate
# Page-number pagination
PagePagination = paginate(page_size=20, max_size=100)
# Limit/offset pagination
LimitPagination = paginate("limit", page_size=50, max_size=200)
# Cursor pagination
CursorPagination = paginate("cursor", page_size=25, ordering="-created_at")from rest_framework.viewsets import ModelViewSet
from simple_drf_pagination import paginate
class ItemViewSet(ModelViewSet):
queryset = Item.objects.all()
serializer_class = ItemSerializer
pagination_class = paginate("page", page_size=20)paginate(
type: str = "page",
page_size: int = 10,
max_size: int = 100,
ordering: str = "-id",
)type:"page","limit", or"cursor". Defaults to"page".page_size: Default page size for the pagination class.max_size: Maximum page size or limit (page and limit types).ordering: Cursor ordering field (cursor type only).
"page": returns aPageNumberPaginationclass withpage_size,page_size_query_param="page_size", andmax_page_size."limit": returns aLimitOffsetPaginationclass withdefault_limitandmax_limit."cursor": returns aCursorPaginationclass withpage_sizeandordering.
If type is not one of "page", "limit", or "cursor", a ValueError
is raised.
MIT