docx2txt

A pure-Python utility to extract text and images from Microsoft Word .docx files.

Library
PyPI
v0.9
585stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity0
Maintenance20
Community68
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture58
Code Quality55
Innovation60
Learning Curve88

docx2txt is a lightweight, pure-Python library and command-line tool for pulling plain text and embedded images out of Microsoft Word .docx documents. Adapted from python-docx, it goes further by also extracting content from headers, footers, and hyperlinks, and by writing embedded images to a directory of your choice.

With a single process() call or a one-line CLI invocation and no heavy dependencies, it is a common building block in document-processing pipelines, search indexing, and data-extraction workflows that need quick access to the textual content of Word files.

What You Get

  • A single process() function that returns the document’s text as a string
  • Optional extraction of embedded images to a specified directory
  • Text capture from headers, footers, and hyperlinks in addition to the body
  • A command-line entry point for extracting text and images without writing code

Common Use Cases

  • Feeding Word document text into search indexes or full-text pipelines
  • Bulk-extracting content from .docx files for data analysis or migration
  • Pulling images and text out of documents in ETL and automation scripts

Under The Hood

Architecture - The whole library is a single module, docx2txt/docx2txt.py (~113 lines), exposing a process() function. It treats the .docx file as a zip archive, reads word/document.xml plus header and footer parts, walks the XML with xml.dom.minidom to collect text and hyperlink nodes, and copies any files under word/media/ to the caller-supplied image directory.

Tech Stack - It is pure Python built on the standard library (zipfile, xml.dom.minidom, os/glob), with no third-party runtime dependencies. Packaging is a classic setuptools setup.py that also installs a bin/docx2txt script as a console entry point.

Code Quality - The code is compact and readable but minimal: there is no bundled test suite, and error handling is limited, reflecting its origin as an adaptation of python-docx focused on one job. Its long track record and wide adoption compensate for the thin structure.

API Design - The public surface is deliberately tiny: docx2txt.process(path) for text, or process(path, img_dir) to also dump images. This one-function design makes it trivial to adopt, though it offers little configuration beyond the image directory.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search