wolfdocx
Edit .docx files in Python. wolfdocx is a python-docx alternative that opens an existing Word document, applies your edits in place, and saves a new package where every part you did not touch is copied byte-for-byte from the original.
- Pure Python, no runtime dependencies.
- Python 3.11 or newer.
- MIT licensed.
Install
pip install wolfdocx
Quickstart
Open an existing .docx, read its paragraphs and tables, make a few edits, and save
the result to a new file.
from wolfdocx import Document
with Document("contract.docx") as doc:
# The first story under doc.node is the main document body.
body = doc.node.children[0]
for paragraph in body.paragraphs:
print(paragraph.to_string("txt").rstrip("\n"))
for table in body.tables:
print(table.to_string("txt"))
# Replace the text of one run. Paragraph and run indices are zero-based and
# count the direct paragraphs of the body and the direct runs of that paragraph.
first_run = body.paragraphs[0].runs[0]
doc.set_run_text(0, 0, "Master Services Agreement", expected_old_text=first_run.text)
# Regular-expression find and replace across runs.
replaced = doc.find_replace(r"ACME Corp\.?", "Acme Corporation")
print(replaced.status, replaced.replacement_count)
# Add a plain paragraph after the last body paragraph.
added = doc.append_paragraph("Signed electronically.")
print(added.status)
report = doc.save("contract-edited.docx")
print(report.status, report.changed_parts, report.raw_copied_parts)
Edits are held in memory until save(path) writes a new file, and doc.node is a
snapshot: read it again after an edit to see the updated tree.
When to use WolfDocx instead of python-docx
Use WolfDocx when you need targeted edits to an existing document and want every untouched package part to remain byte-for-byte identical.
- In-place edits. Each edit rewrites only the XML part it targets. Run properties, attributes, and neighboring markup stay where they were.
- Byte-for-byte preservation. On save, every package part you did not change is
copied from the source archive unchanged.
report.changed_partslists the parts that were rewritten andreport.raw_copied_partscounts the parts copied as-is. - Verified, no-clobber saves. The output is staged and checked before it is
published.
saverefuses to replace an existing file and reportsstatus == "refused"with acodeexplaining why. - Explicit refusals. An edit that cannot be applied safely, such as a
find_replacepattern with no match, returns a report withstatus == "refused"and leaves the document unchanged.set_run_textraisesRunTextEditErrorfor bad indices or anexpected_old_textmismatch.
wolfdocx works on .docx packages. It does not render pages, convert to PDF, or
read legacy binary .doc files.
Commercial capabilities
Commercial capabilities are available at https://wolfdocx.com.
Contributing
python -m pip install -e ".[dev]"
ruff check .
python -m pytest
Report bugs at https://github.com/wolfiesch/wolfdocx-oss/issues. For security issues, see SECURITY.md.
License
MIT. See LICENSE.
Metadata
Release files for wolfdocx 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wolfdocx-0.1.0.tar.gz | 566.6 kB | With provenance | Details for wolfdocx-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wolfdocx-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for wolfdocx-0.1.0-py3-none-any.whl |
Total release size: 1.0 MB
Release files / wolfdocx-0.1.0.tar.gz
| Download URL | wolfdocx-0.1.0.tar.gz |
|---|---|
| Size | 566.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3229e5d51a80b4c43a09919660f76cdde959b85dc85dcf6bfd614a6e91d5342
|
|
BLAKE2b-256 checksum How to use checksums |
2b08323e2ec54bd5a538d6a247ef1844439d67cd4a6f1dd1e9050c75143c9c33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logRelease files / wolfdocx-0.1.0-py3-none-any.whl
| Download URL | wolfdocx-0.1.0-py3-none-any.whl |
|---|---|
| Size | 467.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07385b983dd63a741ccf750645c020e7fb23ba60a02e6e3a2c3378c382f0569b
|
|
BLAKE2b-256 checksum How to use checksums |
b3102f1327ee3dfad129b8e64d32b4743634673668e53225da3d7326b10b836c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logSecurity for wolfdocx 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for wolfdocx-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.