Examples
Complete, runnable examples demonstrating pypaginate v0.2 features.
Quick Links
Example |
Description |
|---|---|
In-memory and SQLAlchemy offset pagination |
|
FilterSpec, And/Or groups, FilterDep |
|
CursorParams, CursorPage, cursor backends |
|
Full app with OffsetDep, filtering, sorting, search |
Prerequisites
pip install pypaginate[all]
The Core Pattern
Every example follows the same pattern – the universal paginate() function:
from pypaginate import paginate, OffsetParams
# In-memory: no backend needed
page = paginate([1, 2, 3, 4, 5], OffsetParams(page=1, limit=2))
# Database: pass a backend explicitly
page = await paginate(query, OffsetParams(page=1, limit=20), backend=backend)
Input type determines output type:
OffsetParamsproducesOffsetPage(withtotal,page,pages)CursorParamsproducesCursorPage(withnext_cursor,previous_cursor)
Example Categories
Getting Started
Basic Pagination –
paginate()with lists and SQLAlchemyFiltering –
FilterSpecandAnd/Orgroups
Intermediate
Keyset Pagination –
CursorParamsfor large datasetsFastAPI Integration – Declarative dependencies
Advanced
Pipelines –
SyncPipeline/AsyncPipelinefor filter + sort + search + paginateCustom backends – Implement the
PaginationBackendprotocol