The py-gutenberg package is a Python library that provides methods to access the Project Gutenberg library. Users can search for books based on a variety of metadata, get full texts in various formats, and retrieve metadata for books by their ID number.
⚠️ This package has only been tested on Python 3.7 and above. There are no plans for a Python 2 version.
The package can be installed using the pip package manager:
pip install py-gutenberg
You should import the module like so:
from gutenberg import GutenbergAPI
The
GutenbergAPI
constructor defaults to using a public instance of the Gutendex API, hosted by me athttps://gutendex.devbranch.co
. If you are self-hosting the API, you can specify the IP address or URL of your instance with theinstance_url
parameter.
# Uses the public instance
gb = GutenbergAPI()
# Uses a self-hosted instance
gb_private = GutenbergAPI(instance_url="https://gutendex.yourdomain.com")
Here's a simple example to get a list of the most recently uploaded books:
gb.get_all_books()
Or, to get only public domain books:
gb.get_public_domain_books()
To get an individual book's metadata:
gb.get_book_metadata()
Or, to get the full text of a book:
gb.get_book_text()
Full usage information is available in the documentation
This module is built on the wonderful but unofficial API built by @garethbjohnson known as Gutendex. By default, this library uses a public instance I'm hosting myself, but does not have the bandwidth to maintain more than a few concurrent users. Please be kind and limit your requests where possible. Additionally, if you intend to use this library in a production environment, I highly encourage you to self-host.