Skip to main content

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

  1. Install Python 3.14 or higher from python.org.

  2. Install the required packages.

    pip install h2hdb-komga
    
  3. 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>.cbz file must be present in Komga and in a successfully published H2HDB catalog revision. After ingest publishes the artifact, run this coordinated command with trigger_scan enabled. 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

h2hdb_komga-0.10.0.tar.gz (55.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

h2hdb_komga-0.10.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

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

Hashes for h2hdb_komga-0.10.0.tar.gz
Algorithm Hash digest
SHA256 41040bbeb40c15d467c29f9a6537a64da292833b9aff80263a1a5716a20daa45
MD5 667726e64d6a0139965a49afd155dbaf
BLAKE2b-256 25f80b32c840d4a6461791249fa7c6dbea5c71460ebef5a79aff0dddc730f1c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for h2hdb_komga-0.10.0.tar.gz:

Publisher: publish.yml on Kuan-Lun/h2hdb-komga

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for h2hdb_komga-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32e1dca4a53669283fb3d3fe5a28e4af283667e841103e536fd0037bcf6d0916
MD5 82c691ce298d8e748d74f341165bd411
BLAKE2b-256 b5ef166c8f5dfafee60bab0e2e6e7190e4a2e4d5f604cc38294711b736d03091

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 files

0.9.0

2 files

0.8.1

2 files

0.6.0

2 files

0.5.6

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.3

2 files

0.2.2

2 files

0.2.0

2 files

0.1.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page