Complete Word document comment manipulation with threading and Word Online compatibility
Project description
docx-comments
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.xmlbut no anchors indocument.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:
- comments.xml - Comment content and metadata
- document.xml - Anchors (
commentRangeStart/End,commentReference) - commentsExtended.xml - Threading (
paraId,paraIdParent,done) - commentsIds.xml - Durable IDs for persistence
Requirements
- Python 3.9+
- python-docx >= 1.0.0
- lxml
References
OOXML Specification
- ECMA-376 - Office Open XML File Formats (free download)
- ISO/IEC 29500 - OOXML Format Family overview
- MS-DOCX Extensions - Microsoft's DOCX extensions documentation
Comment Elements
- commentRangeStart - Comment anchor range start element
- commentRangeEnd - Comment anchor range end element
- commentReference - Comment content reference mark
- Comments Overview - OOXML comments specification
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f280cdc25ba26ea6738b42410a6c29eaf10c24ec2d251dcaf73c42e375f4b7a3
|
|
| MD5 |
a39aa671d672733359e9c6c34d2eb26c
|
|
| BLAKE2b-256 |
a4ca36b994d2217878df457357cb6d94f1fee531199b2b60dc85d0f3bd681565
|
Provenance
The following attestation bundles were made for docx_comments-0.1.1.tar.gz:
Publisher:
publish.yml on sunt05/docx-comments
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docx_comments-0.1.1.tar.gz -
Subject digest:
f280cdc25ba26ea6738b42410a6c29eaf10c24ec2d251dcaf73c42e375f4b7a3 - Sigstore transparency entry: 843015139
- Sigstore integration time:
-
Permalink:
sunt05/docx-comments@5a86b528fbbc81708e808ab94b5a1ed2c844d098 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/sunt05
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a86b528fbbc81708e808ab94b5a1ed2c844d098 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30ec86c0f272dd18bdce9f63c8907328049933c7ae415d5ebd3531709d93c011
|
|
| MD5 |
8da81c7021c59e87369ff3bfff56c12a
|
|
| BLAKE2b-256 |
1e4c6d2a79e7cee46c3d5e2c13687a85453a3e6a140b5026c843d262ea6ea1ce
|
Provenance
The following attestation bundles were made for docx_comments-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on sunt05/docx-comments
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docx_comments-0.1.1-py3-none-any.whl -
Subject digest:
30ec86c0f272dd18bdce9f63c8907328049933c7ae415d5ebd3531709d93c011 - Sigstore transparency entry: 843015156
- Sigstore integration time:
-
Permalink:
sunt05/docx-comments@5a86b528fbbc81708e808ab94b5a1ed2c844d098 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/sunt05
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a86b528fbbc81708e808ab94b5a1ed2c844d098 -
Trigger Event:
release
-
Statement type: