StructOCR Python SDK
Official Python client for the StructOCR API.
Extract validated, structured JSON from 19 document types — spanning identity & KYC (passports, travel visas, proof of address, national IDs, driver licenses, PDF417 barcodes, health insurance cards), vehicles & insurance (VIN, VIN Pro vehicle decode, license plates, registrations, auto insurance cards), finance (invoices, receipts), and logistics (bills of lading, shipping containers, weighbridge tickets, ATM cassettes, boat HINs). One method call per document, zero template training.
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
- Create an account. New accounts get 200 free credits, enough for 100 two-credit document scans, and no credit card is needed.
- Copy your key from API Keys in the dashboard.
- Optionally test any of the 19 endpoints on a sample image in the Playground before you write code.
Not ready to sign up? Try documents directly 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 |
| Driver license (front) | scan_driver_license |
2 | Try it |
| US/Canada driver license PDF417 barcode | scan_driver_license_pdf417 |
2 | Try it |
| National ID card | scan_national_id |
2 | Try it |
| Health insurance card (New) | scan_health_card |
2 | Try it |
| Proof of Address (New) | scan_proof_of_address |
2 | Try it |
| Travel visa (MRV-A/B & eVisa) (New) | scan_visa |
2 | Try it |
| VIN | scan_vin |
1 | Try it |
| VIN Pro (VIN + vehicle details) (New) | scan_vin_pro |
2 | |
| License plate | scan_license_plate |
1 | Try it |
| Vehicle registration | scan_vehicle_registration |
2 | Try it |
| Auto insurance card (New) | scan_auto_insurance |
2 | Try it |
| Invoice | scan_invoice |
3 | Try it |
| Receipt | scan_receipt |
1 | Try it |
| Shipping container (ISO 6346) | scan_container |
1 | Try it |
| Bill of Lading & freight (New) | scan_bill_of_lading |
3 | 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.
What's new in v1.8.0
Added native SDK methods for all six newly launched StructOCR endpoints:
scan_proof_of_address(file)(POST /v1/proof-of-address, 2 credits) — Utility bills, bank statements, tax notices, and leases with 90/180-day freshness and PO Box checks.scan_visa(file)(POST /v1/visa, 2 credits) — Passport visa stickers (ICAO 9303 MRV-A 2×44 & MRV-B 2×36 check-digit verification) and global eVisa PDFs.scan_bill_of_lading(file)(POST /v1/bill-of-lading, 3 credits) — Ocean/road Bills of Lading, Packing Lists, Air Waybills (IATA Mod-7 validation), Commercial Invoices, and signed PODs with ISO 6346 container checks and cargo weight reconciliation.scan_health_card(file)(POST /v1/health-card, 2 credits) — US health insurance cards (Member ID, Group, RxBIN/RxPCN/RxGRP, copays), GCC/Canada/India/Brazil medical cards, and EU Tessera Sanitaria/EHIC, including 2-page front+back PDFs.scan_auto_insurance(file)(POST /v1/auto-insurance, 2 credits) — US ACORD 50 / state proof of insurance and Canadian Pink Cards with NAIC, policy date, and VIN check-digit validation.scan_vin_pro(file)(POST /v1/vin-pro, 2 credits) — VIN OCR with ISO 3779 check-digit validation plus decoded vehicle year, make, model, trim, engine, and body class.
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_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)
scan_container(file)
scan_bill_of_lading(file)
scan_weighbridge_ticket(file)
scan_atm_cassette(file)
scan_hin(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.
Proof of Address example:
poa = client.scan_proof_of_address("./utility-bill.pdf")
if poa.get("success"):
print(poa["data"]["address"], poa["data"]["validation"]["is_within_90_days"])
Travel Visa example:
visa = client.scan_visa("./visa-sticker.jpg")
if visa.get("success"):
print(visa["data"]["visa_number"], visa["data"]["validation"]["mrz_checksum_valid"])
Bill of Lading & freight example:
bol = client.scan_bill_of_lading("./bill-of-lading.pdf")
if bol.get("success"):
print(bol["data"]["document_type"], bol["data"]["containers"], bol["data"]["validation"])
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.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| structocr-1.8.0.tar.gz | 11.9 kB | With provenance | Details for structocr-1.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| structocr-1.8.0-py3-none-any.whl | Python 3 | none | any | Details for structocr-1.8.0-py3-none-any.whl |
Total release size: 20.8 kB
Release files / structocr-1.8.0.tar.gz
| Download URL | structocr-1.8.0.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35d3a45fc14d16b9a89963bce51f9d8150a22621b00aa4ef5cf5278105b3e552
|
|
BLAKE2b-256 checksum How to use checksums |
7676f2a00550f0257d4cf29fca9d8c782ed911c94f66bcb5478e6c5e452f70f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / structocr-1.8.0-py3-none-any.whl
| Download URL | structocr-1.8.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
997350844e93d23aa50d8c777dd5a98d7c7dced646b1bba6d9074189e2bf64ca
|
|
BLAKE2b-256 checksum How to use checksums |
d500dd8361ebd124c4d3ac9a77f3184cf280697e28b64257c651f372efe3c3fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for structocr 1.8.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for structocr-1.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.