Metadata-Version: 2.4
Name: structocr
Version: 1.9.0
Summary: Structured OCR & ID Verification API SDK for Python: driver license front+back PDF417 verification, PDF table extraction, image-to-excel, passports, visas, proof of address, health cards, vehicle registrations, invoices, and bills of lading.
Home-page: https://structocr.com
Author: StructOCR Team
Author-email: support@structocr.com
License: MIT
Project-URL: Homepage, https://structocr.com
Project-URL: Documentation, https://structocr.com/developers
Project-URL: OpenAPI Spec, https://structocr.com/openapi.json
Project-URL: LLMs.txt, https://structocr.com/llms.txt
Project-URL: Get a free API key, https://structocr.com/register?utm_source=pypi&utm_medium=project_urls&utm_campaign=sdk
Project-URL: Source, https://github.com/dracula911/structocr-python
Project-URL: Tracker, https://github.com/dracula911/structocr-python/issues
Keywords: ocr,driver license verification,pdf417,aamva,pdf table extraction,pdf to json,image to excel,passport ocr,mrz,id card ocr,driver license ocr,heic ocr,health card ocr,proof of address ocr,visa ocr,vin ocr,vin pro ocr,vehicle registration ocr,auto insurance ocr,invoice ocr,receipt ocr,bill of lading ocr,freight ocr,kyc,zero data retention,document ai,structocr
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# StructOCR Python SDK

Official Python client for the [StructOCR API](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).

Extract validated, structured JSON from 22 document & verification endpoints — spanning identity & KYC (US/Canadian front+back driver license verification, PDF417 barcodes, driver licenses, passports, travel visas, proof of address, national IDs, health insurance cards), general documents (multi-page PDF table/JSON extraction, Image to Excel), vehicles & insurance (VIN, VIN Pro vehicle decode, license plates, vehicle registrations including Saudi Istimara & UAE Mulkiya, auto insurance cards), finance (multi-page PDF invoices, receipts), and logistics (bills of lading, shipping containers, weighbridge tickets, ATM cassettes, boat HINs). One method call per document, zero template training, pay-as-you-go credits that never expire.

## Get a free API key

1. [Create an account](https://structocr.com/register?utm_source=pypi&utm_medium=readme&utm_campaign=sdk). New accounts get **200 permanent free credits** (50 full driver license verifications or 100 two-credit document scans), with no credit card required.
2. Copy your key from **API Keys** in the dashboard.
3. Optionally test any endpoint on a sample document in the [Playground](https://structocr.com/dashboard/playground?utm_source=pypi&utm_medium=readme&utm_campaign=sdk) before writing code.

After the free credits, packs start at $5 for 500 credits ($0.0058–$0.01/credit). There is no monthly subscription and credits never expire. See [pricing](https://structocr.com/pricing?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).

## Supported documents & endpoints

| Document / Workflow | Method | Credits | Zero Retention | Try it |
| --- | --- | --- | --- | --- |
| US/Canada driver license verify (front OCR + back PDF417) *(New)* | `verify_driver_license` | 4 | Yes | [Try it](https://structocr.com/solutions/driver-license-verification-api?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| PDF table & JSON extraction (up to 20 pages) *(New)* | `extract_pdf` | 2 / page | Yes | [Try it](https://structocr.com/tools/pdf-table-extractor?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try) |
| Image to Excel table extraction *(New)* | `image_to_excel` | 2 / image | Yes | [Try it](https://structocr.com/tools/image-to-excel?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try) |
| US/Canada driver license PDF417 barcode | `scan_driver_license_pdf417` | 2 | Yes | [Try it](https://structocr.com/tools/driver-license-pdf417-scanner?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try) |
| Driver license (front) | `scan_driver_license` | 2 | — | [Try it](https://structocr.com/products/driver-license-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Passport (MRZ + visual) | `scan_passport` | 2 | — | [Try it](https://structocr.com/products/passport-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| National ID card | `scan_national_id` | 2 | — | [Try it](https://structocr.com/products/national-id-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Health insurance card | `scan_health_card` | 2 | Yes | [Try it](https://structocr.com/products/health-card-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Proof of Address | `scan_proof_of_address` | 2 | Yes | [Try it](https://structocr.com/products/proof-of-address-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Travel visa (MRV-A/B & eVisa) | `scan_visa` | 2 | Yes | [Try it](https://structocr.com/products/visa-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| VIN | `scan_vin` | 1 | — | [Try it](https://structocr.com/products/vin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| VIN Pro (VIN + vehicle details) | `scan_vin_pro` | 2 | — | |
| License plate | `scan_license_plate` | 1 | — | [Try it](https://structocr.com/products/license-plate-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Vehicle registration (Istimara, Mulkiya, global) | `scan_vehicle_registration` | 2 | — | [Try it](https://structocr.com/products/vehicle-registration-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Auto insurance card | `scan_auto_insurance` | 2 | — | [Try it](https://structocr.com/products/auto-insurance-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Invoice (multi-page PDF up to 5 pages) | `scan_invoice` | 3 | — | [Try it](https://structocr.com/products/invoice-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Receipt | `scan_receipt` | 1 (2 enhanced) | — | [Try it](https://structocr.com/products/receipt-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Shipping container (ISO 6346) | `scan_container` | 1 | — | [Try it](https://structocr.com/products/container-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Bill of Lading & freight | `scan_bill_of_lading` | 3 | — | [Try it](https://structocr.com/products/bill-of-lading-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| Weighbridge ticket | `scan_weighbridge_ticket` | 2 | — | [Try it](https://structocr.com/products/weighbridge-ticket-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
| ATM cassette | `scan_atm_cassette` | 1 | — | |
| HIN (boat hull number) | `scan_hin` | 1 | — | [Try it](https://structocr.com/products/hin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |

Only successful requests are charged. Failed pages on `extract_pdf` / `image_to_excel` and unreadable back barcodes (`HTTP 422`) on `verify_driver_license` are automatically refunded.

## What's new in v1.9.0

- **`verify_driver_license(front, back, *, min_age=None)`** (`POST /v1/driver-license-verify`, 4 credits, strict Zero Data Retention) — Single-call US & Canadian front OCR + back AAMVA PDF417 cross-check, Document Discriminator (`DD` vs. `DCF`), expiry, and `18+`/`21+`/`min_age` verification. Back barcode decodes first; unreadable barcodes return HTTP 422 with `failed_side`/`capture_issue` and auto-refund all 4 credits. Card-level consistency check only (does not query DMV registries).
- **`extract_pdf(file, *, mode="auto", pages=None, schema=None, stitch_tables=None)`** (`POST /v1/pdf-extract`, 2 credits/succeeded page, strict Zero Data Retention) — Native `multipart/form-data` upload up to 10 MB / 20 pages with multi-page table stitching and optional custom schema extraction.
- **`image_to_excel(file, *, mode="tables", ...)`** (`POST /v1/image-to-excel`, 2 credits/image, strict Zero Data Retention) — Converts table photos and scanned sheets into deterministic `headers[]` and `rows[][]` arrays.
- **Native Apple HEIC/HEIF support** — Local format detection now accepts iPhone `HEIC`/`HEIF` images for `verify_driver_license`, `scan_driver_license_pdf417`, and standard image endpoints (while still rejecting unsupported formats such as AVIF before sending).

## Install

```bash
pip install --upgrade structocr
```

Python 3.7+ is required.

## Quick start

```bash
export STRUCTOCR_API_KEY="YOUR_API_KEY"
```

### Verify US/Canadian driver license (Front OCR + Back PDF417)

```python
from structocr import StructOCR, StructOCRError

client = StructOCR()

try:
    result = client.verify_driver_license(
        "./license-front.jpg",
        "./license-back.heic",
        min_age=21,
    )
    v = result["data"]["verification"]
    print(v["overall_status"], "DD/DCF:", v["dd_dcf_match"], "21+:", v["meets_min_age"])
except StructOCRError as err:
    if err.status_code == 422 and isinstance(err.details, dict):
        # Unreadable back barcode short-circuits with full 4-credit refund
        print("Retake:", err.details.get("failed_side"), err.details.get("capture_issue"))
    else:
        raise
```

### Extract tables from a multi-page PDF or photo

```python
from structocr import StructOCR

client = StructOCR()

pdf_res = client.extract_pdf("./statement.pdf", mode="tables", pages="1-5")
for table in pdf_res["document"]["tables"]:
    print(table["headers"], len(table["rows"]))

img_res = client.image_to_excel("./price-sheet.jpg")
print(img_res["document"]["tables"][0]["rows"])
```

### Scan a passport (or pass in-memory bytes)

```python
from structocr import StructOCR

client = StructOCR()
result = client.scan_passport("./passport.jpg")

if result.get("success"):
    data = result["data"]
    print(data.get("passport_number"))
    print(data.get("given_names"), data.get("surname"))
```

FastAPI and other server frameworks can pass uploaded bytes without a temporary file:

```python
content = await upload.read()
result = client.scan_passport(content)
```

## Methods

```text
verify_driver_license(front, back, *, min_age=None)
extract_pdf(file, *, mode="auto", pages=None, schema=None, stitch_tables=None)
image_to_excel(file, *, mode="tables", pages=None, schema=None, stitch_tables=None)
scan_passport(file)
scan_national_id(file)
scan_driver_license(file)
scan_driver_license_pdf417(file)
scan_health_card(file)
scan_proof_of_address(file)
scan_visa(file)
scan_vin(file)
scan_vin_pro(file)
scan_license_plate(file)
scan_vehicle_registration(file)
scan_auto_insurance(file)
scan_invoice(file)
scan_receipt(file, response_version=None, accuracy="standard")
scan_container(file)
scan_bill_of_lading(file)
scan_weighbridge_ticket(file)
scan_atm_cassette(file)
scan_hin(file)
get_account_balance()
```

- Single-document `scan_*` methods accept a local path or bytes up to 4.5 MB (JPG, PNG, WebP, HEIC, and PDF; `scan_driver_license_pdf417` and `verify_driver_license` accept JPG, PNG, WebP, and HEIC).
- `extract_pdf` and `image_to_excel` send `multipart/form-data` up to 10 MB (PDF, JPG, PNG, and WebP).

## Machine-Readable Specs & Automation

- **OpenAPI 3.1 Spec**: [`https://structocr.com/openapi.json`](https://structocr.com/openapi.json)
- **LLM Documentation Index**: [`https://structocr.com/llms.txt`](https://structocr.com/llms.txt) · [`https://structocr.com/llms-full.txt`](https://structocr.com/llms-full.txt)
- **n8n Workflow Guides**: [Driver License Verification](https://structocr.com/blog/platforms/n8n-driver-license-verification) · [Image to Excel](https://structocr.com/blog/platforms/n8n-image-to-excel-ocr) · [Saudi Istimara](https://structocr.com/blog/platforms/n8n-saudi-istimara-ocr)
- **API Reference**: [`https://structocr.com/developers`](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk)

## Configuration

```python
client = StructOCR(
    api_key="YOUR_API_KEY",
    base_url="https://api.structocr.com/v1",
    timeout=60,
)
```

## Errors

API and network failures raise `StructOCRError`. Existing `except RuntimeError` code continues to work because `StructOCRError` extends `RuntimeError`.

```python
from structocr import StructOCRError

try:
    client.scan_passport("./passport.jpg")
except StructOCRError as error:
    print(error.status_code, error.code, error.retryable)
```

`retryable` is advisory only. The SDK does not automatically retry OCR requests because doing so without an idempotency key could charge a request twice.

## License

MIT
