pagination.md
docs
pagination.md
Pagination
Fenrir provides built-in pagination utilities for list endpoints.
Basic Pagination
1 2 3 4 5 6 7 8 9 10 11 12 | |
PaginationParams
Pydantic model for pagination query parameters, injectable via Depends().
Query parameters:
| Parameter | Type | Default | Constraints | Description |
|---|---|---|---|---|
page |
int |
1 |
ge=1 |
Page number (1-based) |
size |
int |
20 |
ge=1, le=100 |
Items per page |
Properties:
| Property | Type | Description |
|---|---|---|
offset |
int |
Computed offset for database queries: (page - 1) * size |
limit |
int |
Same as size |
1 2 3 | |
PaginationLinks
Pydantic model for HATEOAS-style pagination links.
Fields:
| Field | Type | Default | Description |
|---|---|---|---|
self_url |
str |
"" |
URL for the current page |
first_url |
str |
"" |
URL for the first page |
last_url |
str |
"" |
URL for the last page |
next_url |
Optional[str] |
None |
URL for the next page, or None if on the last page |
prev_url |
Optional[str] |
None |
URL for the previous page, or None if on the first page |
PaginatedResponse
Standardised paginated response envelope returned by paginate().
Fields:
| Field | Type | Description |
|---|---|---|
items |
List[Any] |
Paginated items for the current page |
total |
int |
Total number of items across all pages |
page |
int |
Current page number |
size |
int |
Items per page |
pages |
int |
Total number of pages |
has_next |
bool |
Whether a next page exists |
has_prev |
bool |
Whether a previous page exists |
links |
Optional[PaginationLinks] |
Navigation links (only present when base_url is provided) |
paginate()
Paginate a sequence of items and return a paginated response dict.
1 2 3 | |
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
items |
Sequence[Any] |
— | Sequence of items to paginate |
page |
int |
1 |
Page number (1-based) |
size |
int |
20 |
Items per page |
base_url |
str |
"" |
Base URL for generating pagination links. When provided, the response includes a links field with navigation URLs. Supports existing query parameters in the URL. |
Response format (without base_url):
1 2 3 4 5 6 7 8 9 | |
Response format (with base_url):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Link generation with existing query parameters:
If base_url contains existing query parameters, they are preserved:
1 2 | |
paginate_dict()
Same as paginate but typed specifically for dict items.
1 2 3 4 | |
Parameters: Same as paginate().
Shortcut Usage
Use plain query parameters without PaginationParams:
1 2 3 | |