Track changes (revisions) support for python-docx: read, write and manipulate <w:ins> and <w:del> elements
Maintained. Last release 8 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install docx-revisionsPython Tracked Changes Library - docx-revisions
Read and write track changes in Word documents (.docx) with Python. docx-revisions extends python-docx to support document revision tracking, change tracking, and OOXML revision markup (insertions <w:ins> and deletions <w:del>) so you can programmatically accept text, list revisions with author and date, and apply insertions, deletions, or replacements with full revision metadata.
Use it for Microsoft Word-compatible revision tracking: parse DOCX files with track changes on, get accepted (clean) text, enumerate revisions per paragraph, or write new revisions (insert/delete/replace) that show up as track changes in Word.
Installation
pip install docx-revisions
Quick Start
Check out our examples!
Navigate to the examples directory to see code samples.
Read tracked changes
from docx_revisions import RevisionDocument
rdoc = RevisionDocument("tracked_changes.docx")
for para in rdoc.paragraphs:
if para.has_track_changes:
for change in para.track_changes:
print(f"{type(change).__name__}: '{change.text}' by {change.author}")
print(f"Accepted: {para.accepted_text}")
print(f"Original: {para.original_text}")
Accept or reject all changes
from docx_revisions import RevisionDocument
rdoc = RevisionDocument("tracked_changes.docx")
rdoc.accept_all() # or rdoc.reject_all()
rdoc.save("clean.docx")