Pagination¶
Presscart’s list endpoints use a uniform envelope. pypresscart models it as Paginated[T].
The envelope¶
from pypresscart import Paginated, OutletListing
page: Paginated[OutletListing] = client.outlets.list(limit=25, page=1)
page.records # list[OutletListing]
page.total_records # int — total across all pages
page.total_pages # int
page.current_page # int — 1-indexed
page.next_page # int | None — None on the last page
page.previous_page # int | None — None on the first page
Common query parameters¶
Every paginated endpoint in pypresscart accepts at least:
Param |
Default |
Notes |
|---|---|---|
|
|
Items per page |
|
|
1-indexed page number |
|
varies |
Field name (see endpoint docs) |
|
|
|
Many endpoints also accept a filters= dict — see Outlets for a filter-rich example.
Iterating all pages¶
There’s no built-in paginator today. Page manually:
def all_records(endpoint_callable, **kwargs):
page = 1
while True:
result = endpoint_callable(page=page, **kwargs)
yield from result.records
if result.next_page is None:
return
page = result.next_page
for outlet in all_records(client.outlets.list, limit=100, filters={"country": "United States"}):
print(outlet.outlet_name)
Paginated vs bare-array endpoints¶
A few endpoints return a naked JSON array instead of the paginated envelope. pypresscart returns list[Model] for those, not Paginated[Model]:
Endpoint |
Return type |
|---|---|
|
|
|
|
|
|
|
|
|
|
Check each resource page for the exact return type.
JSON mode¶
With as_json=True (or response_mode="json"), Paginated[T] collapses to the raw envelope dict:
raw = client.outlets.list(as_json=True)
raw["records"] # list of dicts
raw["next_page"] # int | None
See Dual-Mode I/O.
Tips¶
Start with
limit=100rather than the default of 25 if you’re reading a lot.Use
total_pagesto plan work before iterating (e.g., for a progress bar).Server may cap
limit— check the returnedrecordslength rather than trusting your requested limit.Stable ordering matters. If you’re crawling pages over time, sort by a monotonic field (e.g.
created_at) to avoid skips or duplicates when rows change under you.