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-4 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.33.0,<0.34.0. Any configured database access mode is overridden to read-only by this CLI. Older core schema versions must be rebuilt by H2HDB and ingest into a new empty database before syncing; this consumer does not migrate the database. 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.

Release files for h2hdb-komga 0.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h2hdb-komga 0.13.0
File Size Uploaded
h2hdb_komga-0.13.0.tar.gz 57.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for h2hdb-komga 0.13.0
File Interpreter ABI Platform
h2hdb_komga-0.13.0-py3-none-any.whl Python 3 none any Details

Total release size: 89.1 kB

Release files / h2hdb_komga-0.13.0.tar.gz

Download URL h2hdb_komga-0.13.0.tar.gz
Size 57.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2f336337591783d41ec7b52fd8129253b1789f4566777bf6c5f7cd683f719936
BLAKE2b-256 checksum
How to use checksums
0741e8410038d3af460db24228f356967b0e10969e4694f9b2c838aa8b546707
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / h2hdb_komga-0.13.0-py3-none-any.whl

Download URL h2hdb_komga-0.13.0-py3-none-any.whl
Size 31.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4f9a4e0766e2d427e8442a2d2f594ad0b2dfb50f7401c0183ed6224b7fcbb68
BLAKE2b-256 checksum
How to use checksums
711e191f666694f73a6f2daef222d2a7e855e4c107b37a7a1f9c04e6d6affbd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release history Release notifications | RSS feed

0.17.1

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.2

2 release files

0.15.1

2 release files

This release

0.13.0 This release

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.6.0

2 release files

0.5.6

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release 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