Skip to main content

Page Extract Python SDK

Python client for Page Extract by PageIndex: turn a PDF into JSON that fits your schema.

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_SEARCH_API_KEY=pis_live_...

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

Built distribution (wheel)

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

Total release size: 18.9 kB

Release files / pageindex_extract-0.1.0.tar.gz

Download URL pageindex_extract-0.1.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2a53380a42afc7c4c868aff882fd4fafd90c43e1397ae1ce400b80fc5f364ecd
BLAKE2b-256 checksum
How to use checksums
1608ac8148837bbae5c15e66867535039aed78450b40bf352e05a9d5629caec9
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.0-py3-none-any.whl

Download URL pageindex_extract-0.1.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f41153820d3ad8c4157e341aafb6f0aa46fe3314c04c8769ad15ebc6dc0a42ef
BLAKE2b-256 checksum
How to use checksums
c116e9b0edfbfd7bf145b7cac384607eb6f0a13b2e1460a9af6eb5fe621797d7
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.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