Pagination

class atproto_client.utils.pagination.PaginatedResponse(*args, **kwargs)

Bases: Protocol[T_co]

Response of a cursor-paginated method.

Every generated Response model of a query that takes and returns a cursor implements it.

property cursor: str | None
get_page_items() → Sequence[T_co]
class atproto_client.utils.pagination.Paginator(method: Callable[[...], Any], params: Any, max_pages: int | None, kwargs: Any)

Bases: _PaginatorBase, Generic[ResponseT_co]

Lazy iterator over the pages of a cursor-paginated method. Created by paginate().

Iterating again continues after the last fetched page, so an interrupted loop can be resumed.

items() → Iterator[T]

Iterate over the items of all pages.

class atproto_client.utils.pagination.AsyncPaginator(method: Callable[[...], Any], params: Any, max_pages: int | None, kwargs: Any)

Bases: _PaginatorBase, Generic[ResponseT_co]

Lazy async iterator over the pages of a cursor-paginated method. Created by paginate().

Iterating again continues after the last fetched page, so an interrupted loop can be resumed.

async items() → AsyncIterator[T]

Iterate over the items of all pages.

atproto_client.utils.pagination.paginate(method: Callable[[...], Awaitable[ResponseT]], params: Any = None, *, max_pages: int | None = None, **kwargs: Any) → AsyncPaginator[ResponseT]
atproto_client.utils.pagination.paginate(method: Callable[[...], ResponseT], params: Any = None, *, max_pages: int | None = None, **kwargs: Any) → Paginator[ResponseT]

Iterate over all pages of a cursor-paginated method.

Pages are fetched lazily, one request per page, until the server returns no cursor or max_pages pages are fetched. Collecting everything can take many requests and hit rate limits.

Example

>>> from atproto import Client, client_utils
>>> client = Client()
>>> for profile in client_utils.paginate(client.app.bsky.graph.get_follows, {'actor': 'atproto.com'}).items():
...     print(profile.handle)
Parameters:
  • method – Namespace method of a paginated query, e.g. client.app.bsky.graph.get_follows. Async methods return AsyncPaginator.

  • params – Parameters of the method, as a model or a dict. A cursor in them sets the first page.

  • max_pages – Maximum number of pages to fetch.

  • **kwargs – Arbitrary arguments to HTTP request.

Returns:

Paginator or AsyncPaginator over the response models. Use .items() to iterate over the page items instead.