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_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. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
Receipt v2 provides a richer response. Enhanced accuracy requires v2 and costs 2 credits instead of the standard 1 credit:
receipt = client.scan_receipt(
"./receipt.jpg",
response_version=2,
accuracy="enhanced",
)
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.6.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 | |
|---|---|---|---|---|
| structocr-1.6.0.tar.gz | 6.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| structocr-1.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / structocr-1.6.0.tar.gz
| Download URL | structocr-1.6.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebe6f560b329c68502e0b481fd3ae4eab68bbf4b2def0e06697cf944c5dbdfb4
|
|
BLAKE2b-256 checksum How to use checksums |
1817bd4640219c8da46a69070e5389e8ce67cf8e206e34ba5e2e5fea8841bb7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.9
|
Release files / structocr-1.6.0-py3-none-any.whl
| Download URL | structocr-1.6.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
929c2ef3535e13f6a7469b4ba477f0c9d11916ae5f43f7e9f426e6af09913187
|
|
BLAKE2b-256 checksum How to use checksums |
aadd5dd18a194b059ceeebcf3610e2002510c7978c225b76fed9d43e5e287773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.9
|
Security for structocr 1.6.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.