mammoth
Convert Word documents from docx to simple and clean HTML and Markdown
What it is and what it does
Mammoth is a .docx-to-HTML converter designed to produce clean, semantic markup from Word documents created by Microsoft Word, Google Docs, or LibreOffice. Rather than attempting to replicate visual styling, it interprets document structure—converting a paragraph styled as "Heading 1" to an h1 element, for example—and ignores formatting details like fonts and colors. This approach works well for documents that use styles semantically but may lose fidelity on complex layouts.
The package supports headings, lists, tables, footnotes, images, text formatting (bold, italic, strikethrough, superscript, subscript), links, comments, and custom style mappings. It can be used as a CLI tool or imported as a library. A critical caveat: Mammoth performs no sanitization of source documents, so it must be used carefully with untrusted input. The library also includes text extraction and experimental Markdown output (deprecated in favor of generating HTML first).
Use it for:
- Batch convert Word documents to HTML for web publishing or content management systems.
- Extract semantic structure from styled Word documents for downstream processing or archival.
- Build document pipelines that map custom Word styles to specific HTML classes or elements.
- Preserve document content and structure when migrating from Word to web-based authoring platforms.
- Extract raw text from .docx files while ignoring all formatting and styling.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts Microsoft Word .docx documents to clean HTML or Markdown, using document styles to generate semantic markup rather than attempting to replicate visual formatting.
Yes. Mammoth is actively maintained, has low install friction, carries a permissive license, and solves a well-defined problem—converting .docx to clean HTML using semantic information. It is suitable for most document conversion workflows, but avoid it for untrusted input without additional sanitization and be aware that complex document layouts may not convert perfectly.
Install
mammoth on PyPI
pip
pip install mammothuv
uv add mammothpoetry
poetry add mammothInstalling mammoth
Before you install
Low friction: pure Python wheel with a single runtime dependency (cobble). Active maintenance with a release 5 days ago and 1114 repository stars. Supports Python 3.7 through 3.12.
License in practice
BSD-2-Clause permissive license allows commercial and private use with minimal restrictions, though the package performs no sanitization of untrusted input.
Quickstart
pip install mammoth
import mammoth
with open("document.docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
html = result.value
Input .docx files must be opened in binary mode; conversion works best when documents use semantic styles rather than direct formatting.
Verify before relying
- Whether cobble dependency is lightweight and well-maintained (not disclosed in fact sheet).
- Performance characteristics for large documents or batch conversions.
- Fidelity of table formatting preservation beyond text styling.
Package facts
| License | BSD-2-Clause (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — cobble |
| Maintenance | actively maintained — 5 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 16,076,406/month — #1,163 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mammoth-1.12.1-py2.py3-none-any.whl
Keywords: docx, word, office, clean, html, markdown, md
Tags
More HTML packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
lxmllxml provides Python bindings to libxml2 and…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
MarkdownConverts Markdown text to HTML using a Python…
permissive · top 1,000 on PyPI
draftjs_exporterConverts Draft.js ContentState (a rich text…
permissive · top 5,000 on PyPI
html-for-docxConverts HTML content to Word documents…
permissive · top 15,000 on PyPI
textileConverts Textile markup (a human-friendly text…
permissive · top 15,000 on PyPI
htmldocxConverts HTML content into Microsoft Word…
permissive · top 5,000 on PyPI
html2docxConverts valid HTML to Microsoft Word (.docx)…
permissive · top 15,000 on PyPI
spire-docSpire.Doc creates, reads, modifies, and…
unclear · top 15,000 on PyPI
markdown2Converts Markdown text to HTML using a fast,…
permissive · top 5,000 on PyPI
doc2docxConverts legacy .doc files to modern .docx…
permissive · top 15,000 on PyPI
quill-deltaImplements operational transformation for Quill…
permissive · top 15,000 on PyPI
docxtplGenerates Word documents (.docx) from templates…
copyleft · top 5,000 on PyPI