mbox-md
Convert a Gmail Takeout (or other) .mbox archive into one Markdown file per message, organized by year and month, with attachments stored once and shared across messages.
Install
uv tool install mbox-md # or: pipx install mbox-md
To use it as a library, pip install mbox-md (or uv add mbox-md). Requires Python 3.11+.
Usage
CLI:
mbox-md "All mail Including Spam and Trash.mbox" archive/
mbox-md takeout.mbox.zst archive/ --since 2020-01-01 --strip-quotes
mbox-md takeout.mbox --dry-run # counts and output size, writes nothing
mbox-md takeout.mbox archive/ --compress-source zstd --delete-source
| Option | What it does |
|---|---|
--since, --until YYYY-MM-DD |
only messages in this date range (undated mail is skipped when a range is set) |
--skip-labels LABELS |
comma-separated Gmail labels to skip; default Spam,Trash, "" keeps everything |
--limit N |
stop after reading N messages |
--tz ZONE |
timezone for folder and file names and --since/--until: sender (default), utc, local, or an IANA name |
--min-inline-image SIZE |
drop inline images smaller than this (logos, tracking pixels); default 5KB, 0 keeps all |
--strip-quotes |
drop quoted replies from bodies |
--keep-from-escapes |
don't undo mboxrd >From escaping (for mboxo files) |
--workers N |
worker processes; default CPUs − 1 |
--dry-run |
parse and count everything, write nothing |
--incremental |
convert only messages not already in the output (a newer export, or resuming a stopped run) |
--prune |
delete files that earlier runs wrote into the output and this run didn't |
--compress-source zstd|gzip |
after converting, compress the input mbox next to it and verify it by decompressing it in full |
--compress-level 1-10 |
compression level, 1 fastest to 10 smallest (default 5) |
--delete-source |
delete the original mbox, only after the compressed copy verifies |
-q, -v, --json |
quiet, report each failure, or print stats as JSON |
Input can be plain, zstd, or gzip; compression is detected from the file's contents and handled in-process by compress-utils, with no zstd or gzip command needed.
API:
import mbox_md
stats = mbox_md.convert("All mail.mbox", "out/")
for raw in mbox_md.iter_messages("All mail.mbox"):
msg = mbox_md.parse_message(raw) # None if it's in Spam or Trash
Development
uv sync
uv run pytest # unit tests, fabricated data only
uv run pytest -m local # smoke test against local-data/takeout-sample.mbox, if you have it
uv run mypy # strict type checking
uv run coverage run -m pytest && uv run coverage combine && uv run coverage report # branch coverage, 95% minimum
uv run ruff check src tests && uv run ruff format --check src tests
License
Metadata
Release files for mbox-md 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mbox_md-0.1.1.tar.gz | 60.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mbox_md-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 95.7 kB
Release files / mbox_md-0.1.1.tar.gz
| Download URL | mbox_md-0.1.1.tar.gz |
|---|---|
| Size | 60.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11bf0a2d7937dfaddfc3daca45439a3ec6adeb5213c832f9047cb3641730ef9f
|
|
BLAKE2b-256 checksum How to use checksums |
be56a5c43911afba4bb65e183bf00204d813d29220b2eabdb239ee10022ff559
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logRelease files / mbox_md-0.1.1-py3-none-any.whl
| Download URL | mbox_md-0.1.1-py3-none-any.whl |
|---|---|
| Size | 35.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6a364ccbbdbcfb18e11556b23ac07214266447df771991e9c6cf7d0ca3e131f
|
|
BLAKE2b-256 checksum How to use checksums |
66b04bcf461f46ffb73b3c2521d7ab3e75c3eee0b31b4a15db97fa7880bcf358
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency log