Skip to main content

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 a PageNumberPagination class with page_size, page_size_query_param="page_size", and max_page_size.
  • "limit": returns a LimitOffsetPagination class with default_limit and max_limit.
  • "cursor": returns a CursorPagination class with page_size and ordering.

Errors

If type is not one of "page", "limit", or "cursor", a ValueError is raised.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_drf_pagination-0.1.1.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_drf_pagination-0.1.1-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

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

Hashes for simple_drf_pagination-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ba4097f794b53dc25e9b0ede2a131be14f98a4bc5da2b7a1ce14e2f27179bdb0
MD5 a1de6ce5fedaf5076edae825400ec6db
BLAKE2b-256 787a95370dd1478c4b678680e17c67d9e723ba2ea353ff6dd259ace1a0201d64

See more details on using hashes here.

File details

Details for the file simple_drf_pagination-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_drf_pagination-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9b8e18fb2955ffcf0beb54472159ca3e37c164e225faa8acadac240f0a0cbb9
MD5 9a2260a5e1b30f2784abf288434fb619
BLAKE2b-256 bdbc2213c5312c9b19a759155022333fcfd6d87dd080a640b676dc2f66fc0cec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page