Skip to main content

EpubChapterize

EpubChapterize is a Python package designed to split EPUB files into chapters programmatically. It provides a simple interface to process EPUB files and extract their chapters for further use. Currently optimized for Project Gutenberg EPUB3s — if it doesn't work for your use case please get in touch.

Installation

pip install epubchapterize

Usage

from epub_chapterize import chapterize

chapters, language, title, author, cover_image = chapterize("dracula.epub")

print(title)    # "Dracula"
print(author)   # "Bram Stoker"
print(language) # "en"

for chapter in chapters:
    print(chapter["title"])
    for sentence in chapter["sentences"]:
        print(sentence)

Return values

Value Type Description
chapters list[dict] List of chapter dicts, each with "title" and "sentences" keys
language str BCP 47 language code detected from the EPUB metadata (e.g. "en", "fr")
title str Book title from EPUB metadata
author str Author name from EPUB metadata
cover_image bytes | None Raw bytes of the cover image, or None if not found

Example output

For dracula.epub the returned chapters list looks like:

[
    {
        "title": "Jonathan Harker's Journal",
        "sentences": [
            "3 May. Bistritz.—Left Munich at 8:35 P. M., on 1st May, arriving at Vienna early next morning; should have arrived at 6:46, but train was an hour late.",
            "Buda-Pesth seems a wonderful place, from the glimpse which I got of it from the train and the little I could walk through the streets.",
            "I feared to go very far from the station, as we had arrived late and would start as near the correct time as possible.",
            "The impression I had was that we were leaving the West and entering the East; the most western of splendid bridges over the Danube, which is here of noble width and depth, took us among the traditions of Turkish rule."
        ]
    },
    {
        "title": "Jonathan Harker's Journal (Continued)",
        "sentences": [
            "5 May.—I must have been asleep, for certainly if I had been fully awake I must have noticed the approach of such a remarkable place.",
            "In the gloom the courtyard looked of considerable size, and as several dark ways led from it under great round arches, it perhaps seemed bigger than it really is.",
            ...
        ]
    },
    ...
]

The cover_image bytes can be written straight to a file:

if cover_image:
    with open("cover.jpg", "wb") as f:
        f.write(cover_image)

Supported languages

Sentence segmentation is supported for English, French, German, Spanish, Italian, Dutch, and Portuguese via NLTK's Punkt tokenizer (installed automatically). No extra downloads are required unless you switch to the spaCy backend.

Requirements

  • Python 3.13 or higher

License

MIT — see the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests at github.com/nzmattgrant/epubchapterize.

Author

Matthew Grant

Metadata

Release files for epubchapterize 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for epubchapterize 0.2.1
File Size Uploaded
epubchapterize-0.2.1.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for epubchapterize 0.2.1
File Interpreter ABI Platform
epubchapterize-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / epubchapterize-0.2.1.tar.gz

Download URL epubchapterize-0.2.1.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a9e765e449fbe853edac0af96ca868f7d4854c4c258223ce0db7882b34141499
BLAKE2b-256 checksum
How to use checksums
d9a43a1ba2c2800e642d4c58aeb908652771ce8b4c58976db70859344da1bb8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / epubchapterize-0.2.1-py3-none-any.whl

Download URL epubchapterize-0.2.1-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
008864ef1c1c62cb4c56dc008f1f91f26b491e3efdc45601ad11593713d85e6b
BLAKE2b-256 checksum
How to use checksums
ca8f42cf7cd69397a8e37efc5d7f5e52eecbcc7f988e6b35976eadd4bb77b9f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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