pro-ledin-ebook-import
Deterministic ebook-to-Markdown importing for Obsidian vaults and AI-agent workflows. The importer preserves source order and text, copies each original ebook into the generated book directory, extracts referenced media when chosen, and records SHA-256 metadata for repeatable rebuilds.
- Input formats: EPUB, FB2, FB2.ZIP/FBZ, DRM-free MOBI, AZW, and AZW3
- Import name:
pro.ledin.ebook_import - Console script:
ebook-import - PyPI:
pro-ledin-ebook-import - Skill:
skills/ebook-import/SKILL.md
Install
pip install pro-ledin-ebook-import
EPUB and FB2 imports work after the Python package is installed. FB2 parsing
uses the small defusedxml dependency to reject XML entity and DTD attacks.
MOBI, AZW, and AZW3 require one separately installed converter. The importer
prefers mobitool and falls back to Calibre:
brew install libmobi # macOS, preferred
sudo apt install libmobi-tools # Debian/Ubuntu, preferred when available
Calibre is available for macOS, Linux, and Windows from https://calibre-ebook.com/download. The package invokes these tools as separate processes and does not bundle or import their LGPL/GPL code.
Check the current machine:
ebook-import doctor --json
Parser API
The package also exposes a filesystem-independent typed parsing API for other renderers and document systems:
from pro.ledin.ebook_import import Heading, Paragraph, parse_book
book = parse_book("/path/to/book.fb2")
for chapter in book.chapters:
print(chapter.title, len(chapter.blocks))
print(chapter.markdown)
ParsedChapter.blocks contains immutable headings, paragraphs, groups, quotes,
poems, tables, images, links, and footnotes. chapter.markdown is generated from
the same typed model for compatibility with the Obsidian corpus renderer.
Import
Preview without writing to the vault:
ebook-import import \
--vault-root "/path/to/vault" \
--output-dir "05-sources/books" \
--image-mode import \
--dry-run \
--input "/path/to/book.epub" "/path/to/book.fb2" "/path/to/book.mobi"
Run the import after reviewing the JSON result:
ebook-import import \
--vault-root "/path/to/vault" \
--output-dir "05-sources/books" \
--image-mode import \
--input "/path/to/book.epub" "/path/to/book.fb2" "/path/to/book.mobi"
Choose a MOBI backend explicitly when needed:
ebook-import import \
--vault-root "/path/to/vault" \
--mobi-backend mobitool \
--input "/path/to/book.azw3"
--mobi-backend accepts auto, mobitool, or calibre. auto prefers
mobitool, then retries with Calibre for ordinary conversion failures. It does
not retry or bypass DRM/encryption failures.
Image policy
Use --image-mode import to extract referenced images or --image-mode skip
to omit image files and Markdown image markers.
Format behavior
EPUB
EPUB spine order defines chapter order. OPF metadata, NCX chapter titles, common XHTML formatting, links, and referenced images are converted using the package's deterministic standard-library serializer.
FB2
Each top-level content section becomes one chapter file. Nested sections remain
headings. The parser preserves common inline formatting, epigraphs, citations,
poem stanza/verse lines, localized notes bodies, links, tables, embedded binary
images, and cover metadata. Compressed .fb2.zip and .fbz inputs must contain
exactly one .fb2 payload and pass archive safety limits.
MOBI, AZW, and AZW3
The selected external converter creates a temporary EPUB, which is passed through the native EPUB parser. The corpus keeps the original MOBI-family file, hashes the original bytes, records converter/version provenance, and removes the temporary EPUB.
DRM-protected books, KFX, AZW4 Print Replica, and PRC are unsupported. The tool does not remove DRM and does not provide instructions for doing so.
Output
05-sources/books/
├── index.md
└── <book-slug>/
├── book.md
├── manifest.json
├── original/book.<source-extension>
├── chapters/*.md
└── media/*
The manifest records input format, original path, source hash, image mode, chapters, media, warnings, and MOBI converter provenance when applicable. Repeated imports with the same source hash, importer version, and image mode are no-ops. Changing image mode or importer output version rebuilds generated files.
Books with the same metadata title do not overwrite one another: later collisions receive a deterministic format suffix.
Docling integration
Use the separate docling-ebook
package and skill when an ebook request explicitly requires Docling output or
OCR/image-text extraction. ebook-import does not duplicate those behaviors.
pip install pro-ledin-docling-ebook
docling-ebook book.fb2 --images referenced --to md --output-dir ./out
The integration is kept separate so this parser and Obsidian importer remain lightweight and deterministic.
Development
uv sync --extra dev
uv run --extra dev pytest -q -m "not external"
uv run --extra dev pytest \
--cov=pro.ledin.ebook_import --cov-branch --cov-report=json
uv run python scripts/check_coverage.py coverage.json
uv build
Real MOBI integration requires both converters:
EBOOK_IMPORT_EXTERNAL_TESTS=1 \
uv run --extra dev pytest -q tests/test_real_mobi_tools.py
CI tests Python 3.10-3.14, enforces at least 90% statement and 85% branch coverage, runs hostile-input and property tests, builds both distributions, and runs a dedicated real-converter integration job.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pro_ledin_ebook_import-0.4.0.tar.gz.
File metadata
- Download URL: pro_ledin_ebook_import-0.4.0.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ea385a7b8354c99f642d172fc1c573513ec8af179bc4acaaf8f3352048664e3
|
|
| MD5 |
eb9bfba79285b0c2fc01f505334f6e98
|
|
| BLAKE2b-256 |
b582750a7f7760c254629fc74ca26ffeba0b83c7432be58d77b00080ed8887a3
|
File details
Details for the file pro_ledin_ebook_import-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pro_ledin_ebook_import-0.4.0-py3-none-any.whl
- Upload date:
- Size: 28.5 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a2ed1b9a2b4fa025679bfa81079b14352d907612ea3299cb382f9c8788dd44b
|
|
| MD5 |
6aba732d20ef22f5ed02aa8256345d95
|
|
| BLAKE2b-256 |
60c720f404b9026096af0cc5865f18c23a62322f2938b5d1d24161e86371caef
|