Skip to main content

Official Python SDK for Invoice Data Extraction.

Project description

invoicedataextraction-sdk

Official Python SDK for Invoice Data Extraction. Handles file upload, extraction submission, polling, and result download so you can go from local files to structured output in a few lines of code.

  • Python 3.9 or later

Install

pip install invoicedataextraction-sdk

Quick Start

import json
import os
import sys

from invoicedataextraction import InvoiceDataExtraction
from invoicedataextraction.errors import SdkError, ApiResponseError

try:
    client = InvoiceDataExtraction(
        api_key=os.environ.get("INVOICE_DATA_EXTRACTION_API_KEY"),
    )

    result = client.extract(
        folder_path="./invoices",
        prompt="Extract invoice number and total",
        output_structure="per_invoice",
        download={
            "formats": ["xlsx", "json"],
            "output_path": "./output",
        },
        console_output=True,  # remove to disable console logging
    )
except (SdkError, ApiResponseError) as error:
    print(json.dumps(error.body, indent=2), file=sys.stderr)
    raise SystemExit(1)

extract(...) uploads your files (pass a folder_path or a list of files), submits the extraction, polls until it finishes, and downloads the results. The returned result is the final polling response from the API. For completed responses, check result["pages"]["failed_count"] to verify that all uploaded pages were processed successfully, and check result["review_needed"]["count"] for any extracted values that require human verification before relying on the extracted data.

Generate an API key from your dashboard. Every account includes 50 free pages per month. Additional credits can be purchased on a pay-as-you-go basis with no subscription needed.

Staged Workflow

If you need control over individual steps — for example, uploading files in one part of your system and extracting in another — use the lower-level methods:

import json
import os
import sys

from invoicedataextraction import InvoiceDataExtraction
from invoicedataextraction.errors import SdkError, ApiResponseError

try:
    client = InvoiceDataExtraction(
        api_key=os.environ.get("INVOICE_DATA_EXTRACTION_API_KEY"),
    )

    upload = client.upload_files(
        files=["./invoice1.pdf", "./invoice2.pdf"],
        console_output=True,
    )

    submitted = client.submit_extraction(
        upload_session_id=upload["upload_session_id"],
        file_ids=upload["file_ids"],
        prompt="Extract invoice number and total",
        output_structure="per_invoice",
    )

    result = client.wait_for_extraction_to_finish(
        extraction_id=submitted["extraction_id"],
        console_output=True,
    )

    client.download_output(
        extraction_id=submitted["extraction_id"],
        format="xlsx",
        file_path="./output/invoices.xlsx",
    )
except (SdkError, ApiResponseError) as error:
    print(json.dumps(error.body, indent=2), file=sys.stderr)
    raise SystemExit(1)

Listing past extractions

# One-page browse with filters
page = client.list_extractions(
    status="completed",
    limit=50,
)

# Auto-paginating iterator over every matching extraction
for extraction in client.iterate_extractions(status="completed"):
    print(extraction["extraction_id"], extraction["task_name"])

# Full record (the original prompt, options, full pages, full failure error, etc.)
result = client.get_extraction(extraction_id="...")
extraction = result["extraction"]

On listing methods, team admins can pass scope="team" to see extractions submitted by any team member; pass scope="own" to force own-only results.

Error Handling

SDK methods raise SdkError or ApiResponseError on failure. The structured error body is on error.body, with fields error.body["error"]["code"], error.body["error"]["message"], error.body["error"]["retryable"], and error.body["error"]["details"].

When an extraction task itself reaches a terminal state, extract(...) returns that response rather than raising — check result["status"] for "completed", "failed", or "cancelled" for tasks cancelled from the web app. See the full docs for details.

Documentation

  • Python SDK docs — full method reference, parameters, return shapes, and examples
  • REST API docs — endpoint-level documentation for direct HTTP integration
  • Dashboard — manage API keys and view extraction results

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

invoicedataextraction_sdk-0.3.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

invoicedataextraction_sdk-0.3.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file invoicedataextraction_sdk-0.3.0.tar.gz.

File metadata

File hashes

Hashes for invoicedataextraction_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 04e55ee24fc1c26f1a8ec018cf0d866bfc467548be9f23e282fe2a90ba7e0572
MD5 6f5d0774bb8460248be58bbc6f073e07
BLAKE2b-256 ad6855c57977b63b7aad520675f0d9b23f9879dae7956d771b728b3d3bd2a73f

See more details on using hashes here.

File details

Details for the file invoicedataextraction_sdk-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for invoicedataextraction_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f7383e05d416809cfcd0a9c5a5c66969b9abbcc95eb8e5fae5b96b7bab5f72d
MD5 ac91b931c654ffac7c0fb67d54e5e3e3
BLAKE2b-256 6312efce035c8cc571adfb1b8b9db3a77357408b7d16ff17b41e067419580fe2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page