StructOCR Python SDK
Add passport and document OCR to your Python backend without manually encoding files or maintaining REST request code.
Install the SDK
Install or upgrade the official structocr package from PyPI.
pip install --upgrade structocrPassport OCR quickstart
Store the API key in STRUCTOCR_API_KEY, keep it on the server, and pass a supported local file to the SDK.
import os
from structocr import StructOCR
client = StructOCR(api_key=os.environ["STRUCTOCR_API_KEY"])
result = client.scan_passport("./passport.jpg")
if result.get("success"):
passport = result["data"]
print(passport.get("passport_number"))
print(passport.get("given_names"), passport.get("surname"))
else:
print(result.get("error"))For the complete request and response schema, see the Passport OCR API reference.
The SDK converts paths or in-memory data to Base64 locally and sends JSON with an img string. If you call the REST API directly, send either that JSON or a multipart/form-data upload with one file in file or img; file paths and URLs are not accepted.
Supported OCR methods
| Document type | SDK method | Credits | Demo |
|---|---|---|---|
| Passport scan_passport() | scan_passport() | 2 | Try it |
| Driver License scan_driver_license() | scan_driver_license() | 2 | Try it |
| Driver License PDF417 scan_driver_license_pdf417() | scan_driver_license_pdf417() | 2 | Try it |
| National ID scan_national_id() | scan_national_id() | 2 | Try it |
| VIN scan_vin() | scan_vin() | 1 | Try it |
| License Plate scan_license_plate() | scan_license_plate() | 1 | Try it |
| Vehicle Registration scan_vehicle_registration() | scan_vehicle_registration() | 2 | Try it |
| Invoice scan_invoice() | scan_invoice() | 3 | Try it |
| Receipt scan_receipt() | scan_receipt() | 1 | Try it |
| Container scan_container() | scan_container() | 1 | Try it |
| Weighbridge Ticket scan_weighbridge_ticket() | scan_weighbridge_ticket() | 2 | Try it |
| ATM Cassette scan_atm_cassette() | scan_atm_cassette() | 1 | |
| HIN scan_hin() | scan_hin() | 1 | Try it |
| Account balance get_account_balance() | get_account_balance() | — |
Credits are charged per successful request. Try it opens a demo that needs no account: scan a sample image or your own file in the browser.
Package registries are the source of truth for the latest published version and release notes.
Runtime
Python 3.7+
Input
Local JPG, PNG, WebP, or PDF path; or bytes
Output
Structured result with success, data, and error fields
Authentication and errors
- Read the API key from a server-side environment variable.
- Check the returned
successvalue before usingdata. - Handle invalid input, insufficient credits, and temporary service failures in your application.
- Use the API reference for HTTP status codes and detailed error layouts.
Ready to make your first SDK call?
Create an account, receive 200 free credits, and test up to 100 two-credit document scans.
Get your API key