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=pie_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_..."). A file is uploaded to the Page Extract collection (made on first use), where it is kept apart from documents you upload to search; pass collection="..." (a name or an id) for another, or collection=None for none. A file already in that collection is not uploaded again.

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.2

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.2
File Size Uploaded Provenance Actions
pageindex_extract-0.1.2.tar.gz 10.8 kB Without provenance Details for pageindex_extract-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 20.4 kB

Release files / pageindex_extract-0.1.2.tar.gz

Download URL pageindex_extract-0.1.2.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2757a2239e4d2618410e428f376fcc129c2d99a5c89b85e38a7bec0e364a4549
BLAKE2b-256 checksum
How to use checksums
5d0c9f4519e6ee7aba8f729ac0043093bd44abcc88bd5f379b245b141d634d0f
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.2-py3-none-any.whl

Download URL pageindex_extract-0.1.2-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0084e02e617c46d0197bfcd1b6237490e91e6f5b7b436584b121aef3c1432d74
BLAKE2b-256 checksum
How to use checksums
bd72ac250b469fd75ba90027459ef7398fdc96cda7e5fc0d798bd422d371d0c1
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.2

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