Skip to main content

Condense large technical ebooks (EPUB/PDF) preserving code and diagrams, optionally translating in the same pass.

Project description

BreviaBook

Condense large technical ebooks (EPUB/PDF) into a fast, filler-free version — preserving code, formulas, and the important diagrams — and optionally translate them in the same pass. Outputs EPUB, PDF, and Markdown.

Multi-provider LLM from day one: Ollama (local), OpenAI, Gemini, OpenRouter, and any OpenAI-compatible endpoint (vLLM, LM Studio, LocalAI). Runs fully local on a laptop with Ollama, or via a paid API when it makes sense.

License: Apache-2.0

Why

Technical books are long and padded. BreviaBook reads dense books fast without losing the parts that matter — code examples, tables, and meaningful figures survive; filler doesn't — and can deliver the result in your language (e.g. English → Spanish) in one go.

Features

  • Structure-aware condensation — chapter-aware chunking; code blocks are never summarized or split.
  • Hierarchical summarization — per-chunk condense + per-chapter synthesis with active length control toward a --target-ratio.
  • Image preservation (the differentiator) — keeps images whose section survives (Strategy A); optional vision ranking (--rank-images) drops decorative images and improves captions.
  • Integrated translation — translates the already-condensed book (much cheaper) with an optional glossary for consistent terminology; code stays untranslated. Runs in resilient batches: a malformed model response retries and falls back to the source text instead of crashing the run.
  • Three outputs — EPUB (our own builder), PDF (weasyprint), Markdown.
  • Live TUI — a banner plus per-phase progress bars (parse → condense → synthesize → translate → render) and a usage panel that ticks token/cost totals in real time. Degrades to plain text when output is piped.
  • Cost control for reasoning models--reasoning-effort disable turns off "thinking" on models like gemini-3-flash-preview, which otherwise spend most output tokens on discarded reasoning (~3.6× cheaper on a real run, same quality). See Cost & reasoning models.
  • Compression report — every run prints how much smaller the result is and an approximate page count (e.g. ~479 → ~149 pages, 69% smaller).
  • Resumable--resume continues an interrupted job from a checkpoint (already-condensed chunks are reused, not re-billed).
  • Dry-run + cost--dry-run estimates tokens, pages, compression, and approximate cost without calling the LLM.
  • Usage report — every run prints prompt/completion/cached tokens and estimated cost.

Install

Requires Python 3.11+ and uv. EPUB and Markdown output need no system libraries; PDF output adds the optional [pdf] extra (see PDF output requirements). Set credentials before running cloud providers — see Configuration.

Run with uvx (no install)

Run the latest straight from GitHub — no clone, no virtualenv:

# EPUB + Markdown (nothing else needed)
uvx --from "git+https://github.com/willywg/breviabook" breviabook condense book.epub --formats epub,md

# with PDF output
uvx --from "breviabook[pdf] @ git+https://github.com/willywg/breviabook" breviabook condense book.epub

Once published to PyPI this shortens to uvx breviabook condense book.epub (and uvx "breviabook[pdf]" … for PDF output).

Install the command

uv tool install "git+https://github.com/willywg/breviabook"   # append [pdf] for PDF output
breviabook condense book.epub --out ./out/                     # now on your PATH

(After PyPI: uv tool install breviabook.)

From source (development)

git clone https://github.com/willywg/breviabook.git
cd breviabook
uv sync                # EPUB + Markdown
uv sync --extra pdf    # add PDF output
uv run breviabook --help

PDF output requirements

PDF rendering uses weasyprint, which needs system libraries (EPUB and Markdown need nothing extra):

  • macOS: brew install pango gdk-pixbuf libffi — on Apple Silicon also export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib.
  • Debian/Ubuntu: libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf-2.0-0 libffi-dev.

Quickstart

# Local, all three formats, with Ollama
uv run breviabook condense book.epub --formats epub,pdf,md --out ./out/

# Estimate tokens + cost first, without calling the LLM
uv run breviabook condense book.epub --dry-run

# Condense + translate to Spanish with a cloud model (Gemini thinking is off by default)
uv run breviabook condense book.epub \
  --provider gemini --model gemini-3-flash-preview \
  --translate-to Spanish --source-lang English --glossary glossary.json \
  --formats epub,md --out ./out/

# Drop decorative images with a vision model, and resume if interrupted
uv run breviabook condense book.pdf --provider gemini --model gemini-3-flash-preview \
  --rank-images --resume --out ./out/

CLI

breviabook condense INPUT.{epub,pdf} [options]

  --provider        ollama | openai | gemini | openrouter        (default: ollama)
  --model           model tag (default from .env)
  --api-endpoint    base URL for OpenAI-compatible servers (vLLM/LM Studio/LocalAI)
  --target-ratio    target size, e.g. 0.30 = ~30% of the original
  --formats         comma list of epub,pdf,md                     (default: epub,pdf,md)
  --translate-to    target language (omit = no translation)
  --source-lang     source language (optional hint)
  --glossary        glossary JSON {source_term: target_term}
  --rank-images     use a vision model to score/drop images
  --reasoning-effort  auto | disable | low | medium | high  (thinking budget; Gemini defaults
                      to "disable" to save cost — pass "auto" to keep native thinking)
  --manual-toc      manual TOC JSON for PDFs without an outline
  --out             output directory                              (default: ./output)
  --resume          resume from checkpoint
  --dry-run         estimate tokens/cost/pages only, no LLM call

Cost & reasoning models

Some cloud models "think" before answering. For condensation/translation — rewriting tasks, not reasoning tasks — that thinking is pure waste: on a real run ~94% of output tokens were discarded reasoning, billed as output. BreviaBook therefore disables thinking by default for providers that have it on (Gemini). To restore a model's native thinking, pass --reasoning-effort auto (or set low/medium/high explicitly).

Run (Introducing Go, EPUB → Spanish) Cost Output tokens Quality
thinking on (--reasoning-effort auto) $0.78 243k excellent
default (thinking disabled) $0.22 55k excellent (identical)

Estimate first with --dry-run (no LLM call). Note the dry-run assumes no reasoning tokens — which matches the default; if you re-enable thinking with --reasoning-effort auto, the real cost can be several times the estimate. Pricing for gemini-3-flash-preview: ~$0.50 / 1M input, ~$3.00 / 1M output.

Configuration

BreviaBook reads settings from environment variables or a .env file in the directory you run from. Environment variables take precedence. Local Ollama needs no key, so the defaults work out of the box; cloud providers need an API key. CLI flags (--provider, --model, …) override both.

# Option A — environment variable (best for `uvx`; works from any directory)
export GEMINI_API_KEY="your-key"
uvx breviabook condense book.epub --provider gemini --model gemini-3-flash-preview --translate-to Spanish

# one-off, inline (no export)
GEMINI_API_KEY="your-key" uvx breviabook condense book.epub --provider gemini

# Option B — a .env file in the current directory (from source: `cp .env.example .env`)
printf 'GEMINI_API_KEY=your-key\n' > .env

All recognized variables (every one optional; names are case-insensitive):

LLM_PROVIDER=ollama                       # ollama | openai | gemini | openrouter
OLLAMA_ENDPOINT=http://localhost:11434
DEFAULT_MODEL=gemma4:e4b

OPENAI_API_KEY=         # comma-separated for key rotation
GEMINI_API_KEY=
OPENROUTER_API_KEY=

DEFAULT_TARGET_RATIO=0.30
DEFAULT_CHUNK_TOKENS=2000
IMAGE_STRATEGY=keep_referenced   # keep_referenced | vision_ranked

Keys are sent only to the selected provider's endpoint, never elsewhere. .env is gitignored — don't commit credentials.

How it works

Everything flows through a format-agnostic Intermediate Representation (IR):

parse → chunk → condense → synthesize → (translate) → image-select → render
        EPUB/PDF → IR        per-chunk    per-chapter    glossary      Strategy A/B   EPUB/PDF/MD

Parsers turn EPUB/PDF into the IR; the condenser and translator transform its text blocks (leaving code and images intact); renderers emit the final files. Adding an input or output format means writing one parser or one renderer — the condensation logic doesn't change.

See the full design and build plan in docs/ROADMAP.md.

Development

uv run ruff check . && uv run ruff format --check .   # lint + format
uv run mypy --strict breviabook                           # types
uv run pytest -q                                       # tests
uv run pip-licenses --fail-on "GPL"                    # license audit (blocks GPL/AGPL)

License

Apache-2.0. BreviaBook is inspired by open-source work but contains no copied code and depends on no copyleft (GPL/AGPL) libraries — see docs/ROADMAP.md §14 and NOTICE.

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

breviabook-0.1.0.tar.gz (321.7 kB view details)

Uploaded Source

Built Distribution

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

breviabook-0.1.0-py3-none-any.whl (74.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: breviabook-0.1.0.tar.gz
  • Upload date:
  • Size: 321.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for breviabook-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b434a5094a151c3f24e41e697ad84bf6b0cc5e16fa7c02ccec0fa483044a42c9
MD5 5f887eccd8112982d65f6cd609ac25d7
BLAKE2b-256 95fd7735f9d9861228ad1482ee7bc25b0b04d96b2b03cce5ab79cae7ba39902d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: breviabook-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 74.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for breviabook-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 099aa5ee6a69b90825034f96197b2117eb781fac233d29daf70aa4e564589580
MD5 8093d453faad0fdd89dfe7ddf774fff7
BLAKE2b-256 ccfaa6d4eab03a4625c4762732fcd39a635ac09f91e40baaa63225a89526f8fc

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