Skip to main content

Track changes (revisions) support for python-docx: read, write and manipulate <w:ins> and <w:del> elements

Project description

Python Tracked Changes Library - docx-revisions

Documentation Tests Docs PyPI

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")

Find and replace with tracking

from docx_revisions import RevisionDocument

rdoc = RevisionDocument("contract.docx")
count = rdoc.find_and_replace_tracked("Acme Corp", "NewCo Inc", author="Legal")
print(f"Replaced {count} occurrences")
rdoc.save("contract_revised.docx")

Add tracked insertions and deletions

from docx_revisions import RevisionParagraph

rp = RevisionParagraph.from_paragraph(paragraph)
rp.add_tracked_insertion("new text", author="Editor")
rp.add_tracked_deletion(start=5, end=10, author="Editor")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docx_revisions-0.1.3.tar.gz (316.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docx_revisions-0.1.3-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file docx_revisions-0.1.3.tar.gz.

File metadata

  • Download URL: docx_revisions-0.1.3.tar.gz
  • Upload date:
  • Size: 316.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for docx_revisions-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a5ebc8c4f661025a1d403f84a3ed8dad6715dbf053f18f335444e0fceac1a9af
MD5 194148531ae5c5d293fcdcb4c16ca1a3
BLAKE2b-256 0924947ef8b064611a9316a17ac26011c92f1d8fb9fcf7b39b291e6a39cfb49a

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_revisions-0.1.3.tar.gz:

Publisher: release.yml on balalofernandez/docx-revisions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docx_revisions-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: docx_revisions-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for docx_revisions-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cd0d79a9001ad24f8bb35565b86c2ce7ab37b467e29a24bf1405ad762cdef479
MD5 750f42718ea29bf66a35142d17638bf9
BLAKE2b-256 f7999a9e060401f7bd1df72722242c61be87f4047d8a545da8a095600114e2ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_revisions-0.1.3-py3-none-any.whl:

Publisher: release.yml on balalofernandez/docx-revisions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page