Offline hybrid OCR SDK for structured document extraction.
Project description
ocrkitx
ocrkitx is a production-oriented Python SDK for offline OCR and structured business document extraction.
Current milestone includes:
OCRKitpublic API- Tesseract OCR integration
- Optional digital PDF text extraction with
pdfplumber - Optional digital PDF table extraction with Camelot, with
pdfplumberfallback - Optional PaddleOCR primary engine
- Tesseract fallback engine
- Optional EasyOCR fallback for difficult images
- Hybrid Paddle + Tesseract field merge
- Scanned PDF conversion with
pdf2image - Routing for image, digital PDF, and scanned PDF detection
- Auto document classification for invoice, bank statement, and generic documents
- Page-wise output, layout blocks, and table metadata in the standard result
- Invoice, bank statement, and generic document types
- Text, JSON, and Markdown formatters
- TOON formatter for token-oriented object notation
- Confidence, warnings, and
review_required - Debug trace output with route, timing, pages processed, and low-confidence fields
- Production targeted extraction with
fields=[...], custom aliases, and presets - Optional generic
all_fieldsdiscovery with confidence scoring
Install for development
pip install -e ".[dev,image,pdf]"
For PaddleOCR support:
pip install -e ".[paddle]"
For stronger digital PDF table extraction:
pip install -e ".[table]"
For EasyOCR fallback support:
pip install -e ".[easyocr]"
For all optional local engines:
pip install -e ".[all]"
On Windows, scanned PDF conversion through pdf2image may also require Poppler installed and available on PATH.
For Tesseract OCR you also need the Tesseract binary installed on your system.
On Windows, install it separately and make sure tesseract.exe is available on your PATH.
Basic usage
from ocrkitx import OCRKit
ocr = OCRKit(
mode="auto",
tesseract_cmd=r"C:\Program Files\Tesseract-OCR\tesseract.exe",
)
result = ocr.extract(
file="invoice.pdf",
document_type="auto",
output_format="json",
debug=True,
)
print(result)
Production targeted extraction
For production apps, pass the exact fields you want. This keeps output clean and avoids noisy generic discovery.
from ocrkitx import OCRKit
ocr = OCRKit(mode="auto")
result = ocr.extract(
"invoice.pdf",
document_type="invoice",
fields=["invoice_number", "po_number", "total_amount"],
output_format="json",
)
print(result["fields"])
When fields or preset is provided:
fieldscontains only requested fieldskey_valuescontains only requested fields that were foundall_fieldsdiscovery is disabled by default- missing required fields add warnings and can set
review_required=True
Custom fields
Use custom aliases for fields that are specific to your workflow.
result = ocr.extract(
"invoice.pdf",
document_type="invoice",
fields={
"vehicle_type": {
"type": "text",
"aliases": ["Vehicle Type", "Truck Type"],
},
"delivery_terms": {
"type": "text",
"aliases": ["Delivery Terms", "Incoterms"],
"required": False,
},
},
output_format="json",
)
Supported field types include:
textdateamountgstinifsc
Presets
Presets are shortcuts for common production use cases.
result = ocr.extract(
"invoice.pdf",
document_type="invoice",
preset="invoice_compliance",
output_format="json",
)
Available presets:
invoice_basicinvoice_complianceinvoice_logisticsbank_basic
Discovery mode
Generic discovery is still available for exploration/debugging.
result = ocr.extract(
"invoice.pdf",
document_type="invoice",
output_format="json",
all_fields=True,
all_fields_min_confidence="medium",
)
print(result["all_fields"])
Use targeted extraction for production. Use all_fields when exploring a new document format.
Modes
mode="auto": digital PDFs usepdfplumber; scanned PDFs/images use PaddleOCR with Tesseract fallback.mode="fast": prefer digital PDF text or PaddleOCR.mode="fallback": PaddleOCR first, then Tesseract, then EasyOCR if confidence is low.mode="hybrid": run PaddleOCR and Tesseract, then merge extracted fields.
Document types
invoicebank_statementgenericauto
Output formats
jsonmarkdowntexttoon
Internally, extraction runs once into one standard result schema. Formatters only convert that result for humans or machines.
Standard result highlights
JSON output includes:
fieldswith value, confidence, source, validity, and validation errorspagesfor page-wise text/tables/confidence metadatablocksfor simple layout sections such as headers, parties, tables, totals, and footerstablesfrom digital PDFs when availablewarningsandreview_required- optional
debugdetails whendebug=True
Backward-compatible Tesseract-only usage
from ocrkitx import OCRKit
ocr = OCRKit(
engine="tesseract",
tesseract_cmd=r"C:\Program Files\Tesseract-OCR\tesseract.exe",
)
result = ocr.extract("invoice.png", output_format="json")
print(result)
TOON Output
result = ocr.extract(
"invoice.pdf",
document_type="invoice",
output_format="toon",
)
print(result)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ocrkitx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ocrkitx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 54.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3d612de52eb1827ddef628128ca249196fb60b271ac2585118b044218a51fa7
|
|
| MD5 |
c8b56065521ef41852307128edb15607
|
|
| BLAKE2b-256 |
eb1febf6b9829391fd41bf68c4b496cb39c8dd81d0a5b6921e8c00aa771d6e25
|