Skip to main content

StructOCR Python SDK

Official Python client for the StructOCR API.

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.

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"))

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.0

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.0
File Size Uploaded Provenance
structocr-1.7.0.tar.gz 6.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 12.9 kB

Release files / structocr-1.7.0.tar.gz

Download URL structocr-1.7.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6e94b57e626f8a9fc8a8867720b7462429051cba1da14b3f2fa61e67efec27ca
BLAKE2b-256 checksum
How to use checksums
a5e5eefb3f774f923829fc9c7381ef77e73c721c535b1d6b0f88ebb364532032
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.0-py3-none-any.whl

Download URL structocr-1.7.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34c882717e41cb524ffe225b86b38cfbabda85a5cfc6e19ac7c081a1a126367d
BLAKE2b-256 checksum
How to use checksums
052f6c254e5b854dae85a0255270709febc82e31790bde02e6446e44dd114ae7
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.0

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