Python Word DOCX libraries

Updated Nov 2026

Python DOCX libraries create, read, and convert Microsoft Word documents from Python code. A DOCX file is a zip archive of XML parts that a library can edit without opening Word. These libraries let apps and AI agents generate reports, contracts, and letters as Word files.

Popularity

python-docx has the most monthly downloads in this comparison, at 139.9M.

LibraryMonthly downloadsStarsLast releaseLicense
python-docx
139.9M
5.8KJun 2025MIT
Mammoth
18.2M
1.1KSep 2026BSD-2-Clause
docx2txt
5.0M
584Mar 2025MIT
docxtpl
4.7M
2.7KNov 2025LGPL-2.1-only
docxcompose
2.0M
139Jun 2026MIT
docx2pdf
581.5K
600Dec 2021MIT
docx2python
514.0K
213Oct 2026MIT
aspose-words
465.1K
135Nov 2026Commercial
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Creates and updates Microsoft Word DOCX files.

Downloads / mo
139.9M
Stars
5.8K
Last release
1.2.0
License
MIT

Strengths

  • Creates Word documents programmatically. Add bold or italic text runs to a paragraph.
  • Opens existing DOCX files. Read and change supported elements in an existing Word document.

Limitations

  • Legacy DOC files need conversion. Convert older binary Word documents to DOCX before opening them.
  • Paragraph lists skip tracked changes. Inspect revision XML separately when inserted or deleted paragraphs must be included.

Quickstart

From index.rst
$ pip install python-docx
from docx import Document
document = Document()
document.add_paragraph('Hello, world.')
document.save('output.docx')

python-docx examples

From open-source projects on GitHub

Converts DOCX documents into semantic HTML.

Downloads / mo
18.2M
Stars
1.1K
Last release
1.13.0
License
BSD-2-Clause

Strengths

  • Keeps Word heading structure. Convert heading styles into semantic HTML headings.
  • Accepts custom style maps. Map named Word styles to the HTML elements the application expects.

Limitations

  • Generated HTML needs sanitizing. Sanitize converted HTML before inserting it into an application page.
  • External file access stays disabled. Enable external_file_access only when trusted external document references must be read.

Quickstart

From README.md
$ pip install mammoth
import mammoth
with open('input.docx', 'rb') as source:
    result = mammoth.convert_to_html(source)
html = result.value

Mammoth examples

From open-source projects on GitHub

Extracts text and images from DOCX files in pure Python.

Downloads / mo
5.0M
Stars
584
Last release
0.9
License
MIT

Quickstart

From README.md
$ pip install docx2txt
import docx2txt
text = docx2txt.process('input.docx')

docx2txt examples

From open-source projects on GitHub

Fills Word document templates using Jinja-style tags and Python context values.

Downloads / mo
4.7M
Stars
2.7K
Last release
0.20.2
License
LGPL-2.1-only
Runs on
Jinja2

Strengths

  • Keeps templates editable in Word. Design the document in Word, then fill its template tags from Python.
  • Accepts custom Jinja filters. Pass a Jinja environment containing the template filters the application needs.

Limitations

  • Template tags must stay together. Keep each tag inside one Word run, a single formatted text segment.
  • Context escaping starts disabled. Enable autoescape for values containing angle brackets or ampersands.

Quickstart

From latest.md
$ pip install docxtpl
from docxtpl import DocxTemplate
template = DocxTemplate('template.docx')
template.render({'name': 'Ada'}, autoescape=True)
template.save('output.docx')

docxtpl examples

From open-source projects on GitHub

Composes .docx documents.

Downloads / mo
2.0M
Stars
139
Last release
2.2.0
License
MIT

Quickstart

From README.md
$ pip install docxcompose
from docx import Document
from docxcompose.composer import Composer
composer = Composer(Document('master.docx'))
composer.append(Document('append.docx'))
composer.save('combined.docx')

docxcompose examples

From open-source projects on GitHub

Converts DOCX to PDF on Windows or macOS through an installed copy of Microsoft Word.

Downloads / mo
581.5K
Stars
600
Last release
0.1.8
License
MIT

Quickstart

From README.md
$ pip install docx2pdf
from docx2pdf import convert
convert('input.docx', 'output.pdf')

docx2pdf examples

From open-source projects on GitHub
def CreatMe(self):
    try:
        convert(self.new_filepath,self.pdf_filepath)
        self.log.debug("正确获取到pdf转化模块")
    except Exception as e:
        self.log.error("[Err] %s" % e)

Extracts content from DOCX files.

Downloads / mo
514.0K
Stars
213
Last release
3.7.2
License
MIT

Quickstart

From README.md
$ pip install docx2python
from docx2python import docx2python
with docx2python('input.docx') as document:
    text = document.text

docx2python examples

From open-source projects on GitHub

aspose-words

Creates, edits, converts, and renders Word documents locally.

Downloads / mo
465.1K
Stars
135
Last release
26.11.0
License
Commercial

Strengths

  • Converts Word documents to PDF. Save Word documents as PDF, HTML, or supported image formats.
  • Fills Word mail-merge templates. Generate documents by filling merge templates with application data.

Limitations

  • Evaluation mode adds watermarks. Apply a license for documents without evaluation watermarks.

Quickstart

From README.md
$ pip install aspose-words
import aspose.words as aw
document = aw.Document('input.docx')
document.save('output.pdf')

FAQ

python-docx suits creating and editing Word files paragraph by paragraph. docxtpl suits filling a Word template with Jinja-style tags. Mammoth suits converting DOCX into clean HTML.

python-docx creates, reads, and updates Microsoft Word .docx files. Its document API covers paragraphs, tables, sections, and inline shapes.

docxtpl fills a template authored in Word with Jinja tags and values from a Python context. It also supports rich text and subdocuments.

docx2pdf converts DOCX to PDF on Windows or macOS through an installed copy of Microsoft Word. aspose-words renders Word documents to other formats without Office.

docx2txt extracts plain text, including headers, footers, and hyperlinks, and can save embedded images. docx2python returns nested body, header, and footer content with images.

For coding agents

Found your Word DOCX library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official