The Python SDK for Invoice Data Extraction

Convert unstructured invoices into structured JSON, including line items, in seconds, eliminating manual data entry.

Why Production-Ready Invoice OCR is Difficult

Open-source tools like Tesseract fail in production because invoices lack a standard format. Each vendor uses a unique layout, making template-based or regex-based parsing brittle and costly to maintain. Core challenges include accurately identifying and extracting tabular data (line items) which can span multiple pages, parsing various date formats (MM/DD/YY vs DD-MM-YYYY), and handling low-quality inputs from scanners which introduce skew, rotation, and digital noise. This forces engineering teams into a perpetual cycle of building and fixing custom parsers for each new vendor, a fundamentally unscalable approach.

Enterprise-Grade Extraction with StructOCR

StructOCR leverages pre-trained Deep Learning models engineered for invoice and receipt documents, offering a powerful accounts payable ocr solution. Our API bypasses template dependency by understanding document semantics. All inputs undergo automatic image pre-processing for deskewing and denoising. The models then precisely identify key-value pairs and table boundaries for accurate line item extraction. Unlike traditional OCR engines that output unstructured text, StructOCR provides a standardized JSON, delivering clean data structures optimized for direct integration into your AP systems and enhancing finance workflows.

Production Use Cases

  • Accounts Payable Automation: Automate your entire AP workflow from document ingestion to ERP entry. Reduce invoice processing costs by over 80% and eliminate human error.
  • Expense Management Automation: Instantly capture receipt and invoice data for real-time expense reporting and approval, accelerating reimbursement cycles.
  • Supply Chain Finance: Extract purchase order numbers, payment terms, and line items to verify trade documents and accelerate supply chain finance operations.
Need more testing? Create a free account to get 200 free credits (equals 66 Invoice scans).

Implementation: Python SDK

The official Python SDK simplifies the integration by handling file encoding and authentication. It parses the nested JSON response (merchant, financials, line items) automatically.

Prerequisite: pip install structocr

PYTHON EXAMPLE
from structocr import StructOCR

# Get 200 free credits:
# 👉 https://structocr.com/register
# Initialize with your API Key
client = StructOCR("YOUR_API_KEY_HERE")

def process_invoice():
    # Note: Currently supports image inputs (JPG, PNG)
    image_path = "invoice.jpg"

    try:
        print(f"Scanning invoice: {image_path}...")
        
        # The SDK handles the API request and error mapping
        result = client.scan_invoice(image_path)

        # Access the structured data
        data = result['data']
        
        print("✅ Extraction Successful!")
        print(f"Invoice #: {data.get('invoice_number')}")
        print(f"Date: {data.get('date')} (Due: {data.get('due_date')})")
        
        # Merchant Details
        merchant = data.get('merchant', {})
        print(f"Vendor: {merchant.get('name')} (Tax ID: {merchant.get('tax_id')})")
        
        # Financials
        fin = data.get('financials', {})
        print(f"Total: {fin.get('total_amount')} {data.get('currency')}")
        print(f"Tax: {fin.get('tax_amount')}")

        # Line Items Table
        print("\n--- Line Items ---")
        for item in data.get('line_items', []):
            print(f"- {item.get('description')}: {item.get('quantity')} x {item.get('unit_price')} = {item.get('amount')}")

    except Exception as e:
        print(f"❌ Extraction Failed: {e}")

if __name__ == "__main__":
    process_invoice()

Technical Specs

  • •Latency: < 4s (Average)
  • •Availability: Served from Cloudflare's global edge network
  • •Security: AES-256 Encryption & SOC2 Compliant
  • •Input: JPG, PNG (Base64 or File Path)
  • •Max File Size: 4.5MB
  • •Output: JSON (Nested Structure)

Key Features

  • •Line Item Extraction: Automatically parses tables and item lists into structured arrays.
  • •Financial Parsing: Separates tax amounts, subtotals, and grand totals for easy AP automation.
  • •Vendor Identification: Extracts merchant names, addresses, and tax IDs (VAT/EIN) reliably.

Sample JSON Output

StructOCR returns a normalized JSON object, regardless of the input invoice layout, angle, or quality.

{
  "success": true,
  "data": {
    "type": "invoice",
    "invoice_number": "INV-2026-001",
    "date": "2026-01-15",
    "due_date": "2026-02-15",
    "currency": "USD",
    "merchant": {
      "name": "AWS Web Services",
      "address": "410 Terry Ave N, Seattle, WA",
      "tax_id": "EIN-12-3456789",
      "iban": null
    },
    "customer": {
      "name": "Acme Corp Inc.",
      "tax_id": "987654321"
    },
    "financials": {
      "subtotal": 100,
      "tax_amount": 10,
      "total_amount": 110
    },
    "line_items": [
      {
        "description": "EC2 Instance Usage",
        "quantity": 1,
        "unit_price": 80,
        "amount": 80
      },
      {
        "description": "S3 Storage",
        "quantity": 1,
        "unit_price": 20,
        "amount": 20
      }
    ]
  }
}

Frequently Asked Questions

How does StructOCR compare to AWS Textract or Google Vision?

Generic cloud OCR services like Textract or Vision provide raw text blocks and coordinates, leaving your developers to build and maintain complex parsing logic. StructOCR is a specialized, pre-trained model for invoices. It returns a structured JSON with specific fields like `invoice_number`, `line_items`, and `total_amount` directly, eliminating all post-processing overhead.

Do you store the uploaded documents?

No. Uploaded images are kept for at most 24 hours for quality spot-checks, then deleted. We do not persist your data.

How do you handle blurry or skewed invoices?

Our API includes an automatic image pre-processing pipeline. This engine performs deskewing, denoising, and contrast enhancement before the OCR process begins, maximizing accuracy even on low-quality scans or mobile phone captures.

You May Also Like

Related tutorials, platform guides, and comparisons

Tutorial

C# Invoice OCR API

Upload an image for a free test! Integrate a high-accuracy Invoice OCR API into your C# application. Get structured JSON output for line items, totals, and merchant data. Eliminate Tesseract errors.

C# · Invoice
Tutorial

Node.js Invoice Parsing API

High-accuracy Node.js invoice parsing API for accounts payable automation. Upload an image for a free test! Extract line items, merchants, and financials into structured JSON output instantly.

Node.js · Invoice
Tutorial

PHP Invoice Line Item OCR API

Struggling with manual invoice data entry? Our PHP invoice line item OCR API processes documents in <3s, outputting structured JSON. Upload an image for a free test! SOC2 compliant & AES-256 encrypted.

PHP · Invoice
Tutorial

Go Invoice OCR API

Upload an image for a free test! High-accuracy Go invoice OCR API. Automate AP by converting unstructured invoices to structured JSON output. Eliminate manual entry and Tesseract errors.

Go · Invoice
Tutorial

Java OCR Invoice API

Upload an invoice to try our live demo. High-accuracy Java OCR invoice API for accounts payable. Extract line items directly into JSON.

Java · Invoice
Country Tutorial

Slovakia Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Slovakia passports with a server-side integration.

Python · Passport
Country Tutorial

South Africa Smart ID Card OCR Python SDK

Python Tutorial: Automate KYC in South Africa. Extract data from Smart ID Card using StructOCR Python SDK. Supports native text and MRZ extraction.

Python · smart id card
Country Tutorial

Romania Carte de Identitate OCR Python SDK

Python Tutorial: Automate KYC in Romania. Extract data from Carte de Identitate using StructOCR Python SDK. Supports native text, front/back sides, and MRZ extraction.

Python · carte de identitate
Country Tutorial

Serbia Lična karta OCR Python SDK

Python Tutorial: Automate KYC in Serbia. Extract data from Lična karta using StructOCR Python SDK. Supports native text and MRZ extraction.

Python · lična karta
Country Tutorial

Senegal Carte d'Identité CEDEAO OCR Python SDK

Python Tutorial: Automate KYC in Senegal. Extract data from Carte d'Identité CEDEAO using StructOCR Python SDK. Supports native text and MRZ extraction.

Python · carte d'identité cedeao

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

From tutorial to production in 5 minutes.

You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.

Instant Access Cancel Anytime No Credit Card