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](https://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](https://wolfdocx.com/replace-text-docx-python), [update table cells](https://wolfdocx.com/update-docx-table-python), and [convert a .docx to PDF](https://wolfdocx.com/convert-docx-to-pdf-python).

## 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](https://wolfsdk.com/blog/updating-existing-office-reporting-files), or [ask about your document](mailto:trial@wolfxl.com?subject=WolfDocx%20workflow%20fit) before purchasing if compatibility is uncertain.

[See WolfDocx Commercial](https://wolfdocx.com/)

### Related tasks

- [Update table cells in an existing Word document with Python](https://wolfdocx.com/update-docx-table-python)
- [Replace text in an existing Word document with Python](https://wolfdocx.com/replace-text-docx-python)
- [Fill a Word template table with rows from Python](https://wolfdocx.com/fill-word-template-python)
- [Word mail merge in Python: fill MERGEFIELD templates and repeating table rows](https://wolfdocx.com/mail-merge-docx-python)
- [Merge Word documents in Python without breaking numbering, headers, or styles](https://wolfdocx.com/merge-docx-python)
- [Update a Word table of contents in Python without opening Word](https://wolfdocx.com/update-toc-docx-python)
- [Convert DOCX to PDF in Python without Word or LibreOffice](https://wolfdocx.com/convert-docx-to-pdf-python)
- [A python-docx alternative for editing existing Word documents](https://wolfdocx.com/python-docx-alternative)
- [How can Python generate many legal contracts from one Word template?](https://wolfdocx.com/generate-contracts-docx-python)
- [Which Python workflow assembles one Word document from clauses and sections?](https://wolfdocx.com/document-assembly-python)
- [How do you prevent Word's unreadable content warning after a python-docx save?](https://wolfdocx.com/python-docx-unreadable-content)
- [Why does python-docx change Link to Previous on headers and footers?](https://wolfdocx.com/python-docx-header-footer-link-to-previous)
- [Can python-docx handle nested tables and complex headers?](https://wolfdocx.com/nested-tables-docx-python)

## Cost

WolfDocx Commercial is an organization-scoped subscription. The [pricing page](https://wolfxl.com/pricing) lists the current terms, and the [WolfDocx home page](https://wolfdocx.com/) links the before-and-after memo files to review first.
