Home / Class/ AsyncPaginator Class — anthropic-sdk-python Architecture

AsyncPaginator Class — anthropic-sdk-python Architecture

Architecture documentation for the AsyncPaginator class in _base_client.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  8a2fd582_0e13_b770_3de8_662dc0099099["AsyncPaginator"]
  31e60ad8_cac8_652d_176d_4f7cf7dda1ad["_base_client.py"]
  8a2fd582_0e13_b770_3de8_662dc0099099 -->|defined in| 31e60ad8_cac8_652d_176d_4f7cf7dda1ad
  14f27025_f0f1_9ae9_62fa_a3517630739c["__init__()"]
  8a2fd582_0e13_b770_3de8_662dc0099099 -->|method| 14f27025_f0f1_9ae9_62fa_a3517630739c
  bec059de_83fa_8b84_1ea2_cbdbdf2a5190["__await__()"]
  8a2fd582_0e13_b770_3de8_662dc0099099 -->|method| bec059de_83fa_8b84_1ea2_cbdbdf2a5190
  9d7a9d91_d8ce_9c6f_5c77_1481991f47f3["_get_page()"]
  8a2fd582_0e13_b770_3de8_662dc0099099 -->|method| 9d7a9d91_d8ce_9c6f_5c77_1481991f47f3
  71a12105_266c_75c1_4659_d05fb5340298["__aiter__()"]
  8a2fd582_0e13_b770_3de8_662dc0099099 -->|method| 71a12105_266c_75c1_4659_d05fb5340298

Relationship Graph

Source Code

src/anthropic/_base_client.py lines 284–320

class AsyncPaginator(Generic[_T, AsyncPageT]):
    def __init__(
        self,
        client: AsyncAPIClient,
        options: FinalRequestOptions,
        page_cls: Type[AsyncPageT],
        model: Type[_T],
    ) -> None:
        self._model = model
        self._client = client
        self._options = options
        self._page_cls = page_cls

    def __await__(self) -> Generator[Any, None, AsyncPageT]:
        return self._get_page().__await__()

    async def _get_page(self) -> AsyncPageT:
        def _parser(resp: AsyncPageT) -> AsyncPageT:
            resp._set_private_attributes(
                model=self._model,
                options=self._options,
                client=self._client,
            )
            return resp

        self._options.post_parser = _parser

        return await self._client.request(self._page_cls, self._options)

    async def __aiter__(self) -> AsyncIterator[_T]:
        # https://github.com/microsoft/pyright/issues/3464
        page = cast(
            AsyncPageT,
            await self,  # type: ignore
        )
        async for item in page:
            yield item

Frequently Asked Questions

What is the AsyncPaginator class?
AsyncPaginator is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_base_client.py.
Where is AsyncPaginator defined?
AsyncPaginator is defined in src/anthropic/_base_client.py at line 284.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free