Skip to main content

A production-grade Python CLI book search and download application.

Project description

๐Ÿ“š BookCLI

Python License: MIT Author GitHub

BookCLI is a production-grade, clean-architecture command-line interface (CLI) application built in Python 3.12+. It enables you to concurrently search multiple legal book sources, intelligently rank and merge metadata, cache details locally, and safely download public domain/free books directly from the terminal with a beautiful Rich UI.

โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—     โ–ˆโ–ˆโ•—
โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•‘
โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ• โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•‘
โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•‘
โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•—โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•  โ•šโ•โ•โ•โ•โ•โ•  โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•  โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•
     Search, inspect, and legally download books
          Powered by Open Library & Gutenberg
              Developer - Dipesh Malla
                 GitHub : greycode009

๐ŸŒŸ Key Features

  • โšก Concurrent Multi-Provider Search: Queries Google Books, Open Library, Project Gutenberg, and the Internet Archive concurrently using async/await handlers.
  • ๐Ÿ“Š Clean & Interactive TUI Dashboard: Launch the dashboard menu with zero arguments to browse options, review search history, access favorites, inspect cache stats, and customize app configurations.
  • ๐Ÿง  Intelligent Deduplication & Ranking: Merges results from all providers using RapidFuzz fuzzy matching on title/author strings. Automatically ranks entries based on metadata completeness and direct download availability.
  • ๐Ÿ”’ Safe & Legal Downloads: Only downloads books that are explicitly public domain or marked as free by their host provider.
  • โฌ HTTP Range-Resume Downloads: Supports HTTP Range headers for downloading larger books safely; auto-resumes interrupted connections with standard Rich progress displays.
  • ๐Ÿ“‚ Direct OS File Integration: Automatically launch downloaded books (EPUB, PDF, TXT) inside your default OS-registered reader using standard process controls.
  • ๐Ÿ’พ Local Caching & Offline State: Backed by a local SQLite database using aiosqlite, providing fast offline retrieval of previously searched metadata, history logs, and favorites.
  • ๐Ÿ› ๏ธ Flexible Configurations: Toggle providers, set custom cache TTLs, change client timeout constraints, and update default download pathways directly from the CLI or dashboard settings.

๐Ÿ›๏ธ Clean Architecture

The codebase adheres strictly to Clean Architecture principles to separate core services, data layers, providers, and presentation:

graph TD
    User[User] -->|Interact| CLI[cli.py / TUI Dashboard]
    CLI -->|Execute commands/search| SearchService[services/search.py]
    CLI -->|Manage settings| ConfigService[config.py / settings.py]
    CLI -->|Track queries/favs| HistoryService[services/history.py]
    CLI -->|Open files| Opener[opener.py]
    CLI -->|Download files| Downloader[downloader.py]
    
    SearchService -->|Rank/De-duplicate| RankingService[services/ranking.py]
    SearchService -->|Cache lookup/write| CacheService[cache.py]
    SearchService -->|Concurrent requests| Providers[Providers Layer]
    
    CacheService -->|Local database| SQLite[(SQLite: bookcli.db)]
    HistoryService -->|Local database| SQLite
    
    Providers -->|API| GoogleBooks[Google Books Provider]
    Providers -->|API| OpenLibrary[Open Library Provider]
    Providers -->|Scrape/Download| Gutenberg[Project Gutenberg]
    Providers -->|Search/Download| InternetArchive[Internet Archive]

Directory Layout

bookcli/
โ”œโ”€โ”€ database/            # Database initialization and schema migrations
โ”‚   โ””โ”€โ”€ migrations.py
โ”œโ”€โ”€ providers/           # Concretely implemented API / web providers
โ”‚   โ”œโ”€โ”€ base.py          # Abstract base client provider
โ”‚   โ”œโ”€โ”€ google_books.py
โ”‚   โ”œโ”€โ”€ gutenberg.py
โ”‚   โ”œโ”€โ”€ internet_archive.py
โ”‚   โ””โ”€โ”€ openlibrary.py
โ”œโ”€โ”€ services/            # Pure domain services (business rules)
โ”‚   โ”œโ”€โ”€ history.py       # Query log tracking
โ”‚   โ”œโ”€โ”€ ranking.py       # Metadata scoring and deduplication (RapidFuzz)
โ”‚   โ””โ”€โ”€ search.py        # Orchestrates concurrent API querying & caching
โ”œโ”€โ”€ cache.py             # SQLite metadata cache mechanisms
โ”œโ”€โ”€ cli.py               # Typer/Rich CLI interface and main interactive loop
โ”œโ”€โ”€ config.py            # Pydantic models for configuration and serialization
โ”œโ”€โ”€ downloader.py        # Async downloader with range-resume & rich progress bars
โ”œโ”€โ”€ exceptions.py        # Domain-specific custom exception hierarchy
โ”œโ”€โ”€ opener.py            # Platform-specific document launcher
โ”œโ”€โ”€ settings.py          # Default constants and path configuration directories
โ””โ”€โ”€ utils.py             # Clean utilities (unit formatting, filenames)

๐Ÿš€ Installation

Ensure you have Python 3.12+ installed on your system.

  1. Clone the Repository

    git clone https://github.com/Greycode009/bookcli.git
    cd bookcli
    
  2. Install in Editable Mode

    pip install -e .
    

Command Execution wrappers

Once installed, the CLI tool is available globally as the book command. If the python script directory is not present on your PATH, you can use the wrappers provided in the project root:

  • Windows (PowerShell/CMD): .\book.bat <command>
  • Linux / macOS / Git Bash: ./book <command>
  • Python Direct Module: python -m bookcli.cli <command>

๐ŸŽฎ How to Use

๐Ÿ–ฅ๏ธ 1. The Interactive Dashboard

Run book without arguments in an interactive terminal to enter the console dashboard:

book

This launches a complete navigation dashboard:

  1. ๐Ÿ” Search Books: Prompts for a search query and filters, then displays search results.
  2. ๐Ÿ“œ Search History: Shows list of past queries. Includes an option to clear history.
  3. โญ Favorite Books: Displays all favorited items with quick options to download (d <index>), open in reader (o <index>), or remove (r <index>).
  4. โšก Metadata Cache Stats: Shows cache storage metadata sizes.
  5. ๐Ÿงน Clear Metadata Cache: Evicts database-cached search metadata.
  6. โš™๏ธ Settings / Configuration: Change active settings interactively (download path, client timeouts, toggling search providers).
  7. Exit Dashboard.

Inline Search Explorer Actions

Inside the Search Books menu:

  • Enter <ID> to download the book (e.g., 1).
  • Enter <ID> -o <path> or <ID> --output <path> to save to a custom path (e.g., 1 -o C:\downloads or 1 -o book.epub).
  • Enter i <ID> to show complete details (description, pages, published year, publishers, ISBN).
  • Enter f <ID> to add to favorites.
  • Enter o <ID> to open a downloaded file in the OS default reader.
  • Enter q to return to the main dashboard menu.

โš™๏ธ 2. Direct CLI Command Reference

If you prefer to bypass the dashboard, you can invoke direct commands from your shell:

Concurrently Search Providers

book search "Clean Architecture"

Filter searches by specific parameters:

book search "Relativity" --subject "Physics"
book search "Refactoring" --author "Martin Fowler"

Export results directly to a structured file:

book search "Science" --export results.json
book search "History" --export history_books.csv

Get Detailed Information

View structured metadata cards of search entries using either a short session ID (e.g., 1, 2) from your last search or a provider-specific key (e.g., gutenberg:1342):

book info 1

Download Books Legally

Download files with async resume support and live progress bars. Custom output paths automatically resolve folder hierarchies:

# Save to default downloads folder (~/.bookcli/downloads)
book download 1

# Save to custom directory
book download 1 --output "D:\Books"

# Save to custom file path
book download 1 -o "/Users/greycode/Desktop/design_patterns.epub"

Open Files Instantly

Fire up files inside the OS default viewer:

book open 1

Manage Favorites

book favorite add 1
book favorite list
book favorite remove gutenberg:1342

Manage Cache and History

# Show cache count and storage dates
book cache stats

# Remove all cached records
book cache clear

# List past search queries
book history

Modify Settings

Show settings or update values:

# Display settings
book config

# Set default downloads directory
book config set download-dir "C:\Users\Dipesh\Downloads"

# Adjust network client timeout
book config set timeout 20

# Disable Google Books search provider
book config set provider false google-books

๐Ÿ› ๏ธ Development & Testing

Running Tests

To run the project test suites (if pytest is installed in your python environment):

python -m pytest --cov=bookcli

Data Storage Directories

By default, BookCLI stores its application databases and configurations in:

  • Default directory: ~/.bookcli/ (resolves to C:\Users\<User>\.bookcli on Windows)
  • Database: ~/.bookcli/bookcli.db
  • Settings File: ~/.bookcli/config.json
  • Download Path: ~/.bookcli/downloads/

You can redirect the home directory by setting the BOOKCLI_HOME environment variable.


๐Ÿ‘ค Author


๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bookcli-0.2.2.tar.gz (36.6 kB view details)

Uploaded Source

Built Distribution

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

bookcli-0.2.2-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file bookcli-0.2.2.tar.gz.

File metadata

  • Download URL: bookcli-0.2.2.tar.gz
  • Upload date:
  • Size: 36.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for bookcli-0.2.2.tar.gz
Algorithm Hash digest
SHA256 40d6d622aa4292fdbd228dfe1b632608f732f429ceea62d7fafdadb92e6f307b
MD5 3f2372ea35c725224522ba9bce3a5e90
BLAKE2b-256 6c9a8362d47273796c6bf5c0cbad6e22012bbfc620bb4ae211021b477baa8677

See more details on using hashes here.

File details

Details for the file bookcli-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: bookcli-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 41.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for bookcli-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c981765f0fb54cc26eda514bdf1d3fdf6fa5d59fd3e27829972f316ac936cf3
MD5 39527b9ce4403346125700f9d3c4c6d5
BLAKE2b-256 cc978408217c33e8536c1411a35e3cb8137b12d85c35af6bce8378f52296a431

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page