SDKsPython

Pagination

How Page and AsyncPage work in the BimpeAI Python SDK, and how to walk items and pages.

Every list call returns a Page (or AsyncPage on the async client). A page carries the items for the current page in data, the meta block, and the request_id of the response that produced it. The meta is a PaginationMeta with total_count, page_count, current_page, limit, has_next_page, and has_previous_page.

page = client.agents.list(limit=50)
page.data            # list[Agent] for this page
page.meta.total_count if page.meta else 0
page.request_id      # str | None
page.has_next_page   # bool
next_page = page.get_next_page()  # Page[Agent] | None

Iterating items

Iterating a page directly walks every item across every page, fetching the next page only when the current one runs out.

for agent in client.agents.list(limit=50):
    print(agent.id)

Iterating pages

If you want the page objects rather than the items, iterate pages().

for page in client.agents.list().pages():
    print(page.meta.current_page if page.meta else None)

Async client

On the async client these become async for and await page.get_next_page().

page = await client.agents.list(limit=50)
async for agent in page:
    print(agent.id)

async for page in page.pages():
    print(page.meta.current_page if page.meta else None)

next_page = await page.get_next_page()

On this page