Skip to main content

Quickstart

Paginate, filter, sort, and search an in-memory collection with pypaginate. Items can be dicts or objects; your rows are returned untouched.

Paginate a list

from pypaginate import paginate, OffsetParams

users = [...] # any list of dicts or objects

page = paginate(users, OffsetParams(page=1, limit=20))

page.total # total rows across all pages (int)
page.pages # total number of pages
page.has_next # bool
list(page) # the page's items (OffsetPage is iterable, indexable, sized)
page[0] # first item on the page

The one-shot helpers each run a single operation and return a new list:

from pypaginate import filter, sort, search, FilterSpec, SortSpec, SearchSpec, And

adults = filter(users, FilterSpec(field="age", operator="gte", value=18))

grouped = filter(users, And(
FilterSpec(field="age", operator="gte", value=18),
FilterSpec(field="role", operator="in", value=["admin", "owner"]),
))

newest = sort(users, SortSpec(field="created_at", direction="desc"))

hits = search(users, SearchSpec(query="alice", fields=["name", "email"]))

Operators, directions, and search modes are plain strings ("gte", "desc", "contains") — see the shared reference.

Query the same data repeatedly — Dataset

Each one-shot call marshals the whole collection into the engine. When you query the same rows many times, build a Dataset once and reuse it — it runs the full filter → search → sort → paginate pipeline in a single native call:

from pypaginate import Dataset, OffsetParams, FilterSpec, SortSpec

ds = Dataset(users) # marshals once

page = ds.page(
OffsetParams(page=1, limit=20),
filters=[FilterSpec(field="age", operator="gte", value=18)],
sorting=[SortSpec(field="created_at", direction="desc")],
)
page.total # matches across all pages
list(page) # the page's rows

Where next

You want to…Go to
Filter with all 20 operators and boolean groupsFiltering
Sort by multiple keys with null placementSorting
Rank results, fuzzy / typo-tolerant searchSearch
Offset, keyset (cursor), and Dataset in depthPagination
Paginate a database querySQLAlchemy · Django
Parse pagination from a requestFastAPI