Overview
The books module provides functions for managing the library catalog, including local database operations and automatic metadata fetching from the Open Library API.Get Book
Parameters
ISBN-10 or ISBN-13 identifier. Leading/trailing whitespace is stripped automatically.
Returns
Returns book object if found (locally or via API),
None if not foundLookup Flow
- Local Database Check: Queries local SQLite database first
- Cache Hit: Returns immediately if book found locally
- API Fallback: If not found and
USE_LIVE_API = True, queries Open Library - Auto-Cache: Successful API results are automatically saved to local DB
- Offline Mode: Returns
Noneif not found locally andUSE_LIVE_API = False
Get Catalog
Returns
List of all books in the catalog, sorted alphabetically by title
Use Cases
- Browse Catalog: Display all books in the library
- Search Implementation: Client-side filtering by title/author
- Availability Check: Filter by status to show only available books
- Pagination: Split large catalogs across multiple pages
Add Book
Parameters
Unique ISBN identifier for the book
Book title
Primary author name
URL to book cover image. Defaults to empty string if not provided.
Returns
True: Book was successfully added to the catalogFalse: ISBN already exists in the database (duplicate)
Default Values
When a book is added, the following defaults are set automatically:status: “Available”shelf: "" (empty string)cover: "" if not provided
Fetch from Open Library
Parameters
ISBN to lookup in the Open Library API
Returns
Returns book object with fetched metadata, or
None on failureAPI Details
Endpoint:https://openlibrary.org/api/books
Request Format:
INSERT OR IGNORE
Error Handling
ReturnsNone in the following cases:
- HTTP response code is not 200
- ISBN not found in Open Library database
- Network timeout (8 seconds)
- Any other exception during API call or database insert
Configuration
Toggle API usage with:get_book() only searches the local database.