H2HDB-Komga
Description
H2HDB-Komga synchronizes a Komga library from the published catalog
projection in H2HDB. It matches Komga
book names to catalog publications and maps publication title, summary,
release date, every non-empty H2H gallery tag pair, and GID into Komga
metadata. Gallery tag pairs retain their original role/value meaning as Komga
authors. OPDS contributors, including the upload account, are not copied to
Komga, and this adapter does not patch Komga's tags field. When the original
gallery title is blank, the title field is also omitted so Komga keeps its
existing display title.
Canonical h2h-<gid>.cbz artifact basenames are matched directly through the
public lookup. Komga may include or omit the .cbz suffix; the adapter
normalizes either form to the one canonical name and queries names in batches
of at most 128 against one pinned revision. Legacy friendly, pure-GID, and
content-addressed filenames are intentionally unsupported. A revision change
resets the stability window, and completion performs a final revision check.
This adapter does not know the library's hash-shard paths and never reads core
repository internals. An unmatched, duplicate, noncanonical, non-One-Shot,
partial, or extra Komga item makes the observation incomplete, so no metadata
from that pass is patched.
Point the Komga library at the ingest-managed current/acquisitions subtree.
Do not mount the enclosing current directory: it also contains the separate
artwork tree used for OPDS thumbnails, which is not publication content for
Komga to scan.
The H2HDB database is always opened in read-only mode. Startup performs the
exact epoch-3/schema-version-2 READY audit through H2HDB's public database
opener but never initializes or migrates schema; schema ownership stays with
H2HDB core. Schema version 1 is not accepted by this release and has no
compatibility path: rebuild it through the owning core/ingest deployment.
Installation and Usage
-
Install Python 3.14 or higher from python.org.
-
Install the required packages.
pip install h2hdb-komga
-
Run the script.
python -m h2hdb_komga \ --komgaconfig [komga-config.json] \ --h2hdbconfig [h2hdb-config.json]
Config
komga-config.json
{
"base_url": "https://komga.example",
"api_username": "${KOMGA_API_USERNAME}",
"api_password": "${KOMGA_API_PASSWORD}",
"library_id": "library-id",
"coordination_root": "/srv/h2hdb/coordination",
"trigger_scan": true
}
Set both credential variables in the process environment before starting the command:
export KOMGA_API_USERNAME="admin@example.com"
export KOMGA_API_PASSWORD="secret"
${ENV_NAME} is resolved only when it is the complete JSON string value; it is
not substring interpolation. Resolution is recursive, missing variables fail
startup without exposing credential values, and resolved credentials must both
be non-empty strings. Literal api_username and api_password values remain
supported, but placeholders keep deployment secrets out of the JSON file.
Credential fields are also omitted from KomgaConfig's representation so
ordinary diagnostic output does not reveal them.
coordination_root is required and must be an absolute path to a separate
read-only bind of the ingest library's coordination directory. Its host source
is <library-root>/.h2hdb-coordination, alongside the private
<library-root>/.h2hdb-state directory. Mount only .h2hdb-coordination into
this consumer; the private state tree must not be mounted. The coordination
directory contains the permanent regular file publication.lock and, only
during an unfinished cutover, ACTIVATING. The command opens every directory
component without following symlinks, opens the lock nonblocking, acquires a
nonblocking shared flock, and checks the marker before contacting Komga. A busy
or unsafe lock, a symlinked path, or any ACTIVATING entry fails closed. The
shared lock is held through scan, analyze, settling, metadata reconciliation,
and the final stability check. Normal exit, failure, container stop, and the
CLI's hard worker termination all release the kernel lock when the descriptor
closes.
Edit the target Komga library and disable both autonomous scan settings:
- Scan on startup: disabled
- Scan interval: disabled
Only this coordinated command may trigger a library scan/analyze. Keep
trigger_scan set to true for the scheduled synchronization job, and do not
trigger scans from the Komga UI, another API client, or another scheduler.
trigger_scan defaults to true. Set it to false to skip requesting a
Komga scan/analyze and only reconcile metadata already visible in the library.
Afterward, the command polls every five seconds and page-reads every current
book and series. It checks that every book belongs to the configured library,
is a One-Shot, has a unique canonical artifact name and unique series, and
matches a publication from the pinned catalog revision. The referenced series
must exactly equal the library's unique One-Shot series, and both counts must
equal the revision's artifact count. Exact empty catalog and Komga sets are
valid. A temporary file-backed index enforces whole-library uniqueness while
keeping memory bounded; catalog lookups use at most 128 names, Komga pages use
at most 500 items, and pending updates are read in keyset batches of at most
200. No metadata is patched until the complete exact-set proof succeeds.
The command exits only after the exact set and metadata remain unchanged and
write-free for 30 seconds; the default timeout is one hour and can be changed
with --timeout-seconds. This observation window allows Komga's asynchronous
scan/analyze jobs and transient page failures to become visible before
completion. A scan or analyze request must receive a successful response;
client-side timeout cannot prove that Komga accepted it, so the run fails
closed and the next invocation retries the complete operation. Every catalog
lookup in one pass is pinned to the same current H2HDB head. If publication
advances during a batched lookup, the partial pass is discarded before
metadata is patched and the next poll starts again from the new head. Each
HTTP request, PATCH verification, retry, and retry delay uses the remaining
cooperative budget. The CLI also runs the complete operation in a disposable
worker process and kills it at the wall-clock deadline, so a slow-drip socket,
blocked database gate, or executor shutdown cannot extend the documented hard
timeout indefinitely.
h2hdb-config.json
Use an H2HDB core configuration compatible with h2hdb>=0.29.0,<0.30.0. Any
configured database access mode is overridden to read-only by this CLI.
The core loader supports the same exact ${ENV_NAME} placeholders, including
for a dedicated read-only database account and password.
Local Development
Rebuild the repository-local environment and run its canonical gates with:
./scripts/rebuild-env.sh
./scripts/check-fast.sh
./scripts/check-full.sh
The rebuild script installs this project in editable mode and resolves the
published compatible H2HDB core. It uses uv only for .venv and pip-style
installation, never reads uv.lock, and never assumes an adjacent checkout.
Q & A
-
How to use Komga? See Rainie's article.
-
Why is a CBZ file not updated?
The canonical
h2h-<gid>.cbzfile must be present in Komga and in a successfully published H2HDB catalog revision. After ingest publishes the artifact, run this coordinated command withtrigger_scanenabled. Do not trigger an uncoordinated scan from Komga. Legacy content-addressed, pure-GID, and friendly projection names are not supported.
Credits
The project was created by Kuan-Lun Wang.
License
This project is distributed under the terms of the GNU General Public License
version 3 (GPLv3). See the included LICENSE file for the complete terms.
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 h2hdb_komga-0.10.0.tar.gz.
File metadata
- Download URL: h2hdb_komga-0.10.0.tar.gz
- Upload date:
- Size: 55.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41040bbeb40c15d467c29f9a6537a64da292833b9aff80263a1a5716a20daa45
|
|
| MD5 |
667726e64d6a0139965a49afd155dbaf
|
|
| BLAKE2b-256 |
25f80b32c840d4a6461791249fa7c6dbea5c71460ebef5a79aff0dddc730f1c6
|
Provenance
The following attestation bundles were made for h2hdb_komga-0.10.0.tar.gz:
Publisher:
publish.yml on Kuan-Lun/h2hdb-komga
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
h2hdb_komga-0.10.0.tar.gz -
Subject digest:
41040bbeb40c15d467c29f9a6537a64da292833b9aff80263a1a5716a20daa45 - Sigstore transparency entry: 2683522013
- Sigstore integration time:
-
Permalink:
Kuan-Lun/h2hdb-komga@d347b2f883b74f791a1daa80c209937d967ed418 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Kuan-Lun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d347b2f883b74f791a1daa80c209937d967ed418 -
Trigger Event:
push
-
Statement type:
File details
Details for the file h2hdb_komga-0.10.0-py3-none-any.whl.
File metadata
- Download URL: h2hdb_komga-0.10.0-py3-none-any.whl
- Upload date:
- Size: 31.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32e1dca4a53669283fb3d3fe5a28e4af283667e841103e536fd0037bcf6d0916
|
|
| MD5 |
82c691ce298d8e748d74f341165bd411
|
|
| BLAKE2b-256 |
b5ef166c8f5dfafee60bab0e2e6e7190e4a2e4d5f604cc38294711b736d03091
|
Provenance
The following attestation bundles were made for h2hdb_komga-0.10.0-py3-none-any.whl:
Publisher:
publish.yml on Kuan-Lun/h2hdb-komga
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
h2hdb_komga-0.10.0-py3-none-any.whl -
Subject digest:
32e1dca4a53669283fb3d3fe5a28e4af283667e841103e536fd0037bcf6d0916 - Sigstore transparency entry: 2683522032
- Sigstore integration time:
-
Permalink:
Kuan-Lun/h2hdb-komga@d347b2f883b74f791a1daa80c209937d967ed418 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Kuan-Lun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d347b2f883b74f791a1daa80c209937d967ed418 -
Trigger Event:
push
-
Statement type: