Pagination

Iterating a list method walks every page. The page object also exposes one page at a time when you want the cursor yourself.

List methods return a page object rather than a plain list. Iterating it walks every page, fetching each one as you reach it:

import os

from ellipsis import Ellipsis

client = Ellipsis(api_key=os.environ["ELLIPSIS_API_TOKEN"])

for session in client.sessions.list():
    print(session.id, session.status)

That loop makes as many requests as there are pages. Nothing accumulates in memory beyond the current page, so it is safe over a long history.

One page at a time

The page object exposes the current page directly, which is what you want when you are paging a UI or storing a cursor between runs:

page = client.sessions.list(limit=25)
for session in page.items:
    print(session.id)

if page.has_more:
    next_page = client.sessions.list(limit=25, cursor=page.next_cursor)

items is the current page's list, has_more says whether another page exists, and next_cursor is the cursor to pass for it. Attributes of the underlying response are readable straight off the page object, so page.total works when the response defines it.

Which methods paginate

The spec decides: a route paginates when its response carries a next_cursor. Today that is sessions.list, sessions.records, reviews.list, alerts.list, and files.list. Every one of them accepts cursor and limit.

Methods that do not paginate return their response model directly. sessions.search is one of them: it returns ranked matches, not a cursored feed.

Async

Async list methods return an async page, iterated with async for:

import os

from ellipsis import AsyncEllipsis

async with AsyncEllipsis(api_key=os.environ["ELLIPSIS_API_TOKEN"]) as client:
    page = await client.sessions.list()
    async for session in page:
        print(session.id)

Awaiting the method fetches the first page; the async for then walks the rest.

On this page