Paperless-ngx parser that routes OCR through GhostNode instead of Tesseract
Project description
paperless-ghostnode
paperless-ghostnode is a paperless plugin for routing OCR through GhostNode instead of Tesseract. The plugin registers a consumer which does a simple HTTP request to a number of GhostNodes. Should all GhostNodes fail, the processing fails.
A failed processing is not too bad. It keeps the failed files in the consume-folder where they can be "retried" (unfortunately, there is no retry button, but a restart of paperless re-scans the folder and "re-runs" them).
Installation
Depending on your
pip
plain pip install of paperless-ghostnode
pip install paperless-ghostnode
Docker Compose
When using docker compose, we need to somehow give paperless access to the files of paperless-ghostnode. One of the easiest one is to have an init-service, which installs the plugin into a shared volume via pip and then mount that volume into the paperless-worker.
services:
paperless-ghostnode-install:
image: python:slim
command: ["pip", "install", "--target", "/plugins", "paperless-ghostnode"]
volumes:
- paperless-ghostnode:/plugins
paperless-worker:
# ...
depends_on:
paperless-ghostnode-install:
condition: service_completed_successfully
volumes:
- paperless-ghostnode:/plugins
environment:
PYTHONPATH: /plugins
PAPERLESS_APPS: paperless_ghostnode
PAPERLESS_GHOSTNODE_HOSTS: "192.168.x.x:8080"
volumes:
paperless-ghostnode: {}
Nix
When using nix, we can just load the plugin from PyPi, build it, and then directly attach it to the PYTHONPATH of the paperless-task-queue service.
let
paperless-ghostnode = pkgs.python3Packages.buildPythonPackage {
pname = "paperless-ghostnode";
version = "0.1.0";
src = pkgs.fetchPypi {
pname = "paperless-ghostnode";
version = "0.1.0";
sha256 = "sha256-...";
};
format = "pyproject";
nativeBuildInputs = [ pkgs.python3Packages.hatchling ];
};
in {
systemd.services.paperless-task-queue.environment = {
PAPERLESS_APPS = "paperless_ghostnode";
PYTHONPATH = "${paperless-ghostnode}/${pkgs.python3.sitePackages}";
PAPERLESS_GHOSTNODE_HOSTS = "192.168.x.x:8080";
};
}
Configuration
PAPERLESS_APPS=paperless_ghostnode: The plugin needs to be registered as an appPAPERLESS_GHOSTNODE_HOSTS: comma-separated list ofhost:portentries, tried in order. Should point to addresses which may host an active GhostNode appPAPERLESS_GHOSTNODE_MODE:skip(default),force, orall
Why a parser and not a pre-consume script
Paperless supports pre-consumption scripts that run before a document is processed.
Instead of the paperless-ghostnode plugin the pre-consumption-script can be used to OCR documents with GhostNode. The main problem with that is that the pre-consumption-script is not considered "processing" by paperless.
I have not tested what happens, if the "reprocess" of a document is manually triggered from within paperless, when the pre-consumption-script is used. I would guess that either the pre-consumption-script is not rerun which would defeat the purpose of "reprocessing" or it is rerun, which would mean that the script is rerun on an already processed PDF as (we remember) the original is lost with a pre-consumption-script.
If despite these drawbacks you want to still use it, find the script below
Pre-Consumption-Script
#!/usr/bin/env bash
set -euo pipefail
GHOSTNODE_URL="${GHOSTNODE_URL:-http://<ghostnode-ip>:8080}"
case "$DOCUMENT_WORKING_PATH" in
*.pdf | *.PDF) ;;
*)
echo "ghostnode-ocr: not a PDF, skipping"
exit 0
;;
esac
tmp=$(mktemp /tmp/ghostnode-ocr-XXXXXX.pdf)
trap 'rm -f "$tmp"' EXIT
echo "ghostnode-ocr: sending to GhostNode…"
if ! curl \
--silent \
--fail \
--output "$tmp" \
--max-time 300 \
--request POST \
--header "Content-Type: application/pdf" \
--data-binary "@$DOCUMENT_WORKING_PATH" \
"$GHOSTNODE_URL/api/v1/ocr?mode=skip"; then
echo "ghostnode-ocr: GhostNode unreachable or returned error"
exit 1
fi
cp "$tmp" "$DOCUMENT_WORKING_PATH"
echo "ghostnode-ocr: done"
Point Paperless at it via PAPERLESS_PRE_CONSUME_SCRIPT and set PAPERLESS_OCR_SKIP_ARCHIVE_FILE=always so Paperless doesn't re-OCR the result with Tesseract afterwards.
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 Distribution
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 paperless_ghostnode-0.1.0.tar.gz.
File metadata
- Download URL: paperless_ghostnode-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e23a8e7151ee0820d2afc2682c13ca78d4eba5c0c2b5cd9ef09a0b4efe77718
|
|
| MD5 |
4edb15eb895f225f16534a814e00c7de
|
|
| BLAKE2b-256 |
093eeea905d59babad8c3255f8d2a33080fe14e4dced368024b3f4957150a7dc
|
File details
Details for the file paperless_ghostnode-0.1.0-py3-none-any.whl.
File metadata
- Download URL: paperless_ghostnode-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7337ecc722d0ac92602da476eead5047b7ca411e8e66a255c67f1ea8b1168648
|
|
| MD5 |
6c106aa8e1d71d86605d8361f8bc9ede
|
|
| BLAKE2b-256 |
963cf214dc240469863a3029a2dbd4a63b49d33c626961161426a66536e3bc85
|