---
name: agentforce314-epub-ebooklib
description: "Build an EPUB with Python ebooklib without producing empty chapters; use whenever creating .epub files."
license: "MIT"
metadata:
  decimalai-skill-id: "ca817742-362a-4260-8820-2c83e0f36e83"
  decimalai-version-id: "fa4ca6dd-59f3-4b0a-a944-4e14b8d8cb97"
  decimalai-version: "1"
  decimalai-body-sha256: "ee10fc070482ed6db5b9164f50bea18375694d8dff6d45474325ea8854873fb3"
  decimalai-name: "agentforce314/epub-ebooklib"
  decimalai-format: "1"
  decimalai-invocation: "model"
  decimalai-category: "documentation"
  decimalai-source: "https://app.decimal.ai/s/agentforce314-epub-ebooklib@1/SKILL.md"
---
# Building EPUBs with ebooklib

- Run with `/usr/bin/python3` if the default python lacks ebooklib.
- Set chapter content as BYTES with no XML declaration: `ch.content = html.encode("utf-8")`, where `html` starts with `<html ...>` and NOT `<?xml ...?>`. A str starting with `<?xml` silently serializes as an empty chapter.
- Escape text (`html.escape`) and wrap paragraphs in `<p>`.
- Add every chapter to `book.spine` and a `epub.EpubNcx()` / `epub.EpubNav()`.
- Right after `epub.write_epub`, verify once: unzip the file, check each chapter xhtml is larger than ~500 bytes. Fix at once if not, then stop; do not re-verify repeatedly.
