|
1 | 1 | # py-gutenberg |
2 | 2 |
|
3 | | -[](https://pypi.org/project/py-gutenberg/) [](https://pypi.org/project/py-gutenberg/releases) [](https://github.com/peterrauscher/py-gutenberg/actions) [](https://github.com/peterrauscher/py-gutenberg/blob/main/LICENSE) |
| 3 | +[](https://pypi.org/project/py-gutenberg/) [](https://github.com/peterrauscher/py-gutenberg/actions) [](https://github.com/peterrauscher/py-gutenberg/actions) [](https://github.com/peterrauscher/py-gutenberg/blob/main/LICENSE) [](https://pypi.org/project/py-gutenberg/releases) [](https://pypi.org/project/py-gutenberg) |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The **py-gutenberg** package is a Python library that provides methods to access the [Project Gutenberg](https://www.gutenberg.org/) 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. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +> **_⚠️_** This package has only been tested on Python 3.7 and above. There are no plans for a Python 2 version. |
| 12 | +
|
| 13 | +The package can be installed using the pip package manager: |
| 14 | + |
| 15 | +```sh |
| 16 | +pip install py-gutenberg |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +You should import the module like so: |
| 22 | + |
| 23 | +```python |
| 24 | +from gutenberg import GutenbergAPI |
| 25 | +``` |
| 26 | + |
| 27 | +> The `GutenbergAPI` constructor defaults to using the public instance of the Gutendex API, `https://gutendex.com`. If you are [self-hosting the API](#thanks), you can specify the IP address or URL of your instance with the `instance_url` parameter. |
| 28 | +
|
| 29 | +```python |
| 30 | +# Uses the public instance |
| 31 | +gb = GutenbergAPI() |
| 32 | +# Uses a self-hosted instance |
| 33 | +gb_private = GutenbergAPI(instance_url="https://gutendex-two.com") |
| 34 | +``` |
| 35 | + |
| 36 | +### Book Lists and Searching |
| 37 | + |
| 38 | +Here's a simple example to get a list of the most recently uploaded books: |
| 39 | + |
| 40 | +```python |
| 41 | +gb.get_all_books() |
| 42 | +``` |
| 43 | + |
| 44 | +Or, to get only public domain books: |
| 45 | + |
| 46 | +```python |
| 47 | +gb.get_public_domain_books() |
| 48 | +``` |
| 49 | + |
| 50 | +### Individual Books |
| 51 | + |
| 52 | +To get an individual book's metadata: |
| 53 | + |
| 54 | +```python |
| 55 | +gb.get_book_metadata() |
| 56 | +``` |
| 57 | + |
| 58 | +Or, to get the full text of a book: |
| 59 | + |
| 60 | +```python |
| 61 | +gb.get_book_text() |
| 62 | +``` |
| 63 | + |
| 64 | +Full usage information is available in [the documentation](https://github.com/peterrauscher/py-gutenberg/wiki/Documentation) |
| 65 | + |
| 66 | +## Thanks |
| 67 | + |
| 68 | +This module is built on the **wonderful** but unofficial API built by [@garethbjohnson](https://github.com/garethbjohnson) over at [gutendex.com](https://gutendex.com). I have no reason to believe the hosting they've setup is meant to sustain more than a few concurrent users, so please be kind a limit your requests where possible. Additionally, if you intend to use this in a production environment, it is highly encouraged that you self-host. |
| 69 | + |
| 70 | +### Read about [self-hosting the API here!](https://github.com/garethbjohnson/gutendex/wiki/Installation-Guide) |
0 commit comments