Skip to main content

LLM-powered document extraction SDK

Project description

docparse

LLM-powered document extraction SDK. Extract structured data from PDFs, invoices, contracts, and any custom schema — in two lines of Python.

from docparse import LLMExtractor, load, INVOICE_SCHEMA

layout = load("invoice.pdf")                        # or from_text("...")
result = LLMExtractor().extract(layout, INVOICE_SCHEMA)

print(result.get("total_amount"))        # 1500.0
print(result.confidence("vendor_name"))  # 0.97

Installation

pip install docparse                # core (text files only)
pip install "docparse[pdf]"         # + PDF support via pdfplumber
pip install "docparse[openai]"      # + OpenAI provider
pip install "docparse[anthropic]"   # + Anthropic provider
pip install "docparse[all]"         # everything

Quickstart

from docparse import LLMExtractor, from_text, INVOICE_SCHEMA

layout = from_text("""
INVOICE #INV-2024-042
Vendor: Acme Corp
Date: 2024-03-15
Total: $1,500.00
""")

extractor = LLMExtractor(model="gpt-4o-mini", provider="openai")
result = extractor.extract(layout, INVOICE_SCHEMA)

for field_name in INVOICE_SCHEMA.field_names():
    value = result.get(field_name)
    conf  = result.confidence(field_name)
    if value is not None:
        print(f"{field_name}: {value}  (confidence: {conf:.0%})")

Built-in schemas

Schema constant Key Fields
INVOICE_SCHEMA invoice 12 fields — amounts, dates, vendor, line items
LOAN_APPLICATION_SCHEMA loan_application 12 fields — borrower, amounts, property
W2_SCHEMA w2 8 fields — employer, wages, withholdings
NDA_SCHEMA nda 8 fields — parties, term, jurisdiction
CONTRACT_SCHEMA contract 9 fields — parties, dates, obligations

Access any by key: from docparse import REGISTRY; schema = REGISTRY["invoice"]

Custom schemas

from docparse import ExtractionSchema, FieldSpec, LLMExtractor, from_text

schema = ExtractionSchema(name="purchase_order", fields=[
    FieldSpec(name="po_number",     description="PO number",         required=True),
    FieldSpec(name="total",         description="Total amount",       type="number", required=True, example="4200.00"),
    FieldSpec(name="delivery_date", description="Expected delivery",  type="date"),
])

result = LLMExtractor().extract(from_text(po_text), schema)
missing = result.missing_required(schema)

CLI

docparse extract invoice.pdf --schema invoice
docparse extract contract.txt --schema nda --json
docparse schemas          # list available schemas

Providers

# OpenAI (default)
LLMExtractor(model="gpt-4o-mini", provider="openai")

# Anthropic
LLMExtractor(model="claude-3-5-haiku-20241022", provider="anthropic")

License

MIT © Mawlaia

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

mawlaia_docparse-0.3.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

mawlaia_docparse-0.3.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mawlaia_docparse-0.3.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mawlaia_docparse-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b2b833aafbd25c451a51c1c306339d746dbd47dd47f307b7246ec31a077ae0b6
MD5 c9ad02def71458017c08cc585c6768fa
BLAKE2b-256 2865f15a9b58fa541e6a199aa8ffce2649889dd6cc8888a2e7d9b54a18b4475e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mawlaia_docparse-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02399eb4b1c321cb3c42593f9cc8e43eb001ca5431434b756060ddb86d2c676d
MD5 7d9eb5c7060894999bd4aec489a40c1f
BLAKE2b-256 15fd14036dadd3c6c12e0d4363e21eb7676dd5e829b2dc10a2a94d3c9bd2b7c4

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