Skip to main content

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

PyPI version Python versions License

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=16, 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

gutenberg_books-0.1.3.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

gutenberg_books-0.1.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file gutenberg_books-0.1.3.tar.gz.

File metadata

  • Download URL: gutenberg_books-0.1.3.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

Hashes for gutenberg_books-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9bceb23a946154c3ace4a1516b13fc563b3b355141c5b7034f12a914cbb2be63
MD5 a0a2b1cabbbcbefbfeb3063c3b9b8a9c
BLAKE2b-256 c3cbadffc0b968e1fd118ef3c7291e939fa4faf15167280412de8481eb916939

See more details on using hashes here.

File details

Details for the file gutenberg_books-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gutenberg_books-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7f6bcc7adcbd8a9a364108b0158d0bbf33aaecba4184c95341b22f43157d77c6
MD5 3ec068843240c2ff278699d238df4b19
BLAKE2b-256 ef1facc35d9d49fca9d664b2df064a892b8523da2f4d0b5a71885e9890c9f787

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