🚀 Quickstart: PageIndex SDK
To get started, visit the PageIndex Developer Dashboard and generate your API key .
Below is a brief introduction to using the Python SDK, including example code for common operations.
Install the SDK
pip install -U pageindexInitialize the Client
from pageindex import PageIndexClient
pi_client = PageIndexClient(api_key="YOUR_API_KEY")Submit a document
result = pi_client.submit_document("./2023-annual-report.pdf")
doc_id = result["doc_id"]Check processing status
status = pi_client.get_document(doc_id)["status"]
if status == "completed":
print('File processing completed')Once document processing is completed, the following services will be available.
PageIndex Chat API (beta)
Ask questions directly about one or more documents. The Chat API (beta) includes a full agentic, reasoning-based RAG workflow using PageIndex.
Chat with a specific document
You can chat with a specific document by providing a document ID with the query.
response = pi_client.chat_completions(
messages=[{"role": "user", "content": "What are the key findings in this document?"}],
doc_id="pi-abc123def456"
)
print(response["choices"][0]["message"]["content"])Want results instantly with streaming? See PageIndex Chat API (beta) for streaming responses.
You can also get a customized, agentic retrieval API by simply prompting the Chat API (beta). See this notebook for an example.
Chat with multiple documents
You can chat with multiple documents by providing a list of document IDs.
response = pi_client.chat_completions(
messages=[{"role": "user", "content": "Compare these two documents on the results"}],
doc_id=["pi-abc123def456", "pi-abc123ghi789"]
)
print(response["choices"][0]["message"]["content"])PageIndex Tree Generation
Get the PageIndex tree once processing is complete.
tree_result = pi_client.get_tree(doc_id)["result"]See PageIndex tree generation for more details.
Additional Features
Explore the full Python SDK Reference for more examples, including:
- PageIndex OCR: Transform PDF to structure-preserving markdown.