WolfSuiteWolfXLWolfPPTWolfDocxWolfRender

WolfDocx - python-docx alternative

A python-docx alternative for editing existing Word documents

Keep python-docx for building documents and reading their structure. When a pipeline may change only approved values in a reviewed .docx, WolfDocx lists the editable targets, binds each edit to the exact source file, and writes a new file only when every edit verifies.

Two edits in one request

from wolfdocx.reporting import author_report, discover_report_targets, parse_report_request

found = discover_report_targets("board_memo.docx")
by_text = {t["expected_old_text"]: t for t in found["targets"]}
report = author_report(parse_report_request({
    "source": "board_memo.docx",
    "destination": "board_memo_final.docx",
    "source_sha256": found["source_sha256"],
    "edits": [
        {**by_text["$0"], "text": "$7,500"},
        {**by_text["Status: Draft"], "expected_old_text": "Draft", "text": "Final"},
    ],
}))
assert report.passed, report.code
print(report.status, report.unselected_parts_preserved)  # published True

discover_report_targets returns each editable table cell and paragraph with its current text and a structure fingerprint, plus the SHA-256 of the source file. The request names the targets to change and the text each one must hold today. If the file or a target changed after discovery, the write is refused with a code such as expected_old_text_mismatch, and no output file appears. Both edits above apply together or not at all.

The phrase Draft sits in its own run next to a bold label, and the replacement takes the formatting of the run that holds it. report.unselected_parts_preserved confirms that every part outside the edits kept its original content.

When python-docx fits

  • You build documents from code, add paragraphs, tables, and images, or work with styles.
  • You need general read and write access to paragraphs, runs, and tables, and a missing value is acceptable in the output.
  • You inspect a document, for example to read the file WolfDocx wrote: Document("board_memo_final.docx") opens it like any other .docx.

What WolfDocx adds for documents that already exist

  • Find and replace across runs. python-docx exposes paragraphs and runs and has no built-in find and replace, so a phrase that Word split across runs needs custom code. WolfDocx handles that split for supported runs.
  • Edits bound to what you reviewed. A stale source or an unexpected target value stops the write instead of changing the wrong text.
  • A verification report. The result states whether the destination was published and whether unselected parts were preserved.

A published example replaces Q2 with Q3 in one memo saved by Word. The python-docx script, which edits runs through paragraphs, hyperlinks, tables, and headers, changed 6 of the 8 places. The other two sat in a content control and a text box, which the python-docx API does not expose. That example ran the wolf command's replace-text operation, so it does not exercise the WolfDocx Python API shown above, and it covers one document. See the side-by-side example on wolfsdk.com.

Limitations

  • Discovery lists text that sits in simple runs. Text that intersects fields, tracked revisions, comments, content controls, or other unsupported inline structures is refused.
  • A phrase must occur exactly once in the selected paragraph. Ambiguous matches are refused.
  • Headers and footers work when you name their part, for example discover_report_targets(path, part="word/header1.xml").
  • The WolfDocx Python API edits content and does not lay out pages, and it makes no general Word compatibility promise. The convert guide linked below covers PDF output.

Related tasks: replace text in an existing Word document, update table cells, and convert a .docx to PDF.

Get WolfDocx

WolfDocx Community is MIT-licensed and free, including commercial use. It edits existing .docx files in place in pure Python and does not render pages or convert to PDF. WolfDocx Commercial does not change those rights.

pip install wolfdocx

WolfDocx Commercial is an organization-scoped subscription. WolfDocx Community installs from public PyPI with pip install wolfdocx. WolfDocx Commercial installs from the authenticated WolfDocx package index with a per-purchase credential, issued on the checkout success page after payment and reissued through https://wolfxl.com/recover.

Review the scoped before-and-after memo files in the reporting walkthrough, or ask about your document before purchasing if compatibility is uncertain.

Related tasks

Cost

WolfDocx Commercial is an organization-scoped subscription. The pricing page lists the current terms, and the WolfDocx home page links the before-and-after memo files to review first.