Skip to main content

Create and safely rebuild EPUB files from structured text and Markdown.

Project description

PyPI - Version PyPI - Python Version PyPI - Downloads codecov

text2epub

text2epub is a typed Python library for two EPUB output workflows:

  1. Safe rebuilds of existing EPUBs from structured extraction manifests and validated text replacements.
  2. New EPUB creation from Markdown with generated XHTML, OPF, NAV, NCX, CSS, and deterministic package output.

The primary client is booktx, so package-preserving rebuild behavior takes priority over convenience features.

Features

  • byte-identical no-op and identity rebuild paths
  • ZIP-level EPUB validation
  • strict unresolved-token scanning for rewritten or generated text entries
  • safe plain-text and inline-XHTML replacement support
  • Markdown-to-EPUB generation for single-file and multi-file books
  • deterministic output by default
  • small public API and CLI smoke commands

Installation

uv pip install -e .

Python API

from pathlib import Path

from text2epub import (
    BuildOptions,
    EpubMetadata,
    MarkdownBook,
    MarkdownChapter,
    Replacement,
    ReplacementPlan,
    create_epub_from_markdown,
    rebuild_epub,
)

book = MarkdownBook(
    metadata=EpubMetadata(title="Example Book", language="en"),
    chapters=[MarkdownChapter(path=Path("chapter-01.md"))],
    options=BuildOptions(deterministic=True),
)
create_epub_from_markdown(book, Path("book.epub"))

report = rebuild_epub(
    ReplacementPlan(
        source_epub=Path("source.epub"),
        extraction_manifest=Path("manifest.json"),
        replacements=[
            Replacement(
                block_id="spine-0001:block-000001",
                text="Translated paragraph.",
            )
        ],
    ),
    Path("rebuilt.epub"),
)
print(report.changed_entries)

CLI

text2epub markdown INPUT.md -o OUTPUT.epub
text2epub markdown CHAPTER_DIR -o OUTPUT.epub --title "Book" --language en
text2epub rebuild SOURCE.epub MANIFEST.json REPLACEMENTS.json -o OUTPUT.epub
text2epub validate OUTPUT.epub
text2epub version

Documentation

The Sphinx documentation lives under docs/. Build it locally with:

python -m pip install -e ".[docs]"
python -m sphinx -b html docs docs/_build/html

Start with docs/index.md for the user guide and docs/release-checklist.md for release validation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

text2epub-0.1.0.tar.gz (41.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

text2epub-0.1.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file text2epub-0.1.0.tar.gz.

File metadata

  • Download URL: text2epub-0.1.0.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for text2epub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0e206e7d59cdfcf7cfdbeb6b8a133c5b955e13763b7ec92262caedcb11705d57
MD5 861e811be8e1aba6aa8c3ecd470ee9fd
BLAKE2b-256 1991e192b030db04827585362e0f2d6c8a8365bc5ec4572ad955b57a149f85c9

See more details on using hashes here.

File details

Details for the file text2epub-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: text2epub-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for text2epub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0abe004d4918528e58da9451a06e268388cfa06d6f169af4dfe9d8d3a1490d3
MD5 42436c035f2a578e54861ffbc325bd07
BLAKE2b-256 09f7af90fc399ba07f85a8ac17ca4512eb460348c701cdbe15471fc70f414c57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page