Add Word comments to matching text in .docx files.
Project description
word-comment
word-comment adds a Microsoft Word comment to matching text in a .docx file.
It targets a specific paragraph by w14:paraId, finds the first matching occurrence of target_text inside that paragraph, and inserts a standard Word comment range plus comment metadata.
Installation
Install from PyPI:
python -m pip install word-comment
Install from GitHub source instead:
gh auth login
pip install git+https://github.com/AI-Part-A/word-comment.git
Google Colab Source Install
If you want to install from the private GitHub repository in Colab, store these secrets first:
GITHUB_USER: your GitHub usernameGITHUB_TOKEN: a fine-grained personal access token with repository read access
from google.colab import userdata
import subprocess
import sys
github_user = userdata.get("GITHUB_USER")
github_token = userdata.get("GITHUB_TOKEN")
subprocess.run(
[
sys.executable,
"-m",
"pip",
"install",
f"git+https://{github_user}:{github_token}@github.com/AI-Part-A/word-comment.git",
],
check=True,
)
Python API
from word_comment import add_comment
result = add_comment(
input_path="input.docx",
output_path="output.docx",
para_id="7BD69366",
target_text="keyword",
comment_text="comment body",
author="Auto_Bot",
)
print(result.success)
print(result.inserted_count)
print(result.reason)
CLI
word-comment input.docx output.docx 7BD69366 "keyword" "comment body" --author Auto_Bot
Behavior
- Searches for the paragraph whose
w14:paraIdmatchespara_id - Finds the first occurrence of
target_textin that paragraph - Inserts a Word comment range and a
commentReference - Creates
word/comments.xmlwhen it does not already exist - Adds the required relationship and content-type entries when needed
- Copies the input file unchanged when the paragraph or target text is not found
Return Value
add_comment(...) returns AddCommentResult with:
success: boolinserted_count: intpara_id: stroutput_path: Pathreason: str | None
Possible reason values:
paragraph_not_foundtarget_text_not_found
Limitations
- The target paragraph must already have a
w14:paraId target_textis matched against the concatenatedw:ttext in the selected paragraph- Only the first match in the selected paragraph is annotated
- The implementation modifies
word/document.xmlandword/comments.xml
Development Release Check
Build artifacts locally:
python -m build
python -m twine check dist/*
Project details
Release history Release notifications | RSS feed
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 word_comment-0.1.1.tar.gz.
File metadata
- Download URL: word_comment-0.1.1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44a168cee9e4f3e43d94a145c08562e40b7b191ef93313bf656988de44845966
|
|
| MD5 |
103739848ff444331b0e16747f3bfc1e
|
|
| BLAKE2b-256 |
31575c5daa0fe3cd0f52b1ff5033957d533902eef6a5fe69d3d77da168076ff5
|
File details
Details for the file word_comment-0.1.1-py3-none-any.whl.
File metadata
- Download URL: word_comment-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c54a2ca28397471d3b163a3b4429476dfda3a1f3a893b5cf89a6a8c34108a060
|
|
| MD5 |
2b8b29eb6fae44a7e07dcb85fe06614e
|
|
| BLAKE2b-256 |
ac3093c9a5e776dc23142f0d8a40052a5c59edf7b72f4364d07fe66171ca8599
|