Skip to main content

pro-ledin-docling-ebook

Open Docling backend extension for structured ebook conversion.

It converts EPUB, FB2, compressed FB2, and DRM-free MOBI-family books into a native DoclingDocument, then exports through Docling to Markdown, JSON, or HTML.

  • Inputs: .epub, .fb2, .fb2.zip, .fbz, .mobi, .azw, .azw3
  • Python package: pro.ledin.docling_ebook
  • CLI: docling-ebook
  • License: MIT
  • Proprietary dependencies: none

Install

pip install pro-ledin-docling-ebook

The package uses the official docling-slim distribution because ebook conversion needs the Docling document model and backend contracts, not PDF layout, OCR, or VLM models.

EPUB and FB2 work immediately. DRM-free MOBI/AZW/AZW3 require one external converter. mobitool is preferred; Calibre is the fallback:

brew install libmobi
sudo apt install libmobi-tools

Calibre downloads: https://calibre-ebook.com/download

docling-ebook doctor --json

CLI

docling-ebook book.fb2 --to md --output-dir ./out
docling-ebook book.mobi --to json --output-dir ./out
docling-ebook one.epub two.azw3 --to html --output-dir ./out

Preview parsing without writing outputs:

docling-ebook book.fb2 --dry-run

Source image policy:

docling-ebook book.fb2 --images import
docling-ebook book.fb2 --images skip

Docling export image mode:

docling-ebook book.fb2 --to md --image-mode placeholder
docling-ebook book.fb2 --to md --image-mode embedded
docling-ebook book.fb2 --to md --image-mode referenced

MOBI backend selection:

docling-ebook book.azw3 --mobi-backend auto
docling-ebook book.azw3 --mobi-backend mobitool
docling-ebook book.azw3 --mobi-backend calibre

Footnotes default to Markdown-compatible native markers. Use an inline fallback when a downstream Docling consumer does not preserve footnote references:

docling-ebook book.fb2 --footnote-mode inline --to md

Python API

from pro.ledin.docling_ebook import EbookConverter

result = EbookConverter(
    image_mode="import",
    mobi_backend="auto",
).convert("book.fb2")

document = result.document
result.save_as_markdown("book.md", image_mode="embedded")
document.save_as_json("book.json")

Streams require a filename so the ebook format can be detected:

from io import BytesIO
from pro.ledin.docling_ebook import convert_ebook

result = convert_ebook(BytesIO(payload), filename="book.fb2")

Native document mapping

The backend maps the typed pro-ledin-ebook-import model directly into DoclingDocument:

  • book title and metadata
  • chapter and nested-section groups
  • headings and paragraphs
  • mixed emphasis, bold, strike, links, code, subscript, and superscript
  • epigraphs, citations, poems, stanzas, and verse lines
  • tables with row/column spans
  • content and cover pictures
  • footnote references and definitions
  • ordered and unordered lists

Warnings and MOBI converter provenance remain available on EbookConversionResult instead of being inserted into book text.

Docling extension boundary

Docling's third-party plugin entry point currently registers OCR, layout, table-structure, and picture-description models. It does not register new input formats or document backends. This package therefore provides the public EbookDocumentBackend, EbookConverter, and docling-ebook CLI rather than an irrelevant model-plugin entry point.

The stock command below is not provided by an external backend package:

docling --from fb2 book.fb2

Native support for that syntax requires new InputFormat and CLI mappings in Docling upstream. This extension uses only public InputDocument and DeclarativeDocumentBackend APIs and does not call private Docling methods or model pipelines. The converter invokes the public DeclarativeDocumentBackend.convert() contract directly, so docling-slim does not pull PDF/OCR/VLM dependencies.

An alternative commercial project, aspose-words-docling, supports some ebook formats through Aspose.Words. This package instead uses the open pro-ledin-ebook-import parser and libmobi/Calibre subprocess boundary.

Safety

  • FB2 XML rejects DTD and entity expansion.
  • FB2.ZIP/FBZ archives enforce path, size, member-count, and compression limits.
  • External converters run without a shell in temporary directories.
  • Remote Docling services and external model plugins remain disabled.
  • The package never removes DRM and rejects encrypted books.
  • KFX, AZW4 Print Replica, and PRC are unsupported.

Development

uv sync --extra dev
uv run --extra dev pytest -q -m "not external"
uv run --extra dev pytest \
  --cov=pro.ledin.docling_ebook --cov-branch --cov-report=json
uv run python scripts/check_coverage.py coverage.json
uv build

Run real MOBI converter integration when both tools are installed:

DOCLING_EBOOK_EXTERNAL_TESTS=1 \
  uv run --extra dev pytest tests/test_real_mobi_tools.py

License

MIT

Metadata

Release files for pro-ledin-docling-ebook 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pro-ledin-docling-ebook 0.1.0
File Size Uploaded
pro_ledin_docling_ebook-0.1.0.tar.gz 18.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pro-ledin-docling-ebook 0.1.0
File Interpreter ABI Platform
pro_ledin_docling_ebook-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.4 kB

Release files / pro_ledin_docling_ebook-0.1.0.tar.gz

Download URL pro_ledin_docling_ebook-0.1.0.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7c193612c3ca0ff68c1625b8f46ca709c59afda0c43a20d78b0d3d1d8803e876
BLAKE2b-256 checksum
How to use checksums
7c493f2fe09636dfe99fc051627ae8f07352b483b7f3ce9489b1664479bdb3a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pro_ledin_docling_ebook-0.1.0-py3-none-any.whl

Download URL pro_ledin_docling_ebook-0.1.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57b8a9fdf6399606191c1862676ba3b61131752d654c7ba16a9f3c82a29a0784
BLAKE2b-256 checksum
How to use checksums
a3845edabd561010939d1e4d2a310cd99d9112878ac4b859f93dad8e576b106a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page