docs/guides/pagination.md
Some SDK operations return results in pages. The SDK provides Paginator (sync) and
AsyncPaginator (async) to iterate over those pages lazily — only fetching the next
page when you ask for it.
Both classes share the same interface:
| Member | Description |
|---|---|
__iter__ / __aiter__ | Iterate over individual items across all pages |
.pages() | Iterate over Page objects rather than individual items |
.to_list() | Fetch all items into a list in one call |
.pagination_token | Token for the next page; None when all pages have been consumed |
::::{tabs} :::{tab} Sync
from pinecone import Pinecone
pc = Pinecone()
for assistant in pc.assistants.list():
print(assistant.name)
::: :::{tab} Async
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())
::: ::::
::::{tabs} :::{tab} Sync
for page in pc.assistants.list().pages():
print(f"Page has {len(page.items)} items")
for assistant in page.items:
print(assistant.name)
if not page.has_more:
break
::: :::{tab} Async
async with AsyncPinecone() as pc:
async for page in pc.assistants.list().pages():
print(f"Page has {len(page.items)} items")
for assistant in page.items:
print(assistant.name)
::: ::::
::::{tabs} :::{tab} Sync
all_assistants = pc.assistants.list().to_list()
::: :::{tab} Async
async with AsyncPinecone() as pc:
all_assistants = await pc.assistants.list().to_list()
::: ::::
Each page yielded by .pages() has two attributes:
| Attribute | Type | Description |
|---|---|---|
items | list[T] | The items on this page |
pagination_token | str | None | Opaque token to fetch the next page; None on the last page |
has_more | bool | True if more pages are available |
Pass limit to cap the total number of items returned across all pages:
# Return at most 50 assistants total
for assistant in pc.assistants.list(limit=50):
print(assistant.name)
Save pagination_token to resume iteration later:
paginator = pc.assistants.list()
first_page = next(paginator.pages())
# Store the token
token = first_page.pagination_token
# Later: resume from where you left off
from pinecone.models.pagination import Paginator
# (pass initial_token when constructing directly)
Index.list_paginated() returns a ListResponse for a single page of vector IDs.
Use it directly when you need fine-grained control over pagination tokens:
from pinecone import Pinecone
pc = Pinecone()
desc = pc.indexes.describe("product-search")
index = pc.index(host=desc.host)
# Fetch the first page
page = index.list_paginated(prefix="product#", limit=100)
for item in page.vectors:
print(item.id)
# Fetch subsequent pages
while page.pagination is not None and page.pagination.next is not None:
page = index.list_paginated(
prefix="product#",
limit=100,
pagination_token=page.pagination.next,
)
for item in page.vectors:
print(item.id)
Not every list operation uses a paginator. pc.indexes.list() returns an IndexList
directly — it contains all indexes in a single response with no pagination token.
result = pc.indexes.list()
for index in result.indexes:
print(index.name)