skillfed

html-for-docx

Convert HTML to Docx easily and fastly

html-for-docx v1.1.7 345.0K downloads/30d#7,370 on PyPI64
Permissive license MIT Active released

What it is and what it does

html-for-docx is a Python library that transforms HTML markup into Word documents (.docx format). It wraps python-docx and beautifulsoup4 to parse HTML and render it as native Word content, preserving text, tables, images, and styling where possible. The library supports inline CSS, custom style mappings from HTML classes to Word styles, tag-level style overrides, and document metadata manipulation.

You use it by instantiating a parser, then either adding HTML snippets to an existing Word document incrementally, converting entire HTML files, or parsing HTML strings directly to new documents. It handles both file-based and in-memory workflows, offers granular control over which HTML features to process (images, tables, styles, comments), and lets you apply Word template styles to preserve formatting across conversions.

Use it for:

  • Generate Word reports from HTML templates or web content without manual formatting.
  • Batch-convert HTML files to .docx for archival, distribution, or further editing.
  • Embed HTML-to-docx conversion in a web application to let users download formatted documents.
  • Combine markdown-to-HTML pipelines with this library to produce Word documents from markdown source.
  • Populate Word documents with styled HTML content from a CMS or database dynamically.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts HTML content to Word documents (.docx), with support for styling, tables, images, and metadata.

Yes. The package is actively maintained, has low install friction, carries a permissive MIT license, supports Python 3.7 through 3.14, and solves a concrete problem with a straightforward API. No known vulnerabilities. Install it if you need to convert HTML to Word documents; the main limitation is fidelity of complex CSS styling, which is inherent to the Word format itself.

Install

html-for-docx on PyPI

pip

pip install html-for-docx

uv

uv add html-for-docx

poetry

poetry add html-for-docx

Installing html-for-docx

Before you install

Low friction install with two stable runtime dependencies. Actively maintained with recent release activity.

License in practice

MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute freely provided you include the license notice.

Quickstart

pip install html-for-docx

from html_for_docx import HtmlToDocx
from docx import Document

parser = HtmlToDocx()
document = Document()
parser.add_html_to_document('Hello world', document)
document.save('output.docx')

Verify before relying

  • Extent of HTML/CSS feature coverage beyond what the description excerpt shows (e.g., form elements, media queries, complex layouts).
  • Performance characteristics with large HTML documents or complex nested structures.
  • Fidelity of style conversion from CSS to Word's native style system in edge cases.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies 2 — python-docx, beautifulsoup4
Maintenance actively maintained — 14 days since the last release
Last repo commit
First released
Downloads 344,972/month — #7,370 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: html_for_docx-1.1.7-py3-none-any.whl

Keywords: html, docx, docs, office, word, convert, transform

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Build ToolsTopic :: Software Development :: LibrariesTopic :: Text ProcessingTopic :: Text Processing :: Markup :: HTMLTopic :: Utilities

Tags

html to docx converterconvert html to word documenthtml to microsoft wordgenerate docx from htmlhtml parsing to docxword document generation from htmlhtml markup to office format
document-generationhtml-conversionoffice-automation

More Libraries packages