Registry / data / docx2txt

docx2txt

JSON →
library0.9pypypi✓ verified 26d ago

docx2txt is a pure Python-based utility designed to extract text and images from .docx files. It leverages the `python-docx` library for parsing the document structure and `Pillow` for image handling. The current version is 0.9, and the project appears to be in maintenance mode with infrequent releases, primarily addressing minor updates.

pip install docx2txt
INSTALL
IMPORT
SIG · DOCX2TXT
D
docx2txt
datapythonv0.9
Install
1.5s avg
Import
74ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.080s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.068s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

process
from docx2txt import process
import docx2txt

This quickstart demonstrates how to extract text from a .docx file and optionally extract embedded images to a specified directory. Ensure a .docx file exists for the example to run correctly.

import docx2txt import os # Assuming 'my_document.docx' exists in the current directory # and 'extracted_images' is a directory for image output. # If 'my_document.docx' does not exist, create a dummy one for testing. if not os.path.exists('my_document.docx'): print("Please create a dummy 'my_document.docx' file for this example.") # Example: Create a simple dummy docx (requires python-docx library) # from docx import Document # document = Document() # document.add_paragraph('This is a test document for docx2txt.') # document.save('my_document.docx') # Extract text text = docx2txt.process("my_document.docx") print("Extracted Text:\n", text) # Extract text and images to a specified directory image_dir = 'extracted_images' if not os.path.exists(image_dir): os.makedirs(image_dir) text_with_images = docx2txt.process("my_document.docx", image_dir) print(f"\nExtracted Text (images saved to {image_dir}):\n", text_with_images)
Debug
Known issues
gotchaInput files must exist and be valid .docx files. Passing non-existent paths or corrupted/invalid files will raise `FileNotFoundError` or other exceptions from `python-docx`.
fix
Always ensure the input path points to an accessible and valid .docx file before calling `docx2txt.process()`.
affects: 0.1 - 0.9
gotchaWhen extracting images, you must provide a valid directory path for `img_dir`. If `img_dir` is not provided, images will be skipped. If the provided directory does not exist, `docx2txt` will attempt to create it. Ensure the process has write permissions to the specified `img_dir`.
fix
Pass a string representing an existing or creatable directory path to the `img_dir` argument of `docx2txt.process()`.
affects: 0.1 - 0.9
gotchadocx2txt relies on `python-docx` and may not perfectly handle all complex .docx features (e.g., embedded objects, intricate formatting, specific table layouts, or non-standard XML structures). Text extraction might lose some formatting or omit certain content types.
fix
For critical applications, always verify the extracted text against the original document. Consider alternative libraries or more robust parsing solutions for highly complex documents.
affects: 0.1 - 0.9
gotchaAlthough PyPI states `requires_python: None`, the underlying `python-docx` dependency (version >=0.8.10) requires Python 3.6 or newer. Therefore, `docx2txt` effectively also requires Python 3.6+ to function correctly.
fix
Ensure your environment uses Python 3.6 or a newer version before installing and using `docx2txt`.
affects: 0.1 - 0.9
Upgrade
Version history
0.9latest on PyPI · released Mar 24, 2025
Audit
Dependencies
python-docxrequiredCore dependency for parsing .docx file structure and extracting text.
PillowrequiredUsed for handling and saving extracted images from .docx files.
Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
docx2txt — pip install docx2txt · libregistry