Skip to main content

Page Extract Python SDK

Python client for Page Extract by PageIndex: extract the data you need out of any PDF.

pip install pageindex-extract

Create an API key in the console. Page Extract and Page Search share one key, one credit balance and one set of documents.

export PAGEINDEX_EXTRACT_API_KEY=pis_live_...

The client reads PAGEINDEX_EXTRACT_API_KEY, or PAGEINDEX_SEARCH_API_KEY if you already keep the key there.

Extract

from pageindex_extract import PageExtract

client = PageExtract()

schema = {
    "type": "object",
    "properties": {
        "invoice_number": {"type": "string"},
        "total": {"type": "number", "description": "Amount due, in dollars, without the currency sign"},
        "lines": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {"item": {"type": "string"}, "amount": {"type": "number"}},
            },
        },
    },
}

job = client.extract("invoice.pdf", schema)
print(job.result)

extract uploads the file (a file uploaded before is not uploaded again), waits for the extraction and returns it. job.result is JSON that fits your schema; a field the document does not give is null.

The schema can also be a Pydantic model:

from pydantic import BaseModel

class Line(BaseModel):
    item: str
    amount: float

class Invoice(BaseModel):
    invoice_number: str
    total: float
    lines: list[Line]

job = client.extract("invoice.pdf", Invoice)
invoice = job.parse(Invoice)

Options

job = client.extract(
    "report.pdf",
    schema,
    tier="pro",            # "standard" ($0.03 a page) or "pro" ($0.05 a page)
    pages="3-9",           # only these pages, and only they are charged; also (3, 9) or 3
    cite_sources=True,     # the page each list item is on: job.sources
    system_prompt="Amounts are in thousands of dollars.",
)
print(job.usage.pages, job.usage.credits)

document can be a path, bytes, an open binary file, an uploaded document, or a document id ("doc_...").

You pay only for extractions that complete. A failed extraction raises PageExtractError (its job holds the job) and costs nothing.

Jobs

Extractions run in the background. To start one and come back for it later:

job = client.extract("report.pdf", schema, wait=False)   # PENDING
job = client.jobs.wait(job)                              # COMPLETED, or raises

client.jobs.get(job.id)          # the job, with its result once COMPLETED
client.jobs.cancel(job.id)       # stop it; nothing is charged
client.jobs.delete(job.id)       # delete it and its result

for job in client.jobs.list():   # every extraction, newest first
    print(job.id, job.status)

Documents

client.documents is the Page Search client's, with the same key:

doc = client.documents.upload("report.pdf")
job = client.extract(doc, schema)

Errors

Errors raise PageExtractError with status, code, message and request_id.

Code When
unauthorized The API key is missing or not valid.
insufficient_credit Your credit does not cover the pages. Add credit in the console.
invalid_schema The schema is not valid JSON Schema, or its top is not an object.
schema_too_large The schema is larger than 1 MB.
invalid_target_pages pages is not within the document.
document_not_found No such document.
job_not_found No such job.
job_failed / job_cancelled The extraction failed or was cancelled. Nothing is charged.
timeout wait gave up; the job goes on running.

License

MIT

Metadata

Release files for pageindex-extract 0.1.1

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-extract 0.1.1
File Size Uploaded Provenance Actions
pageindex_extract-0.1.1.tar.gz 10.1 kB Without provenance Details for pageindex_extract-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pageindex-extract 0.1.1
File Interpreter ABI Platform Actions
pageindex_extract-0.1.1-py3-none-any.whl Python 3 none any Details for pageindex_extract-0.1.1-py3-none-any.whl

Total release size: 19.3 kB

Release files / pageindex_extract-0.1.1.tar.gz

Download URL pageindex_extract-0.1.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4b1d67510737adca1da732468af29fb27c9e7bd899f9c25d5f0605cb3ce62caf
BLAKE2b-256 checksum
How to use checksums
99d346681773f792991bcd065c0f74d2204ed88d34f82d80300b5ef07a5772cb
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_extract-0.1.1-py3-none-any.whl

Download URL pageindex_extract-0.1.1-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
405115725f5fe913ccf7e8e50d30945af685f059da55eba08009a22fb9b08ae1
BLAKE2b-256 checksum
How to use checksums
d82bfd1a374994f5511dacffc7523025c6f748e0a65d2d73bb65cb2c08f40eb7
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-extract 0.1.1

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