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.4.0.tar.gz (9.5 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.4.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mawlaia_docparse-0.4.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/25.3.0

File hashes

Hashes for mawlaia_docparse-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8a630c58055e079b135df2916d447e26d6baad38de89faa14eb9525c5e16f134
MD5 133f189d6ee320511702774ae6e7f39b
BLAKE2b-256 042604eb5fc0af305131d3fe5970382f5f530c10f0aa6a8071e42af3fcb0326d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mawlaia_docparse-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/25.3.0

File hashes

Hashes for mawlaia_docparse-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30c4f26fb05d8a00c4ae59df2e653e1919e89b8ff30dc4058fcdfbee05f9fdae
MD5 32b5b9b3eaff715ad5cf25f93745b61d
BLAKE2b-256 db3a7173cc4d781d68d12b95bfded3a3978642abc70d23786ef824a1b54d7866

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