Skip to main content
https://travis-ci.org/c-w/Gutenberg.svg?branch=master

Overview

This package contains a variety of scripts to make working with the Project Gutenberg body of public domain texts easier.

The functionality provided by this package includes:

  • Downloading texts from Project Gutenberg.

  • Cleaning the texts: removing all the crud, leaving just the text behind.

  • Making meta-data about the texts easily accessible.

The package has been tested with Python 2.6, 2.7 and 3.4

Installation

This project is on PyPI, so I’d recommend that you just install everything from there using your favourite Python package manager.

pip install gutenberg

If you want to install from source or modify the package, you’ll need to clone this repository:

git clone https://github.com/c-w/Gutenberg.git

This package depends on Berkeley DB so you’ll need to install that:

sudo apt-get install libdb5.1-dev
export BERKELEYDB_DIR=/usr

Now, you should probably install the dependencies for the package and verify your checkout by running the tests.

cd Gutenberg

virtualenv --no-site-packages virtualenv
source virtualenv/bin/activate
pip install -r requirements.pip

pip install nose
nosetests

Usage

Downloading a text

from gutenberg.acquire import load_etext
from gutenberg.cleanup import strip_headers

text = strip_headers(load_etext(2701)).strip()
print(text)  # prints 'MOBY DICK; OR THE WHALE\n\nBy Herman Melville ...'

Looking up meta-data

Title and author meta-data can queried:

from gutenberg.query import get_etexts
from gutenberg.query import get_metadata

print(get_metadata('title', 2701))  # prints 'Moby Dick; Or, The Whale'
print(get_metadata('author', 2701)) # prints 'Melville, Hermann'

print(get_etexts('title', 'Moby Dick; Or, The Whale'))  # prints (2701, ...)
print(get_etexts('author', 'Melville, Hermann'))        # prints (2701, ...)

Note: The first time that one of the functions from gutenberg.query is called, the library will create a rather large database of meta-data about the Project Gutenberg texts. This one-off process will take quite a while to complete (18 hours on my machine) but once it is done, any subsequent calls to get_etexts or get_metadata will be very fast.

Limitations

This project deliberately does not include any natural language processing functionality. Consuming and processing the text is the responsibility of the client; this library merely focuses on offering a simple and easy to use interface to the works in the Project Gutenberg corpus. Any linguistic processing can easily be done client-side e.g. using the TextBlob library.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Gutenberg-0.4.1.tar.gz (9.9 kB view details)

Uploaded Source

File details

Details for the file Gutenberg-0.4.1.tar.gz.

File metadata

  • Download URL: Gutenberg-0.4.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Gutenberg-0.4.1.tar.gz
Algorithm Hash digest
SHA256 286525e599303c09a803616426647229bef65bca0cfe94e222b751ccbb591230
MD5 1fc39f6e550917dbd18af799cde5315b
BLAKE2b-256 6e529d00f84986e30f39d3926b9e58ca418431f0497ace818b30b1bf8b6bb3c5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.8.2

2 files

0.8.1

1 file

0.8.0

1 file

0.7.0

1 file

0.6.1

1 file

0.5.0

1 file

0.4.5

2 files

0.4.4

1 file

0.4.2

1 file

This release

0.4.1 This release

1 file

0.4.0

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.1

1 file

0.1.0

1 file

0.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page