philiprehberger-pagination
Cursor and offset pagination utilities for any data source.
Installation
pip install philiprehberger-pagination
Usage
from philiprehberger_pagination import paginate
items = list(range(100))
page = paginate(items, page=2, per_page=25)
print(page.items) # [25, 26, ..., 49]
print(page.pages) # 4
print(page.has_next) # True
Cursor Pagination
from philiprehberger_pagination import CursorPage
rows = [{"id": 1, "name": "a"}, {"id": 2, "name": "b"}, {"id": 3, "name": "c"}]
page = CursorPage.encode(rows, key="id", limit=2)
print(page.items) # first 2 rows
print(page.has_more) # True
print(page.next_cursor) # base64-encoded cursor
decoded = CursorPage.decode(page.next_cursor)
print(decoded) # {"id": 2}
API
| Function / Class | Description |
|---|---|
paginate(items, page, per_page) |
Offset-paginate a list and return a Page |
Page.items |
Items on the current page |
Page.total |
Total number of items |
Page.page |
Current page number (1-based) |
Page.per_page |
Items per page |
Page.pages |
Total number of pages |
Page.has_next |
Whether a next page exists |
Page.has_prev |
Whether a previous page exists |
CursorPage.encode(items, key, limit) |
Build a cursor page from a list of items |
CursorPage.decode(cursor) |
Decode a cursor string back to a dict |
CursorPage.items |
Items on the current page |
CursorPage.next_cursor |
Encoded cursor for the next page |
CursorPage.has_more |
Whether more items exist |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-pagination 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_pagination-0.2.0.tar.gz | 5.8 kB | Without provenance | Details for philiprehberger_pagination-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_pagination-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_pagination-0.2.0-py3-none-any.whl |
Total release size: 10.6 kB
Release files / philiprehberger_pagination-0.2.0.tar.gz
| Download URL | philiprehberger_pagination-0.2.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc4a1a3c2186bced5c4af6a1842275d5ac37812b337ba5c3c36ee95fd33e0866
|
|
BLAKE2b-256 checksum How to use checksums |
fad6f7a19109b3c62c1f3d53dbb51eaa64762c2b35ddd5ef8511774f613c5909
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_pagination-0.2.0-py3-none-any.whl
| Download URL | philiprehberger_pagination-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e67d7c9088acd7a701d2faeb9f89805b23f864a045fe4ed54e56c026da8a074a
|
|
BLAKE2b-256 checksum How to use checksums |
4f8cd106cd61f355aaea1b27b7091a8e0382d02ca7d42f437dcfff298e4f0b79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-pagination 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.