Create, read, and update Microsoft Word .docx files.
Actively maintained. Last release 2 months ago, commits in 5 of the last 26 weeks. A safe choice.
pip install paper-docxAn import-compatible, agent-safe fork of python-docx for creating and editing Word documents without silent corruption.
paper-docx is an import-compatible hard fork of python-docx for creating and editing Microsoft Word (.docx) documents. It keeps the docx import name and upstream object model, and adds guarded inspection and editing APIs that refuse unsupported operations instead of guessing.
Installation
Use an activated virtual environment.
python -m pip uninstall -y python-docx paper-docx
python -m pip install paper-docx
python -m paper_docx_doctor
Both distributions provide the docx import package. Do not install python-docx and paper-docx in the same environment.
To return to python-docx, run the uninstall line above again, then python -m pip install python-docx.
Quick start
Create a Word redline from two document versions:
import docx
from docx.package import compare
original = docx.Document()
original.add_paragraph("Payment is due within thirty calendar days.")
original.save("original.docx")
revised = docx.Document()
revised.add_paragraph("Payment is due within thirty business days.")
revised.save("revised.docx")
result = compare("original.docx", "revised.docx", author="Reviewer")
result.document.save("redline.docx")
print(result.revision_count) # 2
compare writes differences as tracked changes and refuses changes it cannot represent safely.
Documentation
Read the paper-docx documentation.