PTM-OCR
Batch OCR Processing for Thai Documents using Typhoon OCR API
Installation
pip install ptm-ocr
Quick Start
1. Set Environment Variables
Create a .env file or export environment variables:
export OCR_BASE_URL=https://openai.com/v1
export OCR_API_KEY=your_api_key_here
export OCR_MODEL=ocr
2. Run OCR
Command Line:
# Basic usage
ptm-ocr data/pdfs
# With options
ptm-ocr data/pdfs -o output -w 8 -t structure
Python API:
from ptm_ocr import process_folder, process_pdf_file
# Process entire folder
summary = process_folder(
input_folder="data/pdfs",
output_folder="output",
task_type="default",
max_workers=4
)
# Process single PDF
summary = process_pdf_file(
pdf_path="document.pdf",
output_path="document.jsonl"
)
CLI Options
| Option | Short | Default | Description |
|---|---|---|---|
--output |
-o |
output |
Output folder for JSONL files |
--task-type |
-t |
default |
OCR task type: default or structure |
--workers |
-w |
4 |
Number of parallel workers |
--base-url |
env | Override OCR_BASE_URL | |
--api-key |
env | Override OCR_API_KEY | |
--model |
env | Override OCR_MODEL |
Output Format (JSONL)
Each line in the output file is a JSON object:
{"page": 1, "text": "ข้อความที่ OCR ได้", "status": "success", "error": null}
{"page": 2, "text": "ข้อความหน้า 2", "status": "success", "error": null}
Task Types
- default: General documents, infographics
- structure: Complex layouts (tables, forms, mixed content)
Reading Output
import json
with open('output/document.jsonl', 'r', encoding='utf-8') as f:
for line in f:
page = json.loads(line)
print(f"Page {page['page']}: {page['text'][:100]}...")
License
MIT
Metadata
Release files for ptm-ocr 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ptm_ocr-0.1.1.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ptm_ocr-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.3 kB
Release files / ptm_ocr-0.1.1.tar.gz
| Download URL | ptm_ocr-0.1.1.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
578dad22add1f8fe4c5943733b4d686d03354228194d8f59eb3006f6f10d56df
|
|
BLAKE2b-256 checksum How to use checksums |
863b3cd7e7302297c1a22b07671847a3df9933c2c4977d1122e374bd92116637
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.12
|
Release files / ptm_ocr-0.1.1-py3-none-any.whl
| Download URL | ptm_ocr-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e5c6d86cbd0b1ae7f9cfdb0e8d3e0b781433a87d35da84f5aa3b3c8267838ce
|
|
BLAKE2b-256 checksum How to use checksums |
ad9854b975470628ad0dba986350437c63cf0f6aa0093105e58b78da711ffcc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.12
|