Official SDK

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.

BASH EXAMPLE
pip install --upgrade structocr

Passport OCR quickstart

Store the API key in STRUCTOCR_API_KEY, keep it on the server, and pass a supported local file to the SDK.

Never expose your StructOCR API key in browser or mobile client code.
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. The REST API itself accepts JSON with an img Base64 string, not file paths, binary bodies, URLs, or multipart uploads.

Supported OCR methods

Document typeSDK method
Passportscan_passport()
National IDscan_national_id()
Driver Licensescan_driver_license()
Invoicescan_invoice()
Receiptscan_receipt()
VINscan_vin()
HINscan_hin()
Shipping Containerscan_container()
License Platescan_license_plate()
Vehicle Registrationscan_vehicle_registration()
ATM Cassettescan_atm_cassette()
Account Balanceget_account_balance()

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 success value before using data.
  • 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 passport scans.

Get your API key