Skip to main content

StructOCR Python SDK

Official Python client for the StructOCR API.

Send a photo or PDF of a passport, ID card, driver license, VIN, invoice, receipt or shipping container and get structured JSON back: one method call per document, no templates to train.

The SDK accepts a local JPG, PNG, WebP, or PDF path, plus in-memory bytes. It validates the decoded file locally, converts it to Base64, and sends JSON as {"img": "..."}. The REST API also supports multipart uploads; this SDK release keeps Base64 JSON as its default transport for backward compatibility.

Get a free API key

  1. Create an account. New accounts get 200 free credits, enough for 100 passport or driver license scans, and no credit card is needed.
  2. Copy your key from API Keys in the dashboard.
  3. Optionally try any document type on a sample image in the Playground before you write code.

Not ready to sign up? Try any document in your browser on a sample image or your own file, no account needed: use the Try it links in the table below.

After the free credits, packs start at $5 for 500 credits. There is no subscription and credits do not expire. See pricing.

Supported documents

Document Method Credits per scan Try it
Passport scan_passport 2 Try it
National ID card scan_national_id 2 Try it
Driver license (front) scan_driver_license 2 Try it
US/Canada driver license PDF417 barcode scan_driver_license_pdf417 2 Try it
Vehicle registration scan_vehicle_registration 2 Try it
VIN scan_vin 1 Try it
License plate scan_license_plate 1 Try it
Invoice scan_invoice 3 Try it
Receipt scan_receipt 1 Try it
Shipping container (ISO 6346) scan_container 1 Try it
Weighbridge ticket scan_weighbridge_ticket 2 Try it
ATM cassette scan_atm_cassette 1
HIN (boat hull number) scan_hin 1 Try it

The receipt endpoint's optional enhanced mode costs 2 credits. Only successful requests are charged.

Install

pip install --upgrade structocr

Python 3.7+ is required.

Quick start

export STRUCTOCR_API_KEY="YOUR_API_KEY"
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"))

A passport scan returns JSON like this (fictional sample document):

{
  "success": true,
  "data": {
    "type": "passport",
    "country_code": "UTO",
    "nationality": "UTOPIAN",
    "passport_number": "X4R7T2K9P",
    "surname": "MORGAN",
    "given_names": "OLIVIA ROSE",
    "sex": "F",
    "date_of_birth": "1990-03-14",
    "place_of_birth": "ZENITH CITY",
    "date_of_issue": "2024-07-16",
    "date_of_expiry": "2034-07-15",
    "place_of_issue": null
  }
}

PDF paths work the same way:

result = client.scan_invoice("./invoice.pdf")

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

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

Methods

scan_passport(file)
scan_national_id(file)
scan_driver_license(file)
scan_driver_license_pdf417(file)
scan_invoice(file)
scan_receipt(file)
scan_vin(file)
scan_hin(file)
scan_container(file)
scan_license_plate(file)
scan_vehicle_registration(file)
scan_atm_cassette(file)
scan_weighbridge_ticket(file)
get_account_balance()

All document methods accept a local path or bytes, up to 4.5MB. Most methods support JPG, PNG, WebP, and PDF. scan_driver_license_pdf417 accepts JPG, PNG, and WebP only.

The Receipt endpoint returns v2 by default. Enhanced accuracy costs 2 credits instead of the standard 1 credit and is enabled with the accuracy parameter:

receipt = client.scan_receipt(
    "./receipt.jpg",
    accuracy="enhanced",
)

response_version=2 remains accepted for compatibility but is not required. Receipt v1 is retired.

US driver license PDF417 example:

result = client.scan_driver_license_pdf417("./license-back.jpg")
if result.get("success"):
    print(result["data"]["document_number"])

Weighbridge ticket example:

result = client.scan_weighbridge_ticket("./weighbridge-ticket.jpg")
if result.get("success"):
    print(result["data"]["weights"])
    print(result["data"]["validation"])

Configuration

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

See the API documentation for endpoint-specific response schemas and error codes.

Errors

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

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

Metadata

Release files for structocr 1.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for structocr 1.7.1
File Size Uploaded Provenance
structocr-1.7.1.tar.gz 9.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for structocr 1.7.1
File Interpreter ABI Platform
structocr-1.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / structocr-1.7.1.tar.gz

Download URL structocr-1.7.1.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b8a253ce3149cec80cea5e722b43bc67a2807f507249701fd3dc1fdd32a6d9f8
BLAKE2b-256 checksum
How to use checksums
603c7c317be4afd5b39f4ba0d8b6bd5e33cc932745312f210f78da0c4cd89c29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.9

Release files / structocr-1.7.1-py3-none-any.whl

Download URL structocr-1.7.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7811bffa06483d9be14b3579a9c85a2dd22301dee3e63f1e8148900173de0da2
BLAKE2b-256 checksum
How to use checksums
57d58137dd5044f23137d8fd85892b4720c0adf3c4221d686c068df1d3962a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.9

Security for structocr 1.7.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page