Skip to main content

Complete Word document comment manipulation with threading and Word Online compatibility

Project description

docx-comments

PyPI version Python versions CI License: MIT

Python module for complete Word document comment manipulation - adding, replying, and resolving comments with full Word Online compatibility.

Problem

python-docx can read Word comments but cannot properly create or reply to them:

  • Creates comments.xml but no anchors in document.xml
  • Missing commentsExtended.xml (threading)
  • Missing commentsIds.xml (durable IDs)

Microsoft Graph API does NOT support Word comments (only Excel).

Solution

This module provides complete OOXML comment manipulation based on ECMA-376 / ISO/IEC 29500:

  • Add anchored comments to specific text ranges
  • Reply to existing comments (threaded)
  • Mark comments as resolved
  • Full Word Online compatibility

Installation

pip install docx-comments

Usage

from docx import Document
from docx_comments import CommentManager

doc = Document("document.docx")
mgr = CommentManager(doc)

# Add anchored comment to text range
comment_id = mgr.add_comment(
    paragraph=doc.paragraphs[0],
    start_run=0,
    end_run=2,
    text="Please review this section",
    author="Reviewer Name",
    initials="RN"
)

# Reply to existing comment
reply_id = mgr.reply_to_comment(
    parent_id=comment_id,
    text="Addressed in this revision",
    author="Author Name",
    initials="AN"
)

# Mark comment as resolved
mgr.resolve_comment(comment_id)

# List all comment threads
for thread in mgr.get_comment_threads():
    print(f"Root: {thread.root.text} by {thread.root.author}")
    for reply in thread.replies:
        print(f"  Reply: {reply.text} by {reply.author}")

doc.save("document_reviewed.docx")

OOXML Parts Handled

This module manages four XML parts:

  1. comments.xml - Comment content and metadata
  2. document.xml - Anchors (commentRangeStart/End, commentReference)
  3. commentsExtended.xml - Threading (paraId, paraIdParent, done)
  4. commentsIds.xml - Durable IDs for persistence

Requirements

  • Python 3.9+
  • python-docx >= 1.0.0
  • lxml

References

OOXML Specification

Comment Elements

Threading & Extended Parts

  • CommentEx Class - Office 2013 comment threading (paraId, paraIdParent, done)
  • commentsIds - Durable IDs specification (Office 2016+)

Related Libraries

  • python-docx - Python library for Word documents (foundation for this module)
  • Open XML SDK - Microsoft's .NET SDK for OOXML

Acknowledgements

This project was conceptualised by Ting Sun and implemented with the assistance of Claude Code (Anthropic's AI coding assistant) under his guidance. The collaboration involved iterative development of the OOXML comment handling logic, with Claude Code contributing to code implementation and Ting Sun providing architectural direction and domain expertise.

License

MIT

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_comments-0.1.1.tar.gz (78.2 kB view details)

Uploaded Source

Built Distribution

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

docx_comments-0.1.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file docx_comments-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for docx_comments-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f280cdc25ba26ea6738b42410a6c29eaf10c24ec2d251dcaf73c42e375f4b7a3
MD5 a39aa671d672733359e9c6c34d2eb26c
BLAKE2b-256 a4ca36b994d2217878df457357cb6d94f1fee531199b2b60dc85d0f3bd681565

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_comments-0.1.1.tar.gz:

Publisher: publish.yml on sunt05/docx-comments

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_comments-0.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for docx_comments-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30ec86c0f272dd18bdce9f63c8907328049933c7ae415d5ebd3531709d93c011
MD5 8da81c7021c59e87369ff3bfff56c12a
BLAKE2b-256 1e4c6d2a79e7cee46c3d5e2c13687a85453a3e6a140b5026c843d262ea6ea1ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for docx_comments-0.1.1-py3-none-any.whl:

Publisher: publish.yml on sunt05/docx-comments

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