docx2txt
A pure-Python utility to extract text and images from Microsoft Word .docx files.
Repository Health
Technical Analysis
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.
Used by 2 apps in this directory
Khoj
AI Assistants · Knowledge Management · Productivity
A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.
Open WebUI
AI Assistants · AI Agents
The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.