Pagination primitives for chirp.data.
Offset-based pagination that composes withQuery. One method call
replaces the manual count-query + offset-math + total-pages-calc pattern.
Usage::
from chirp.data import Query, PageResult
result: PageResult[Todo] = await (
Query(Todo, "todos")
.where("done = ?", False)
.order_by("id DESC")
.paginate(db, page=2, per_page=20)
)
result.items # list[Todo] — rows for this page
result.total_pages # 5
result.has_next # True
result.page_range() # [1, 2, 3, 4]
Free-threading safety:
- Frozen dataclass — immutable after creation
- No shared mutable state
data.pagination
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
PageResult
class
A page of results with pagination metadata.
Constructed byQuery.paginate()— not typically created directly.
View source · /home/runner/work/chirp/chirp/site/../src/chirp/data/pagination.py:1