TomeTrove is a command-line application built with Textual for managing your personal digital library of books (primarily PDFs, EPUBs, DOCX, etc.). It allows you to add, edit, view, search, and organize your books, all within a rich terminal user interface.
- π Library Management: View your book collection in a sortable, filterable table.
- β Add New Books: Easily add new books from your filesystem.
- Files are copied into an organized library structure (by author).
- Automatic filename generation based on title and author for consistency.
- βοΈ Edit Book Metadata: Modify title, author, tags, series information, read status, description, and more.
- π·οΈ Tagging System: Organize books with custom tags.
- Autocomplete for existing tags when adding/editing.
- βοΈ Author Autocomplete: Suggests existing authors during input.
- π Search Functionality: Quickly find books by title or author.
- π Read Status: Mark books as read and record the date (or clear read status).
- π οΈ PDF/File Metadata Update: Optionally updates file metadata (Author, Title, Keywords, Description) using ExifTool when adding new books.
- π Open Books: Launch books with your system's default application directly from the TUI.
- βοΈ Configuration: Manage essential application paths (library, database, logs, ExifTool) via an in-app settings screen or by directly editing
config.json. - β¨ Rich TUI: Modern and responsive terminal interface powered by Textual, with interactive forms and tables.
- π Logging: Application events and errors are logged for easier debugging.
-
Clone the repository:
git clone https://github.com/salvodif/TomeTrove.git cd TomeTrove -
(Recommended) Create and activate a Python virtual environment:
python -m venv venv # On Linux / macOS source venv/bin/activate # On Windows (Command Prompt / PowerShell) .\venv\Scripts\activate
-
Install Python dependencies: Ensure you have a
requirements.txtfile with the following content:textual tinydb textual-autocomplete
Then run:
pip install -r requirements.txt
-
Install ExifTool (External Dependency for Metadata): TomeTrove uses ExifTool to update file metadata (e.g., author, title in PDFs).
- Download from the ExifTool Official Website.
- Follow their installation instructions for your operating system.
- Make sure its path is correctly configured in
config.jsonor via the in-app settings.
Before the first run, or to customize paths, create/edit the config.json file in the same directory as main.py.
An example template can be found in the file config.json.template.
Here's an example structure (adjust paths for your system):
{
"paths": {
"tinydb_file": "library.json",
"library_path": "/path/with/yours/pdfs",
"upload_dir_path": "/default/path/where/look/for/pdf/to/upload",
"exiftool_path": "/exiftool/path/exiftool.exe",
"log_dir": "/logs/path"
}
}tinydb_file: Name of the TinyDB database file (e.g.,library.json). It will be created inside yourlibrary_path.library_path: The root directory where your book files will be organized (by author) and stored. This is a critical path.upload_dir_path: Default directory the file browser will open to when adding new books.exiftool_path: Full path to the ExifTool executable. Required if you want file metadata to be updated. For Windows, this would end in.exe. For Linux/macOS, it's usually justexiftoolif it's in your system's PATH, or the full path to the executable.log_dir: Directory where log files will be stored (can be relative to the script or an absolute path).
You can also configure these paths through the Settings screen (Ctrl+S) within the application after the first run.
- Ensure you have followed the Installation and Configuration steps.
- Navigate to the
TomeTroveproject directory in your terminal (wheremain.pyis located). - Run the application:
python main.py
The application will start, displaying your book library (empty at first). Use the keybindings below to navigate and manage your books.
| Key | Action | Description |
|---|---|---|
Ctrl+A |
Add Book | Opens the screen to add a new book to the library. |
E |
Edit Book | Opens the selected book's details for editing. |
Ctrl+F |
Search | Opens a prompt to search books by title or author. |
F5 |
Reset Search | Clears the current search and displays all books. |
Ctrl+O |
Open Book | Opens the selected book file with the default app. |
Ctrl+R |
Reverse Sort / Sort by Column | Reverses the current sort order. If a column header is focused, sorts by that column. |
Ctrl+S |
Settings | Opens the application settings screen. |
Arrow Keys |
Navigate Table | Move selection up/down in the book list. |
Escape |
Back / Cancel | Closes modals, forms, or navigates back. |
π‘ Example Workflow: Adding a Book
- Press
Ctrl+A. - The "Add Book" screen appears.
- Use the directory tree to navigate to and select your book file (PDF, EPUB, etc.).
- The selected file path will appear.
- Fill in the Title, Author (autocomplete available), Tags (autocomplete available), and other optional fields.
- Click the "Salva" (Save) button.
- The book is copied to your
library_path(organized by author), metadata is (optionally) updated using ExifTool, and it's added to the database and main table.
- Textual: Core framework for the Terminal User Interface (TUI).
- TinyDB: A lightweight, document-oriented database used for storing book metadata in a JSON file.
- textual-autocomplete: Provides autocompletion for author and tag input fields.
- ExifTool: An external command-line application for reading, writing, and editing meta information in a wide variety of files (used here for PDF/EPUB/DOCX metadata).
- Python
pathlib: For robust and cross-platform path manipulation. - Python
subprocess: For interacting with ExifTool. - Python
logging: For application logging.
The tools/ directory contains several utility scripts to help manage your TomeTrove library and data.
This script is designed to import your existing book library from a Calibre export into TomeTrove's TinyDB database.
Functionality:
- Reads a JSON file exported from Calibre (containing book metadata).
- Copies book files (PDFs and other formats) from their original Calibre locations to the TomeTrove
library_path, organizing them into author-specific subdirectories. - Attempts to update PDF metadata (title, author, tags) using ExifTool.
- Creates corresponding entries in the TomeTrove
library.jsondatabase. - Logs the import process, including any errors encountered.
Usage:
- Export your Calibre library to JSON:
- You can use Calibre's
calibredb listcommand-line tool. Refer to the official Calibre documentation for detailed instructions: calibredb list documentation. - A typical command might look like this (run from your terminal/command prompt):
This command exports the specified fields for all books into a JSON file named
calibredb list --for-machine --fields authors,title,formats,tags,series,series_index,comments,last_modified > calibre_books.jsoncalibre_books.json. Make sure to include at leastauthors,title, andformats.
- You can use Calibre's
- Place
calibre_books.json: Put the exported JSON file in the same directory asimport_calibre_to_tinydb.pyor specify its path when running the script (currently, the script defaults to looking forcalibre_books.jsonin its own directory). - Configure Paths: Ensure your
config.jsonfor TomeTrove has the correctlibrary_path(where books will be copied) andexiftool_path. - Run the script:
python tools/import_calibre_to_tinydb.py
- The script will process the JSON, copy files, and create/update your
library.json. - Check the generated log file in the
logs/directory (as specified inconfig.jsonor the script's default) for details and any errors.
- The script will process the JSON, copy files, and create/update your
Important Notes for import_calibre_to_tinydb.py:
- The script assumes that the paths to your book files listed in the Calibre JSON export are accessible from where you run the script.
- It tries to handle different text encodings for the JSON file but UTF-8 is preferred.
- PDFs for which metadata update via ExifTool fails will be copied to a
02 - PDF no metadata updateddirectory within yourlibrary_path. - Non-PDF files (e.g., EPUB, MOBI) associated with a book are copied to a
01 - non-PDFdirectory within yourlibrary_path.
This utility script allows you to pre-populate or update the tags table in your TomeTrove library.json database with a predefined set of tags and their associated icons.
Functionality:
- Connects to your
library.jsondatabase. - Iterates through a predefined dictionary of tag names and icons.
- If a tag already exists by name, it updates its icon.
- If a tag does not exist, it inserts a new tag entry with the name and icon.
Usage:
- Modify
tags_data(Optional): Opentools/add_tags_in_db.pyand edit thetags_datadictionary if you want to change the default tags or their icons. - Specify Database Path: Ensure the line
db = TinyDB('test_library.json')(or similar) in the script points to your actuallibrary.jsonfile, which should be located within your configuredlibrary_path.- Recommendation: It's best to modify this script to read the
library_pathandtinydb_filefrom your mainconfig.jsonfor consistency, rather than hardcodingtest_library.json.
- Recommendation: It's best to modify this script to read the
- Run the script:
The script will print messages indicating which tags were added or updated.
python tools/add_tags_in_db.py
This script helps verify the integrity of your TomeTrove library by checking if the book files referenced in your library.json database actually exist at their expected locations within your library_path.
Functionality:
- Reads your main
config.jsonto get thelibrary_pathandtinydb_filepath. - Iterates through all book entries in your
library.json. - For each book, it constructs the expected file path (based on author and filename).
- Checks if the file exists at that path.
- Reports any missing files or entries with missing filename/author information.
- Uses
coloramafor colored terminal output to highlight issues.
Usage:
- Ensure your main
config.jsonis correctly configured with the paths to your library and database. - Run the script from the root directory of your TomeTrove project:
The script will output a summary of any problems found.
python tools/checkpdf.py
This is a PowerShell script designed to count the number of non-PDF files present within a specified import/upload directory. It's useful for getting a quick overview before or after an import process if you're primarily interested in PDF files.
Functionality:
- Prompts the user to enter the path to the directory to scan (defaults to the current directory if none is provided).
- Recursively searches the specified directory and its subdirectories.
- Counts all files that do not have a
.pdfextension. - Outputs the total count of non-PDF files found.
Usage (Windows PowerShell):
- Open PowerShell.
- Navigate to the
tools/directory:cd path/to/TomeTrove/tools
- Run the script:
.\count_non_pdf.ps1
- When prompted, enter the path to the directory you want to analyze, or press Enter to scan the current directory (
tools/).
- Metadata Updates: File metadata updating (e.g., for PDFs) relies entirely on a correctly installed and configured ExifTool. If ExifTool is not found, misconfigured, or encounters an error with a specific file, metadata won't be updated (though the book will still be added to the TomeTrove library).
- File Organization: Books are organized into subdirectories by author name within the main
library_path. Renaming authors directly in the database will not automatically move or rename the corresponding physical files/folders. - Error Handling: While basic error handling and logging are implemented, complex edge cases or file corruption issues might not always be gracefully handled.
- No Cloud Sync: TomeTrove is a local application. For cloud synchronization of your library, you would need to manage the
library_pathdirectory (containing your books andlibrary.json) andconfig.jsonusing a third-party service like Dropbox, OneDrive, Nextcloud, Syncthing, etc. - Single User: Designed as a single-user local application.
- Scalability: For extremely large libraries (tens of thousands of books), TinyDB performance might eventually degrade.
Contributions, issues, and feature requests are welcome! Please feel free to:
- Open an issue on the TomeTrove GitHub repository.
- Fork the project and submit a pull request for bug fixes or new features.
When contributing, please try to:
- Follow the existing code style.
- Add comments to your code where necessary.
- Test your changes thoroughly.
This project is licensed under the MIT License - see the LICENSE file for details.

