docx_plus.comments.people¶
Comment author presence — /word/people.xml.
Word records one entry per comment author, driving the presence indicator beside a comment in the reviewing pane and the identity a click resolves to:
<w15:people>
<w15:person w15:author="Thomas Villani">
<w15:presenceInfo w15:providerId="AD"
w15:userId="S::thomas@example.com::541bd2ef-..."/>
</w15:person>
</w15:people>
Nothing here runs automatically
The part is purely cosmetic — comments, threading, and resolution all work without it, and Word neither requires it nor complains when it is missing.
add_comment deliberately does not write
it. Registering an author means inventing a userId for someone
the library knows nothing about, and a fabricated directory
identity is worse than an absent one. Call set_author_presence
explicitly when you want the entry.
The author name is the only join between this part and
comments.xml — there are no comment ids here — so the name passed to
set_author_presence must match the w:author on that person's
comments exactly.
Stale authors are not pruned when their last comment is deleted.
Word does not prune them either, and doing so would need the author
ref-counted across every surviving comment. clear_author_presence is
the explicit escape hatch.
Architecture walkthrough: Durable ids and author presence.
docx_plus.comments.people ¶
people.xml — comment author presence.
Word records one entry per comment author in a separate
/word/people.xml part:
.. code-block:: xml
<w15:people>
<w15:person w15:author="Thomas Villani">
<w15:presenceInfo w15:providerId="AD"
w15:userId="S::thomas@example.com::541bd2ef-..."/>
</w15:person>
</w15:people>
The part drives the presence indicator beside a comment in Word's reviewing pane — the dot that says whether the author is online, and the identity a click resolves to. It is purely cosmetic. Comments, threading, and resolution all work without it; Word neither requires it nor complains when it is missing.
That is why nothing here runs automatically. :func:~docx_plus.comments.add_comment
deliberately does not write this part: registering an author means
inventing a userId for someone the library knows nothing about, and
a fabricated directory identity is worse than an absent one. Call
:func:set_author_presence explicitly when you want the entry.
Word does not prune stale authors when their last comment is
deleted, and neither does this module — see :func:clear_author_presence.
This module imports only from docx_plus.core (SPEC §9.1).
AuthorPresence
dataclass
¶
One author's entry in people.xml.
Attributes:
| Name | Type | Description |
|---|---|---|
author |
str
|
The author name, matching the |
provider_id |
str | None
|
The identity provider ( |
user_id |
str | None
|
The provider-scoped identity string. |
set_author_presence ¶
set_author_presence(
doc: Document,
author: str,
*,
provider_id: str = LOCAL_PROVIDER,
user_id: str | None = None,
) -> AuthorPresence | None
Record author in people.xml, creating the part on first use.
Idempotent — re-registering an author replaces that author's entry rather than appending a second one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
author
|
str
|
Author name. Must match the |
required |
provider_id
|
str
|
Identity provider. Defaults to
:data: |
LOCAL_PROVIDER
|
user_id
|
str | None
|
Provider-scoped identity. Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
AuthorPresence | None
|
class: |
AuthorPresence | None
|
is empty. |
Example
from docx import Document from docx_plus.comments import add_comment, set_author_presence doc = Document() add_comment(doc.add_paragraph("text"), "note", author="Reviewer") CommentRef(comment_id=..., body_element=...) set_author_presence(doc, "Reviewer") AuthorPresence(author='Reviewer', provider_id='None', user_id='Reviewer')
Source code in docx_plus/comments/people.py
read_author_presence ¶
Return every author entry in doc's people.xml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[AuthorPresence]
|
class: |
list[AuthorPresence]
|
order. Empty when the part is absent — the state of every |
|
list[AuthorPresence]
|
document this library wrote before v0.5, and of anything not |
|
list[AuthorPresence]
|
produced by Word. Entries with no |
|
list[AuthorPresence]
|
an entry with no |
|
list[AuthorPresence]
|
both provider and user id. |
Example
from docx import Document from docx_plus.comments import read_author_presence read_author_presence(Document()) []
Source code in docx_plus/comments/people.py
clear_author_presence ¶
Remove every author entry, optionally tearing down the part.
Deliberately not wired into
:func:~docx_plus.comments.delete_comment. Pruning on delete would
need the author ref-counted across every surviving comment, and Word
does not do it either — a document that once had a comment from a
given author keeps that author's entry. Call this explicitly if a
stale name is a problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
remove_part
|
bool
|
When |
False
|
Example
from docx import Document from docx_plus.comments import clear_author_presence clear_author_presence(Document())