receipt-reader
Analyze a photo of a shopping receipt fully locally and break its lines down into the categories and subcategories defined in a YAML taxonomy. The output is structured JSON, designed to be easily embedded into other applications.
Architecture
The core is decoupled from providers through ports & adapters:
image → preprocess(OpenCV) → OcrEngine(RapidOCR | Tesseract)
→ reconstruct (rows) → receipt_parser → RawExtraction
→ ItemClassifier(Nimble) → ReceiptResult → JSON
- OCR: RapidOCR by default (PP-OCR models in ONNX, CPU, no CUDA); Tesseract as an alternative. Optionally Surya 2 (layout + reading order + document OCR) for maximum accuracy.
- Parser: heuristics for Spanish EUR receipts (quantities, weight, discounts, VAT, payment noise), with an OCR-tolerant amount tokenizer and arithmetic reconciliation against the total.
- Classification: Nimble 9B served by
Ollama (
/v1/systemone), queried over HTTP and suitable for CPU.
Switching OCR engine or classifier is just a matter of configuration; the
pipeline does not change. For maximum accuracy there is a vlm extractor
(self-hosted vision VLM via Ollama) and an ensemble extractor that combines
engines by consensus.
Installation
# Everything needed for local extraction + preprocessing
pip install "receipt-reader[local,preprocess]"
# Tesseract alternative (also requires the tesseract-ocr and spa binaries)
sudo apt install tesseract-ocr tesseract-ocr-spa
pip install "receipt-reader[tesseract]"
For development, clone the repository and install it in editable mode:
pip install -e ".[local,preprocess,nimble,dev]"
Extras: local (RapidOCR), tesseract, surya, preprocess (OpenCV),
nimble (httpx), vlm, web, dev.
RapidOCR downloads its ONNX models the first time it runs.
Configuration
Copy .env.example to .env. Everything is optional; the defaults work. Do
not put comments on the same line as a value (systemd and some parsers do not
strip them):
OCR_ENGINE=rapidocr
OCR_LANG=es
OCR_MODEL_TYPE=small
OCR_VERSION=PP-OCRv6
OCR_USE_GPU=false
TAXONOMY_PATH=
OCR_ENGINE: rapidocr | tesseract · OCR_MODEL_TYPE: tiny | small |
medium · OCR_VERSION: PP-OCRv4 | PP-OCRv5 | PP-OCRv6.
RapidOCR uses PP-OCRv6 by default with lang_type as an ISO code (es). The
first run downloads the corresponding recognition model. If your receipts are
hard, try OCR_MODEL_TYPE=medium (more accurate, slower).
Nimble is consumed over HTTP. If it lives on another machine, open an SSH tunnel:
ssh -L 11434:127.0.0.1:11434 user@nimble-host
and set NIMBLE_BASE_URL=http://localhost:11434.
Usage
# with TAXONOMY_PATH set, -t is not needed
receipt-reader analizar ticket.jpg --pretty
# or passing the taxonomy explicitly
receipt-reader analizar ticket.jpg --taxonomy categories.yaml --pretty
# engine ensemble (consensus): combines the extractors in ENSEMBLE_EXTRACTORS
receipt-reader analizar ticket.jpg -e ensemble --pretty
# classifier with a persistent lexicon (learns from the webapp corrections)
receipt-reader analizar ticket.jpg -c lexicon --pretty
To fine-tune the parser on real receipts (prints raw OCR, rows and parsing):
receipt-reader depurar ticket.jpg --pretty
To measure extraction accuracy against a labeled dataset (format in
evaluation/README.md):
receipt-reader evaluar evaluation/ --detalle
As a library:
from receipt_reader.taxonomy import load_taxonomy
from receipt_reader.registry import make_extractor, make_classifier
from receipt_reader.pipeline import ReceiptPipeline
tax = load_taxonomy("categories.yaml")
pipeline = ReceiptPipeline(make_extractor("local"), make_classifier("nimble"))
result = pipeline.process(open("ticket.jpg", "rb").read(), tax)
print(result.model_dump_json(indent=2))
Output
{
"comercio": "Mercadona",
"fecha": "2024-05-02",
"moneda": "EUR",
"total": "3.00",
"lineas": [
{
"descripcion": "Leche entera",
"cantidad": "2",
"importe": "1.90",
"categoria_id": "alimentacion",
"subcategoria_id": "lacteos",
"confianza": 0.93
}
],
"totales_por_categoria": {"alimentacion": {"lacteos": "1.90"}},
"revisar": [],
"avisos": [],
"meta": {"proveedor": "local:rapidocr"}
}
Amounts and quantities are serialized as strings to preserve decimal
accuracy. revisar holds the indices of the lines whose category could not be
assigned or fell below the confidence threshold.
Taxonomy format
version: 1
currency: EUR
categories:
- id: alimentacion
name: Alimentación
description: Productos de supermercado para consumo en casa
subcategories:
- {id: lacteos, name: Lácteos, description: Leche, yogur, queso...}
Debug web app
debug_webapp/ contains a small Flask app isolated from the package to
upload receipts, inspect the raw OCR, correct the classification by hand and
edit/validate the YAML taxonomies. It lets you pick the extractor (local,
surya, vlm or ensemble), which enables the multi-engine consensus and the
VLM configured in .env from the browser. It is not included in the wheel.
pip install -e ".[local,preprocess,nimble,web]"
TAXONOMY_PATH=~/receipt-config/household.yaml python -m debug_webapp.app
See debug_webapp/README.md for details.
Tests
pytest # unit and contract tests (no network)
pytest -m integration # real services (Nimble)
Known limitations
- The parser is tuned for standard Spanish supermarkets; very different formats
may need adjustments (use
depurarto iterate). - Heavily rotated, crumpled or low-contrast photos degrade the OCR beyond what
the parser can fix; in those cases use the
ensembleorvlmextractor, or retake the photo. - The local extractor does not process PDFs directly: convert them to an image first.
License
MIT.
Metadata
Release files for receipt-reader 0.1.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 | Actions |
|---|---|---|---|---|
| receipt_reader-0.1.0.tar.gz | 44.4 kB | Without provenance | Details for receipt_reader-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| receipt_reader-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for receipt_reader-0.1.0-py3-none-any.whl |
Total release size: 103.3 kB
Release files / receipt_reader-0.1.0.tar.gz
| Download URL | receipt_reader-0.1.0.tar.gz |
|---|---|
| Size | 44.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbaeb174b66c797131b7a6ae102619ec2611871b5b7bf56151855fca8b01fcc8
|
|
BLAKE2b-256 checksum How to use checksums |
3a597b85379eb8265bb56cde787ce191d76f8defdc10ac4524467475ccc33cf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.11
|
Release files / receipt_reader-0.1.0-py3-none-any.whl
| Download URL | receipt_reader-0.1.0-py3-none-any.whl |
|---|---|
| Size | 58.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c34f28d7cd30cdbc0786d1e9775156fe29a16115076fa012e5c0e20769077805
|
|
BLAKE2b-256 checksum How to use checksums |
be9ef296471d4f1e1097f9352b48f9c3fb954827df73f66a9c488cf0f479c64e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.11
|
Security for receipt-reader 0.1.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.