Skip to main content

Lightweight DOCX comment engine based on text view API

Project description

Docxnote

Lightweight DOCX comment engine: add and read Word comments from plain paragraph text, with only an lxml dependency.

Python 3.12+ License: Apache 2.0 PyPI version GitHub stars

简体中文


Overview

docxnote automates Word comments (annotations) without manual run editing: you traverse Paragraph / Table / Cell, call paragraph.comment(...), and optionally read comments via paragraph.comments and doc.comments().

Repository: touken928/docxnote


Installation

pip install docxnote

With uv:

uv add docxnote

Quick start

from docxnote import DocxDocument, Paragraph, Table

# Load document
with open("document.docx", "rb") as f:
    # By default existing comments are stripped before writing new ones
    doc = DocxDocument.parse(f.read())

    # To preserve existing comments and append more:
    # doc = DocxDocument.parse(f.read(), keep_comments=True)

# Walk block-level content
for block in doc.blocks():
    if isinstance(block, Paragraph):
        if block.text:
            block.comment("Please review wording", end=5, author="reviewer")

    elif isinstance(block, Table):
        rows, cols = block.shape()
        for r in range(rows):
            for c in range(cols):
                cell = block[r, c]
                for inner in cell.blocks():
                    if isinstance(inner, Paragraph) and inner.text:
                        inner.comment("Needs review", end=3, author="reviewer")

# Write output
output = doc.render()
with open("output.docx", "wb") as f:
    f.write(output)

Table traversal accounts for Word tables whose rows omit leading or trailing grid columns. Comment ranges use Python slice semantics on paragraph.text, including negative and oversized endpoints; a reversed range is an empty anchor at its normalized start. See the API reference for details.


CLI

Installing docxnote adds a console script of the same name. Every read command supports --json, every write command takes an explicit output path, and they all share the library's addressable paths (p:0, t:0/r:1/c:2/p:0, p:0#3, ...).

docxnote list input.docx --text --json
docxnote show input.docx "t:0/r:1/c:2/p:0"
docxnote comments input.docx --json
docxnote annotate input.docx output.docx --path p:0 --text "please revise"
docxnote annotate input.docx output.docx --spec ops.json --keep-comments

Full reference: docs/CLI.md · docs/CLI_zh.md.

annotate rejects input/output aliases, including symlinks and hard links, and writes through a temporary sibling file before atomically replacing OUTPUT.

start / end always refer to character offsets inside paragraph.text using Python slice semantics ([start, end)). docxnote handles run splitting, including ranges that fall inside hyperlinks and other nested paragraph containers.


Documentation

Full Python API (methods, parameters, comments, paths, tables, and advanced patterns):

When keep_comments=True, existing comments are preserved and re-emitted with their existing comment XML metadata, while new comments are appended on top.


Tests

Test documents are generated with python-docx; no checked-in DOCX fixtures. See tests/README.md.


SKILL

npx skills add touken928/docxnote

Agent-oriented docs live under skills/docxnote.


License

Licensed under the Apache License, Version 2.0. See LICENSE in the repository root.

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

docxnote-0.3.3.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

docxnote-0.3.3-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file docxnote-0.3.3.tar.gz.

File metadata

  • Download URL: docxnote-0.3.3.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docxnote-0.3.3.tar.gz
Algorithm Hash digest
SHA256 530bbff2161d36ae9d6ec9c976cb2a1ee2cddc6af0afb44b91dab84a5c0c1e34
MD5 a291fcf2fbec56f529ae10a005328e95
BLAKE2b-256 4da1efc59e3e3508d302f8fbb0e5a17a1d82e9e922a2c7ce89b63edb86fb5416

See more details on using hashes here.

Provenance

The following attestation bundles were made for docxnote-0.3.3.tar.gz:

Publisher: publish.yml on touken928/docxnote

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

File details

Details for the file docxnote-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: docxnote-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docxnote-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a1a43e0acbe004c48dc1668df6716c8000a1ff9fca3e8a2750578c6ea840a294
MD5 2dbf3baabcf4dc3cf5c5099122b46951
BLAKE2b-256 82e3069dad352b95cd7ec56ca7bc0993b76064ecfe727cb4d129c1a5e3ec9da4

See more details on using hashes here.

Provenance

The following attestation bundles were made for docxnote-0.3.3-py3-none-any.whl:

Publisher: publish.yml on touken928/docxnote

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