🐍

Python SDK — OCR Document Intelligence

Python integration guide for Cargoffer OCR. Extract invoice, price list, and email data with 3 lines of code.

Quick Start

Install with pip and extract your first document in under 30 seconds.

Installation

bash
pip install requests
# No SDK needed — use the REST API directly

Extract Invoice

python
import requests

API = "https://ocr.cargoffer.com"
KEY = "ocr_your_api_key"
HEADERS = {"Authorization": f"Bearer {KEY}"}

# 1. Upload
r = requests.post(f"{API}/api/upload",
    headers=HEADERS,
    files={"file": open("invoice.pdf", "rb")})
job = r.json()["job"]

# 2. Analyze
r = requests.post(f"{API}/api/analyze/{job}",
    headers=HEADERS)
data = r.json()

# 3. Use extracted data
result = list(data["results"].values())[0]
print(f"Invoice: {result['invoice_number']}")
print(f"Total: {result['totals']['total']}€")
print(f"Items: {len(result['line_items'])} lines")

Bulk Processing

python
import os, requests, concurrent.futures

def process_pdf(path):
    with open(path, 'rb') as f:
        r = requests.post(f"{API}/api/upload",
            headers=HEADERS, files={"file": f})
        job = r.json()["job"]
    r = requests.post(f"{API}/api/analyze/{job}", headers=HEADERS)
    return path, r.json()

# Process 50 invoices in parallel
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as ex:
    results = ex.map(process_pdf, pdf_files)

Error Handling

python
r = requests.post(...)
if r.status_code == 401:
    print("Invalid API key")
elif r.status_code == 402:
    print("Quota exhausted — upgrade your plan")
elif r.status_code == 429:
    print("Rate limited — retry after 1 second")

Ready to try it?

Start Free →