Skip to main content

pageindex-search

Python client for Page Search API by PageIndex. Upload a PDF, ask up to 10 questions at once, and get back the pages that answer each one, ranked by relevance. Every page is read.

pip install pageindex-search

Create an API key in the console and set it:

export PAGEINDEX_SEARCH_API_KEY=pis_live_...

Quick start

from pageindex_search import PageSearch

client = PageSearch()

doc = client.documents.upload("3M_2018_10K.pdf")
result = client.search(doc, ["What was capital expenditure in 2018?", "Who is the CEO?"])

for answer in result.results:
    print(answer.question)
    for page in answer.pages:
        print(f"  page {page.page}: {page.relevance}")

print(f"cost ${result.usage.cost_usd}, credit left ${result.usage.balance_usd}")

Upload a document once and search it as often as you like; uploading the same file again returns the same document. Documents are kept until you delete them:

for doc in client.documents.list():  # every document, newest first, a page at a time
    print(doc.id, doc.filename, doc.pages)

client.search("doc_60a07bcef3094b68806070f2", ["What was revenue in 2018?"])  # search one again by its id
client.documents.delete("doc_60a07bcef3094b68806070f2")

With many documents, first find the ones that answer a question, then search their pages:

found = client.documents.search("What was capital expenditure in 2018?")  # every document of yours
for match in found.results[0].documents:
    print(match.filename, match.relevance)
    client.search(match.document_id, ["What was capital expenditure in 2018?"])

Group documents into collections, and search within one:

reports = client.collections.create("Annual reports")
client.documents.upload("3M_2018_10K.pdf", collection=reports)  # or later: client.collections.add(reports, [doc])
found = client.documents.search("What was capital expenditure in 2018?", collection=reports)

A document may be in many collections; deleting a collection leaves its documents.

Give documents your own metadata (strings, numbers and booleans) and filter by it:

doc = client.documents.upload("3M_2018_10K.pdf", metadata={"ticker": "MMM", "year": 2018})
client.documents.update(doc, metadata={"audited": True})          # None removes a key
recent = client.documents.list(filter={"year": {"$gte": 2020}})
found = client.documents.search("Who is the CEO?", filter={"ticker": {"$in": ["MMM", "AAPL"]}})

Filters take $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $and and $or.

Reference

PageSearch(api_key=None, base_url=None, timeout=120, max_retries=2) The key defaults to PAGEINDEX_SEARCH_API_KEY.
documents.upload(file, collection=None, metadata=None, wait=True) A path, bytes or an open file. Returns a Document, ready to search unless wait=False.
search(document, questions, top_k=None, idempotency_key=None) Up to 10 questions. Each answer lists the pages likely to help (possibly none), or exactly top_k. A search retried after a timeout is not charged twice.
documents.search(questions, document_ids=None, collection=None, filter=None, top_k=None, idempotency_key=None) Up to 10 questions of your documents (all of them, up to 1,000, those named, or a collection's). Each answer lists the documents likely to hold it, or exactly top_k. Each document is priced as a page.
documents.list(limit=20, after=None, collection=None, filter=None) Your documents, newest first, or a collection's, or those whose metadata meets filter. Loop over it for every document; .data and .has_more are one page.
documents.get(id), documents.delete(document) One document; delete one.
documents.update(document, metadata=) Set metadata keys; None removes one.
collections.create(name), .list(), .get(id), .rename(collection, name), .delete(collection) Named groups of your documents. Deleting one leaves its documents.
collections.add(collection, documents), .remove(collection, document) Put documents in a collection, or take one out. documents.upload(..., collection=) puts a new one in.
usage(start=None, end=None) Uploads, searches and cost by day, your credit and stored pages.

Before 0.2 these were upload(), document(), documents(), iter_documents() and delete() on the client; they still work, with a warning, for now.

Errors raise PageSearchError, with the API's status, code, message and request_id.

See the API reference for every field and the pricing.

Metadata

Release files for pageindex-search 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pageindex-search 0.3.0
File Size Uploaded Provenance Actions
pageindex_search-0.3.0.tar.gz 11.1 kB Without provenance Details for pageindex_search-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pageindex-search 0.3.0
File Interpreter ABI Platform Actions
pageindex_search-0.3.0-py3-none-any.whl Python 3 none any Details for pageindex_search-0.3.0-py3-none-any.whl

Total release size: 21.5 kB

Release files / pageindex_search-0.3.0.tar.gz

Download URL pageindex_search-0.3.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
039c61aef0ca531c9159781cde30a27a10d75902a0e4a5b65bd1432eeaa3be92
BLAKE2b-256 checksum
How to use checksums
457b503a7d4dfc013ea2c39ed5308bd6c760befc9d58faddc6cd666673d432fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pageindex_search-0.3.0-py3-none-any.whl

Download URL pageindex_search-0.3.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f082546d1a5bee79a1bb20665984773b8a15863ad9ca27a1a509954416cc2117
BLAKE2b-256 checksum
How to use checksums
38667968aa6a58f57bd313ebfb0aea392ea2b72a2cfd8c11a27482e24ab007ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pageindex-search 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page