BaseSyncPage Class — anthropic-sdk-python Architecture
Architecture documentation for the BaseSyncPage class in _base_client.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD c0f008e5_ad6e_1b9d_0800_826eae176f95["BaseSyncPage"] 31e60ad8_cac8_652d_176d_4f7cf7dda1ad["_base_client.py"] c0f008e5_ad6e_1b9d_0800_826eae176f95 -->|defined in| 31e60ad8_cac8_652d_176d_4f7cf7dda1ad e150825c_d273_74d9_8c92_a32cb6cd5ef0["_set_private_attributes()"] c0f008e5_ad6e_1b9d_0800_826eae176f95 -->|method| e150825c_d273_74d9_8c92_a32cb6cd5ef0 2c4da4ef_7964_9e36_1a27_ae34aeee40e6["__iter__()"] c0f008e5_ad6e_1b9d_0800_826eae176f95 -->|method| 2c4da4ef_7964_9e36_1a27_ae34aeee40e6 d9e752cd_a96a_d446_3674_d1eb9c8808b6["iter_pages()"] c0f008e5_ad6e_1b9d_0800_826eae176f95 -->|method| d9e752cd_a96a_d446_3674_d1eb9c8808b6 f2d28c81_dfd4_1ffe_b1b5_5248a43a1ab5["get_next_page()"] c0f008e5_ad6e_1b9d_0800_826eae176f95 -->|method| f2d28c81_dfd4_1ffe_b1b5_5248a43a1ab5
Relationship Graph
Source Code
src/anthropic/_base_client.py lines 235–281
class BaseSyncPage(BasePage[_T], Generic[_T]):
_client: SyncAPIClient = pydantic.PrivateAttr()
def _set_private_attributes(
self,
client: SyncAPIClient,
model: Type[_T],
options: FinalRequestOptions,
) -> None:
if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
self.__pydantic_private__ = {}
self._model = model
self._client = client
self._options = options
# Pydantic uses a custom `__iter__` method to support casting BaseModels
# to dictionaries. e.g. dict(model).
# As we want to support `for item in page`, this is inherently incompatible
# with the default pydantic behaviour. It is not possible to support both
# use cases at once. Fortunately, this is not a big deal as all other pydantic
# methods should continue to work as expected as there is an alternative method
# to cast a model to a dictionary, model.dict(), which is used internally
# by pydantic.
def __iter__(self) -> Iterator[_T]: # type: ignore
for page in self.iter_pages():
for item in page._get_page_items():
yield item
def iter_pages(self: SyncPageT) -> Iterator[SyncPageT]:
page = self
while True:
yield page
if page.has_next_page():
page = page.get_next_page()
else:
return
def get_next_page(self: SyncPageT) -> SyncPageT:
info = self.next_page_info()
if not info:
raise RuntimeError(
"No next page expected; please check `.has_next_page()` before calling `.get_next_page()`."
)
options = self._info_to_options(info)
return self._client._request_api_list(self._model, page=self.__class__, options=options)
Domain
Defined In
Source
Frequently Asked Questions
What is the BaseSyncPage class?
BaseSyncPage is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_base_client.py.
Where is BaseSyncPage defined?
BaseSyncPage is defined in src/anthropic/_base_client.py at line 235.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free