Skip to main content

Python SDK for the Qomplement StructDatafy API — extract structured data from documents and fill forms with AI.

Project description

qomplement

Python SDK for the Qomplement StructDatafy API — extract structured data from documents and fill PDF/Excel forms with AI.

Installation

pip install qomplement

Quick Start

from qomplement import Qomplement

client = Qomplement("sd_your_api_key")

# Extract data from any document
result = client.extract("invoice.pdf")
print(result.fields)
# {'invoice_number': '12345', 'client_name': 'Acme Corp', 'total': '$5,000.00'}
print(result.tables)
print(result.document_type)  # 'invoice'
print(result.confidence)     # 94

Extract

# Basic extraction
result = client.extract("document.pdf")

# With full detail (entities, summary, primary/secondary entities)
result = client.extract("document.pdf", detail=True)
print(result.detail["entities"])
print(result.detail["summary"])

# Guided extraction with schema
schema = [
    {"name": "invoice_number", "type": "string"},
    {"name": "total_amount", "type": "number"},
    {"name": "vendor_name", "type": "string"},
]
result = client.extract("invoice.pdf", schema=schema)

# Extract with text chunking
result = client.extract("long_document.pdf", chunk_size=1000, chunk_overlap=200)
for chunk in result.chunks:
    print(chunk["text"])

# From bytes
with open("document.pdf", "rb") as f:
    result = client.extract(f.read(), filename="document.pdf")

Fill PDF

# Fill using source documents (AI extracts and maps fields)
result = client.fill_pdf(
    "form.pdf",
    source="invoice.pdf",
)
result.save("filled_form.pdf")

# Fill with natural language instructions
result = client.fill_pdf(
    "contract.pdf",
    instructions="Fill client name as 'Acme Corporation' and date as January 15, 2024",
)
result.save("filled_contract.pdf")

# Fill with explicit field mappings
result = client.fill_pdf(
    "form.pdf",
    field_mappings={"client_name": "Acme Corp", "date": "2024-01-15"},
)
result.save("filled_form.pdf")

print(f"Filled {result.fields_filled}/{result.fields_total} fields")

Fill Excel

# Fill Excel template from source documents
result = client.fill_excel(
    "template.xlsx",
    source="invoice.pdf",
)
result.save("filled_template.xlsx")

# Fill with instructions
result = client.fill_excel(
    "template.xlsx",
    instructions="Add company name as Acme Corp in the header",
)
result.save("filled.xlsx")

Async Jobs

Large documents (>5 pages) are processed asynchronously. By default, the SDK polls and waits for completion:

# This automatically waits for completion (default: wait=True)
result = client.extract("large_document.pdf")

# Get a job reference without waiting
job = client.extract("large_document.pdf", wait=False)
print(job.id)      # job ID
print(job.status)  # 'processing'

# Check job status later
job = client.get_job(job.id)
if job.status == "completed":
    print(job.result)

# List your jobs
jobs = client.list_jobs(status="completed", limit=10)

Usage

usage = client.usage()
print(f"Requests: {usage.requests}")
print(f"Pages processed: {usage.pages_processed}")

# Usage for a specific month
usage = client.usage(period="2026-02")

Supported Formats

formats = client.formats()
print(formats["total_formats"])  # 33

# List available models
models = client.models()
for m in models:
    print(f"{m['id']}: {m['description']}")

The API supports 33+ file formats including PDF, DOCX, XLSX, PPTX, CSV, TXT, RTF, images (PNG, JPEG, HEIC, TIFF), and legacy formats (DOC, XLS, PPT).

Configuration

# API key from environment variable
import os
os.environ["QOMPLEMENT_API_KEY"] = "sd_your_api_key"
client = Qomplement()

# Custom base URL
client = Qomplement("sd_your_api_key", base_url="https://developer-api-testing.qomplement.com")

# Custom timeout and max wait
client = Qomplement("sd_your_api_key", timeout=120, max_wait=300)

Error Handling

from qomplement import Qomplement, AuthenticationError, RateLimitError, ValidationError

client = Qomplement("sd_your_api_key")

try:
    result = client.extract("document.pdf")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except ValidationError as e:
    print(f"Invalid request: {e}")

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

qomplement-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

qomplement-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file qomplement-0.1.0.tar.gz.

File metadata

  • Download URL: qomplement-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for qomplement-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe93170739f45a99272b6115089ad31f5d6898254672a51c7ac01b184b2ea9e2
MD5 852d1062785681eaebabc921bc323cfd
BLAKE2b-256 489e217afa2b72e9165b50771581bc35f4dac308d99293535197bdadd28e7ae6

See more details on using hashes here.

File details

Details for the file qomplement-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qomplement-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for qomplement-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95e70fffcb3bbd63b0e732ff68f03318771a5bf2ca2b0d5af040695bc5059738
MD5 fa7a6d2a502da8ede68dd81325ec8423
BLAKE2b-256 7031049966ae9d5a6db58615b0a5eb7efb3320cf369df32851f4f648ff238d11

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