Rust-powered EPUB2/EPUB3 library for Python. Fast reading, writing, validation, and markdown conversion.
pip install fast-ebookfast-ebook
Rust-powered EPUB2/EPUB3 library for Python. Fast reading, writing, validation, and markdown conversion — MIT-licensed.
How fast?
Converting War and Peace (1.8 MB EPUB) to a single markdown document:
| Library | Time | |
|---|---|---|
| ebooklib + html2text | 375 ms | baseline |
fast-ebook book.to_markdown() | 56 ms | 6.7x faster |
from fast_ebook import epub
book = epub.read_epub('war_and_peace.epub')
markdown = book.to_markdown()
Other operations on the same book — read+extract every chapter is 3x faster, get_item_with_id is 78x faster. Full numbers and methodology: docs/benchmarks.md.
Installation
pip install fast-ebook
Quick Start
Migration from ebooklib
The public API mirrors ebooklib — for most code you only need to change the import:
from fast_ebook import epub
import fast_ebook # for ITEM_* constants
Or use the drop-in compatibility layer for a one-line change:
import fast_ebook.compat as ebooklib
from fast_ebook.compat import epub
Read
from fast_ebook import epub
import fast_ebook
book = epub.read_epub('book.epub')
print(book.get_metadata('DC', 'title'))
for img in book.get_items_of_type(fast_ebook.ITEM_IMAGE):
print(img.get_name(), len(img.get_content()), 'bytes')
item = book.get_item_with_id('chapter1')
for entry in book.toc:
print(entry.title, entry.href)