semvec/pypi-packages huggingface dataset:
OCRStateMachine 0.1.1
A pluggable, logic-agnostic state machine for OCR processing
License: MIT
Requires Python: >=3.8

# OCRStateMachine

**OCRStateMachine** is a lightweight, customizable state machine framework for document OCR processing workflows.

It abstracts the typical stages of a document OCR pipeline — metadata loading, binary loading, preprocessing, OCR extraction, supplier matching, and upload — into distinct states, and allows users to inject their own logic into each state.

---

## Installation

```bash
pip install OCRStateMachine
```

---

## Usage

```python
from OCRStateMachine import OCRStateMachine
from your_module import preprocess, extract_text, match_supplier, upload_result
from your_module import DeepJSONClient  # a connector compatible with the DeepJSON backend

state_machine = OCRStateMachine(
    key="some-file-key.pdf",
    token="your-access-token",
    preprocess_fn=preprocess,
    ocr_extract_fn=extract_text,
    match_supplier_fn=match_supplier,
    upload_fn=upload_result,
    deepjson_connector_cls=DeepJSONClient
)

state_machine.run()
```

---

## Injected Functions

You need to implement and inject the following:

- `preprocess(binary: bytes, meta: dict) -> Image`
- `ocr_extract(image: Image) -> dict`
- `match_supplier(extracted: dict) -> dict`
- `upload(key: str, extracted: dict) -> None`

The state machine handles orchestration. You provide the logic.

---

## Example Project Structure

```
my_project/
├── ocr/
│   ├── logic.py  # contains your 4 logic functions
│   └── connector.py  # defines your DeepJSON-compatible connector
└── main.py       # runs the OCRStateMachine
```

---

## Notes

- The state machine uses a DeepJSON-compatible client to retrieve metadata and binary.
- The `key` should exist and point to an uploaded document.
- The `token` must be authorized to access the key via your API.

---

## License

MIT