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.3.0

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.3.0
File Size Uploaded Provenance Actions
epubchapterize-0.3.0.tar.gz 15.7 kB Without provenance Details for epubchapterize-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 26.0 kB

Release files / epubchapterize-0.3.0.tar.gz

Download URL epubchapterize-0.3.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
163cc6ce8003bdb4c2c848824e6870e0449364c4b1ac275f173f728e9b92d370
BLAKE2b-256 checksum
How to use checksums
e86b9556dd56c8490c2cced28d4fe1a45429242bd4040fb58400081cc44d4a16
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.3.0-py3-none-any.whl

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

Security for epubchapterize 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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