Collections
A Collection is a lazy, chainable wrapper around a list endpoint. No HTTP
request happens until you await it (Python) or call .fetch() (TypeScript).
Creating a Collection
Chaining
Every method returns a new Collection instance. The original is untouched
— useful when you conditionally modify a query before sending it, similar to
Django's QuerySet:
filter()
sort()
page()
include()
fields()
extra()
Non-standard query parameters:
Fetching
Pagination
After fetch, navigate pages:
col = await sdk.articles.list().page(1)
if col.has_next():
next_page = await col.get_next()
for article in next_page:
print(article.title)
# Iterate ALL pages
async for page in col.all_pages():
for article in page:
print(article.title)
# Iterate ALL items across all pages
async for article in col.all():
print(article.title)
const col = await sdk.articles.list().page(1).fetch();
if (col.hasNext()) {
const nextPage = await col.getNext().fetch();
for await (const article of nextPage) {
console.log(article.title);
}
}
// Iterate ALL pages
for await (const page of col.allPages()) {
for await (const article of page) {
console.log(article.title);
}
}
// Iterate ALL items across all pages
for await (const article of col.all()) {
console.log(article.title);
}
Navigation methods
| Method | Returns | Description |
|---|---|---|
has_next() |
bool |
Next page available? |
get_next() |
Collection |
Fetch next page |
has_previous() |
bool |
Previous page available? |
get_previous() |
Collection |
Fetch previous page |
has_first() |
bool |
First page link exists? |
get_first() |
Collection |
Fetch first page |
has_last() |
bool |
Last page link exists? |
get_last() |
Collection |
Fetch last page |
These operate on the links object from JSON:API responses. Server must include
pagination links (via Response(links={...})) for these to work.