|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: May 2026
Location: Ontario, Canada
Device: Kindle Oasis (last gen)
|
CalibreQuarry and cquarry: small read-only tools for Calibre libraries
Hello everyone.
I'm a computer engineering student and have used Calibre for years. My library is a few thousand books with a lot of virtual libraries and hierarchical tags, and I kept wanting answers the GUI doesn't really give: which series have gaps, how much is unrated, what's actually inside a given virtual library. So I built some command-line tools for my own use. They get used constantly on my machine, and I'm posting them here in case someone else finds them handy. Posting these particular tools in this particular place is doubly intimidating for me, because they work by reading Calibre's database directly, and this is the forum where Kovid Goyal and the people who actually build Calibre are active. But they're genuinely useful to me, and they might be to someone else, so here goes. What they are CalibreQuarry: a CLI (and a small TUI if you run it with no arguments) that opens metadata.db directly, in SQLite read-only mode. It does catalogs, stats, series gap detection, audits, and exports. cquarry: the Python library underneath it, zero dependencies. If you write your own scripts against your library, this is probably the more useful half. Both MIT, on GitHub and PyPI. Links at the bottom. Searching The search tries to speak Calibre's own grammar, so most of what you'd type into Calibre's search bar works the same way: Code:
cquarry --search 'series:Mistborn and rating:>=4' cquarry --search 'formats:PDF and not formats:EPUB' cquarry --search 'search:"Needs Filtering"' # saved searches work too cquarry --stats --restrict 'vl:The Tabletop' # scope any mode to a virtual library Some examples Code:
cquarry --series # completeness + gap detection cquarry --audit # untagged/unrated/coverless books, duplicates, db-vs-folder mismatches cquarry --fts "the spice must flow" # content search over Calibre's full-text index cquarry --export --format csv # the whole library Code:
Aubrey-Maturin: 20 of 20 (complete) Asian Saga: Chronological Order: 4 of 6 (incomplete) ⚠ missing: 2, 3 It still works. It reads straight from the database when it can, and if Calibre holds the lock it reads from a temporary snapshot instead (it says so, and the results reflect the last saved state). Nothing in the read path can write anything. A note on reading the format directly I know metadata.db is an internal Calibre format, not a documented interface, and that it can change between releases. I take that seriously. The read path opens the database in SQLite read-only mode, so the connection itself can't write. Part of maintaining the library is chasing those schema changes when they land. And when something doesn't look the way it expects, it says so rather than guessing. If anyone here who knows the format better than I do spots me doing something unwise, tell me and I'll fix it. About writes I was nervous about letting a program touch metadata.db at all, so the write side is deliberately awkward to do damage with. It's dry-run by default: Code:
# just prints the plan: the ids it resolved and the verbs it would run cquarry --from-search 'tags:Unsorted' --batch-add-tag Audited Code:
# apply needs Calibre closed and a backup outside the library, then runs # the whole pass as one transaction cquarry --from-search 'tags:Unsorted' --batch-add-tag Audited --apply --backup-dir ~/backups The library underneath Code:
from cquarry.db import CalibreDB
with CalibreDB("~/Calibre Library/metadata.db") as db:
books = db.search("tags:Fic.SciFi and rating:>=4")
to_read = db.resolve_vl("To Read")
notes = db.get_annotations(42)
Install Code:
pip install calibrequarry # the CLI; the command is cquarry pip install cquarry # the library One more thing: this code was written with a lot of AI assistance (it's how I learn). If you'd rather not use software written by AI, I completely understand. My feelings won't be hurt, but the AI's will. (jkjk) Links: CalibreQuarry: https://github.com/VirInvictus/CalibreQuarry cquarry: https://github.com/VirInvictus/cquarry Thanks for reading. If you try it and something breaks, I'd genuinely like to know. And if you have questions, replies in this thread are the best way to reach me. ![]() Also, a big thank you to Kovid for making such a wonderful application. It really changed how I interact with books. These tools are just my attempt to express that in the CLI. |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 46,488
Karma: 29634066
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You're welcome, though why not just use the builtin calibredb command line tool with a script?
|
|
|
|
| Advert | |
|
|
|
|
#3 | |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: May 2026
Location: Ontario, Canada
Device: Kindle Oasis (last gen)
|
Quote:
What ended up mattering:
And to be fair about where calibredb wins, it isn't close: adding books with the metadata plugins, the embed/backup/restore/clone verbs, content-server access to remote libraries, catalog generation to EPUB or MOBI, and schema changes tracked upstream automatically instead of by me. My run flush verb literally shells out to calibredb embed_metadata, because it is the right tool for that job. If any of this is already in calibredb and I missed it, I'd genuinely like to know. I'd rather lean on the builtin where it fits. |
|
|
|
|
![]() |
| Tags |
| calibre, calibrequarry, cquarry, metadata, sqlite |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| dictutil: Tools, documentation, and libraries related to Kobo dictionaries | geek1011 | Kobo Reader | 99 | 03-05-2026 05:25 PM |
| Small images impossible to read (Kindle-Calibre-.MOBI). | kpoviv | Amazon Kindle | 10 | 07-05-2022 08:25 AM |
| Small (-ish) GUI issues Virtual Libraries/Searches | StillReading | Calibre | 9 | 10-09-2015 09:00 AM |
| Copy/Move books between libraries using command line tools | jameszh | Library Management | 3 | 02-15-2011 09:02 AM |
| PDF's too small to read | Jenny123 | Sony Reader | 4 | 05-08-2009 05:56 PM |