How Paginator and AsyncPaginator work
mainSome SDK operations return results in pages rather than a single list. To handle this, the SDK provides Paginator (for synchronous code) and AsyncPaginator (for asynchronous code). These objects allow you to iterate over results lazily, fetching subsequent pages only when requested.
Both paginators support the following interface:
__iter__/__aiter__: Iterate over individual items across all pages sequentially..pages(): Iterate overPageobjects instead of individual items..to_list(): Fetch all items from all pages into a single list in one call..pagination_token: Access the token for the next page; returnsNonewhen all pages have been consumed.
# Sync example: iterating over items
from pinecone import Pinecone
pc = Pinecone()
for assistant in pc.assistants.list():
print(assistant.name)
# Async example: iterating over items
import asyncio
from pinecone import AsyncPinecone
async def main() -> None:
async with AsyncPinecone() as pc:
async for assistant in pc.assistants.list():
print(assistant.name)
asyncio.run(main())