Zero-boilerplate pagination helpers for Django REST Framework
Project description
simple-drf-pagination
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.
Installation
pip install simple-drf-pagination
Quick start
from 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")
Usage with DRF views
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)
API
paginate(
type: str = "page",
page_size: int = 10,
max_size: int = 100,
ordering: str = "-id",
)
Parameters
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).
Behavior details
"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.
Errors
If type is not one of "page", "limit", or "cursor", a ValueError
is raised.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_drf_pagination-0.1.1.tar.gz.
File metadata
- Download URL: simple_drf_pagination-0.1.1.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba4097f794b53dc25e9b0ede2a131be14f98a4bc5da2b7a1ce14e2f27179bdb0
|
|
| MD5 |
a1de6ce5fedaf5076edae825400ec6db
|
|
| BLAKE2b-256 |
787a95370dd1478c4b678680e17c67d9e723ba2ea353ff6dd259ace1a0201d64
|
File details
Details for the file simple_drf_pagination-0.1.1-py3-none-any.whl.
File metadata
- Download URL: simple_drf_pagination-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9b8e18fb2955ffcf0beb54472159ca3e37c164e225faa8acadac240f0a0cbb9
|
|
| MD5 |
9a2260a5e1b30f2784abf288434fb619
|
|
| BLAKE2b-256 |
bdbc2213c5312c9b19a759155022333fcfd6d87dd080a640b676dc2f66fc0cec
|