📖 ebook-rs
High-Performance Pure-Rust Multi-Format eBook Parsing & Reader Engine
Pure Rust multi-format eBook engine (EPUB 2/3, MOBI, AZW3, KFX, FB2, LIT, CBZ, PDF, ODT, DOCX, RTF, TXT & MD) featuring Mozilla UniFFI mobile bindings, Readium CFI locators & LCP DRM, SpeechSynthesis TTS word sync, CJK vertical & RTL pagination, academic PDF reflow, lossless EPUB3 optimizer, AI RAG BM25 chunking, zero-copy search, Zstd caching, Python/WASM bindings, and native MCP server.
📋 Table of Contents
- ⚡ Feature Parity Matrix
- 📊 Conversion Benchmarks
- 📦 Installation
- 🚀 Quick Start (Rust)
- 🐍 Python Bindings
- 🤖 Model Context Protocol (MCP) Server
- 💻 CLI Usage
- 📚 Complete API Reference
- 🏗️ Architecture Overview
- 🤝 Contributing
- 🙏 Acknowledgments
- 📜 License
⚡ Feature Parity Matrix
📂 Format Support
| Feature | 🚀 ebook-rs (v0.16.1) |
📦 epub.js |
📖 foliate-js |
🦀 rbook |
|---|---|---|---|---|
| EPUB 2 & 3 Support | ✅ Full OPF + NCX/NAV | ✅ Yes | ✅ Yes | ✅ Yes |
| EPUB 3 Fixed-Layout (FXL) | ✅ 2-page spread renderer | ✅ Yes | ✅ Yes | ❌ No |
| Amazon KFX (KF10) Support | ✅ Clean-room b"CONT" container |
❌ No | ✅ Yes | ❌ No |
| MOBI & AZW3 (KF8) Support | ✅ Native PalmDOC LZ77 | ❌ No | ✅ Yes | ❌ No |
| FB2 (FictionBook 2) Support | ✅ Native XML + xlink:href | ❌ No | ✅ Yes | ❌ No |
| KEPUB (Kobo EPUB) Support | ✅ Native | ❌ No | ✅ Yes | ❌ No |
| LIT (Microsoft Reader) Support | ✅ Native | ❌ No | ✅ Yes | ❌ No |
| CBZ (Comic Book ZIP) Support | ✅ Native ZIP Images | ❌ No | ✅ Yes | ❌ No |
| PDF Support & Academic 2-Column Reflow | ✅ pdf_oxide spatial reflow |
❌ No | ❌ No | ❌ No |
| ODT (OpenDocument Text) | ✅ Native XML + content.xml |
❌ No | ❌ No | ❌ No |
| DOCX (Microsoft Word) | ✅ Native WordML + rdocx |
❌ No | ❌ No | ❌ No |
| RTF (Rich Text Format) | ✅ Native Control Words + Unicode | ❌ No | ❌ No | ❌ No |
| TXT / Markdown Support | ✅ Auto-reflow sections | ❌ No | ❌ No | ❌ No |
| Auto Format Detection | ✅ Magic-byte detection | ❌ No | ❌ No | ❌ No |
🧭 Navigation, Rendering & Security
| Feature | 🚀 ebook-rs (v0.16.1) |
📦 epub.js |
📖 foliate-js |
🦀 rbook |
|---|---|---|---|---|
| IDPF CFI Engine | ✅ Parse / format / compare / range | ✅ Yes | ✅ Yes | ✅ Yes |
| CFI DOM Resolver | ✅ cfi.resolve_dom_path(html) |
✅ Yes | ✅ Yes | ❌ No |
| Readium CFI Unified Locator | ✅ Full model | ✅ Yes | ✅ Yes | ❌ No |
| Location / Reading Progress | ✅ locations_from_sections() |
✅ Yes | ✅ Yes | ✅ Yes |
| SpeechSynthesis TTS Word Synchronizer | ✅ tokenize_tts_words() token spans |
❌ No | ❌ No | ❌ No |
| SMIL Media Overlays (Sync) | ✅ NPT clock parser | ✅ Yes | ✅ Yes | ❌ No |
| EPUB NCX / NAV TOC Parsing | ✅ Deep recursive nav tree | ✅ Yes | ✅ Yes | ✅ Yes |
| RTL & CJK Vertical Writing | ✅ direction: rtl + vertical-rl |
✅ Yes | ✅ Yes | ❌ No |
| Viewport Meta Parsing | ✅ Zero-alloc slice parse | ✅ Yes | ✅ Yes | ❌ No |
| Reflow Paginator | ✅ ReflowPaginator::paginate_section |
✅ Yes | ✅ Yes | ❌ No |
| Readium LCP DRM License Parser | ✅ LcpLicense + expiry checks |
❌ No | ✅ Yes | ❌ No |
| Legacy Non-UTF-8 Auto-Decoding | ✅ Auto Win-1252/Shift-JIS/GBK | ❌ No | ❌ No | ❌ No |
🔍 Search, Analytics & AI RAG
| Feature | 🚀 ebook-rs (v0.16.1) |
📦 epub.js |
📖 foliate-js |
🦀 rbook |
|---|---|---|---|---|
| Model Context Protocol (MCP 2024-11-05) | ✅ Built-in Stdio & HTTP Server | ❌ No | ❌ No | ❌ No |
| Okapi BM25 Relevance Scoring | ✅ rank_chunks_bm25() TF-IDF |
❌ No | ❌ No | ❌ No |
| AI & RAG Chunking Engine | ✅ to_rag_chunks() + CFI citations |
❌ No | ❌ No | ❌ No |
| Zero-Allocation Full-Text Search | ✅ SIMD char_indices slicing |
❌ No | ✅ Basic | ❌ No |
| Regex Search | ✅ regex_search |
❌ No | ❌ No | ❌ No |
| Search Context Snippets | ✅ <mark> highlights + XSS guard |
❌ No | ✅ Yes | ❌ No |
| Readium Search JSON Export | ✅ Readium-compliant JSON | ❌ No | ✅ Yes | ❌ No |
| NLP Reading Analytics | ✅ Word count / reading time / complexity | ❌ No | ❌ No | ❌ No |
| Auto Language Detection | ✅ detect_language (whatlang) |
❌ No | ❌ No | ❌ No |
🌐 Interoperability, Exporters & Performance
| Feature | 🚀 ebook-rs (v0.16.1) |
📦 epub.js |
📖 foliate-js |
🦀 rbook |
|---|---|---|---|---|
| Universal EPUB 3 & KFX Exporters | ✅ export_epub3 & export_kfx |
❌ No | ❌ No | ❌ No |
| Sub-5ms Lazy Resource Hydration | ✅ On-demand asset inlining | ❌ No | ❌ No | ❌ No |
| Zstd Compressed State Caching | ✅ Instant export_zstd_cache() |
❌ No | ❌ No | ❌ No |
| C / Python / Node FFI Bindings | ✅ ebook_rs::ffi C ABI + PyO3 |
❌ No | ❌ No | ❌ No |
| Web Component Generator | ✅ <ebook-reader> HTMLElement |
❌ No | ❌ No | ❌ No |
| WASM Client SDK | ✅ WasmBook WASM bindings |
✅ Yes | ✅ Yes | ❌ No |
| W3C Web Annotation (JSON-LD) | ✅ Full CRUD + to_w3c_json |
❌ No | ✅ Yes | ❌ No |
| Readium WebPub Manifest Export | ✅ book.to_webpub_manifest() |
❌ No | ✅ Yes | ❌ No |
⚡ Format Conversion Benchmark (ebook-rs vs Calibre ebook-convert)
Empirically measured conversion benchmark converting eBook formats to EPUB 3 on identical test hardware:
| Input Format | 🚀 ebook-rs (v0.16.1) |
🐍 Calibre ebook-convert |
Speedup | Image Assets Extracted | Chapter Sections | Output Parity |
|---|---|---|---|---|---|---|
| MOBI → EPUB | 0.98s ⚡ | 4.64s | 4.8× Faster | 38 / 37 (100% Parity) ✅ | 17 chapters | Matched |
| AZW3 (KF8) → EPUB | 0.34s ⚡ | 3.29s | 9.7× Faster | 38 / 37 (100% Parity) ✅ | 14 chapters | Matched |
| FB2 → EPUB | 0.26s ⚡ | 2.73s | 10.5× Faster | 37 / 37 (100% Parity) ✅ | 15 chapters | Matched |
| LIT → EPUB | 0.48s ⚡ | 3.53s | 7.4× Faster | 37 / 37 (100% Parity) ✅ | 21 chapters | Matched |
| KFX → EPUB | 0.37s ⚡ | 3.84s (Plugin Req.) | 10.4× Faster | 37 / 37 (100% Parity) ✅ | 22 chapters | Matched |
📦 Installation
Add ebook-rs to your Cargo.toml:
[]
= "0.16.1"
Or install via cargo:
For Python projects:
🚀 Quick Start (Rust)
use ;
🐍 Python Bindings
# Load eBook file
=
# Read Section HTML & RAG JSON
=
=
🤖 Model Context Protocol (MCP) Server
ebook-rs includes a built-in Model Context Protocol (MCP 2024-11-05) JSON-RPC server on stdio or HTTP/SSE. Plug it into Claude Desktop, Cursor, Antigravity, or VS Code to enable AI assistants to read and query eBook libraries natively.
Run Server:
Claude Desktop / Cursor Setup (claude_desktop_config.json):
See detailed MCP documentation in
docs/MCP_SERVER.md.
💻 CLI Usage
The ebook-rs executable provides several utility sub-commands:
# Parse metadata and TOC
# Perform full-text search
# Launch Model Context Protocol (MCP) AI server
# Convert formats (MOBI/FB2/PDF -> EPUB / KFX / RAG JSON)
# Launch local HTTP Reader web server (Port 8080)
📚 Complete API Reference
For detailed function signatures, struct documentation, and module guides, refer to:
API.md: Full API reference guide.docs/MCP_SERVER.md: Model Context Protocol (MCP) server specification.- Docs.rs Documentation: Generated Rust API docs.
🏗️ Architecture Overview
ebook-rs is designed around a zero-copy, highly modular system architecture:
┌────────────────────────────────────────┐
│ Book (src/book.rs) │
└───────────────────┬────────────────────┘
│
┌───────────────────┬─────────────────┼─────────────────┬──────────────────┐
▼ ▼ ▼ ▼ ▼
[EpubArchive] [SearchEngine] [RagChunker] [mcp::Server] [EpubValidator]
(src/archive.rs) (src/search.rs) (src/rag.rs) (src/mcp.rs) (src/validator.rs)
src/book.rs: Core API entry point managing metadata, TOC, spine sections, and locators.src/search.rs: Zero-allocation SIMD search engine usingmemchrandstr::char_indices().src/rag.rs: Okapi BM25 relevance scoring and AI document chunking engine.src/mcp.rs: Model Context Protocol (MCP 2024-11-05) JSON-RPC stdio & HTTP server.src/section.rs: Sub-5ms lazy section hydration and Base64 asset inlining.src/validator.rs: Structural EPUB 2/3 validator and multi-threaded EPUB3/KFX exporter.
🤝 Contributing
Contributions are warmly welcomed! Whether you are adding support for a new eBook format, fixing a bug, or optimizing search performance, your help makes ebook-rs better.
Development Workflow
- Clone & Build:
- Run Test Suite:
- Check Code Formatting & Lints:
- Submit a Pull Request:
- Ensure all unit and blackbox integration tests pass cleanly without warnings.
- Include a concise description of your changes in your PR description.
🙏 Acknowledgments & Credits
- Inspired by the feature capabilities of epub.js and foliate-js.
- Compliant with W3C EPUB 3.3 Specifications and Readium Foundation Architecture.
📜 License
Distributed under the MIT License. See LICENSE for more information.