Easy access to the Project Gutenberg catalog and books
Project description
gutenberg-books
Easy access to the entire Project Gutenberg catalog + book downloading
A lightweight, modern Python library that lets you explore 70,000+ public-domain books from Project Gutenberg with zero hassle.
- Search by subject, author, language, title, or year
- Weighted random sampling (realistic distribution)
- Polite book downloading with built-in delays (respects Gutenberg's robot policy)
- Fully offline after the first run
Installation
pip install gutenberg-books
Quick Start
from gutenberg_books import GutenbergBooks
# Initialize (downloads ~12 MB catalog on first run and caches it)
gb = GutenbergBooks() # default cache: ./GutenbergBooks
# Explore the catalog
print(gb.topn_subjects(5))
print(gb.topn_authors(5))
# Random books (weighted by popularity)
print(gb.random_books(n=3, seed=42))
# Search
results = gb.search_books(subject="Pride and Prejudice")
print(results[["Title", "Authors", "Language"]])
# Books whose authors were alive in a specific year
print(gb.books_matching_year(1813)) # e.g. Jane Austen era
# Download books (safe & polite)
gb.download_book(1342) # Pride and Prejudice
paths = gb.download_n_books(10, subject="Science Fiction", random_delay_sec=5)
paths = gb.download_size_books(size_mb=256, random_delay_sec=5)
All returned data are pandas DataFrames — easy to filter, save to CSV, or use in ML pipelines.
Main Features
| Feature | Method | Description |
|---|---|---|
| Top-N lists | topn_subjects(n), topn_authors(n) etc. |
Most frequent subjects, authors, languages, bookshelves |
| Weighted random | random_subjects(n, seed), random_authors(n, seed) |
Realistic sampling |
| Search | search_books(...) |
Multi-criteria search |
| Subject / Author filter | books_matching_subject(substr) |
Case-insensitive |
| Year-based search | books_matching_year(year) |
Authors alive in that year |
| Download single book | download_book(book_id, random_delay_sec=5) |
Returns Path to file |
| Download multiple books | download_books(book_ids, ...) |
List of IDs |
| Download by subject | download_n_books(n, subject, ...) |
First N matching books |
| Download until total size | download_size_books(size_mb, ...) |
Great for big-data test sets |
Important: The download methods include random delays by default to respect Project Gutenberg's robot access policy.
Advanced Usage
# Use custom cache location
gb = GutenbergBooks(cache_dir="~/my_gutenberg_cache")
# Refresh catalog
gb.refresh_catalog()
# All unique values (pre-computed)
print(gb.all_subjects[:10])
print(gb.all_authors[:10])
Development
See the Development section in the repository for how to run tests, build the package, and contribute.
License
MIT © groda
Made with ❤️ for book lovers, data scientists, and developers.
Want to contribute? Open a PR on GitHub!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gutenberg_books-0.1.2.tar.gz.
File metadata
- Download URL: gutenberg_books-0.1.2.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bfbd2d1505a5ca158f7c1675740ab3f7ccd9611a2e419baac86466622b78994
|
|
| MD5 |
467884ba395b93da27fa594b69d7d951
|
|
| BLAKE2b-256 |
cc5e14f44cd71615368bf79ffa245aca5607384b2217ad43b3ba71b656cd5733
|
File details
Details for the file gutenberg_books-0.1.2-py3-none-any.whl.
File metadata
- Download URL: gutenberg_books-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d5cdb0e3608d42c9aa4e30af209633d88a0201ed760ac11983606c972f11dd7
|
|
| MD5 |
4aacfefdb9e2572f5620ef4f8db7999d
|
|
| BLAKE2b-256 |
cab1cb5d95eb20fc52e08f009f499f2b5afb39947a9c6906d1df86b789067bfd
|