Skip to main content

WolfDocx python-docx import alias

Use import wolfdocx_docx as docx for the documented python-docx API subset over WolfDocx's native document builder and verified session saves. Install this separate, opt-in distribution alongside WolfDocx. The docx namespace remains available to python-docx; no upstream runtime dependency or import replacement is required.

Install and use

pip install wolfdocx-docx

The MIT wolfdocx engine is the only runtime dependency. Capabilities that engine does not ship raise ModuleNotFoundError("commercial_feature_unavailable").

import wolfdocx_docx as docx
from wolfdocx_docx.shared import Inches, RGBColor

report = docx.Document()
report.add_heading("Operating review", level=1)
paragraph = report.add_paragraph("Status: ")
paragraph.add_run("approved").bold = True
cell = report.add_table(rows=1, cols=2).cell(0, 0)
cell.text = "Owner"
report.save("review.docx")

opened = docx.Document("review.docx")
opened.paragraphs[0].text = "Updated operating review"
opened.tables[0].cell(0, 1).text = "Finance"
opened.save("review.docx")

Supported API

Surface Supported operations
Document Document(), open a path or seekable binary stream; paragraphs, tables, add_paragraph, add_heading levels 0–9, add_table, save to a path or seekable binary stream
Paragraph text, runs, add_run(text, style), clear(), alignment
Run text, tri-state bold and italic; boolean/None underline writes and existing OOXML underline-value reads
Table cell(row_idx, col_idx), live rows sequence (iteration, indexing and slicing), add_row(); zero-sized tables
Row cells, including repeated grid positions for merged cells
Cell text, paragraphs, tables, grid_span, add_paragraph, nested add_table
Shared values Length, Inches, Cm, Mm, Pt, Twips, Emu, RGBColor

Use zero-based table coordinates. Text assignments translate tabs and line breaks as python-docx does. Preserve run formatting when assigning run text; preserve paragraph properties and clear run formatting when assigning paragraph text. Assign docx.WD_ALIGN_PARAGRAPH.CENTER (or the other native alignment constants) to paragraph.alignment; assign None to inherit alignment from its style.

Resolve style names and IDs against an opened package's styles. For missing names in new documents, create native minimal style definitions. The python-docx bundled template and its formatting are outside this coverage. Style objects, pictures, sections, headers and footers, core properties, the upstream comments API, full font APIs, OXML/OPC internals, and all unlisted APIs are outside this coverage.

Save through the native verified session path before publication. For a path, replace the destination atomically after staging; follow an existing symbolic link to its target and retain existing file permissions. Return None, as python-docx does. Preserve unchanged package members, including opaque parts. Native validation refusals raise wolfdocx.model.NodeEditError. Native wolfdocx.Document.save retains its separate no-clobber contract.

Upstream coverage

Pin python-docx v1.2.0 at commit e45454602b53e8e572b179ccf1c91093ec9f4ed7. The MIT license and source-file digests are recorded in upstream/pin.json; ship the derived shared-type notice in THIRD_PARTY_NOTICES.txt. upstream/expected.json freezes the digest of pin.json, pins upstream tests/test_document.py, tests/test_table.py, tests/text/test_paragraph.py and tests/text/test_run.py by sha256 and git blob, and records the admitted node IDs, every excluded node with its reason, and exclusion rules for every other upstream test module and feature file. The admitted set was frozen before implementation; changing it requires central approval.

Five unmodified upstream test modules run through the import alias. Every module remains partially exercised; none is fully qualified:

Upstream module Passing cases Excluded cases Status
tests/test_shared.py 18 of 21 3 ElementProxy cases partial
tests/test_document.py 8 of 32 24, each with its own reason partial
tests/test_table.py 24 of 150 126, each with its own reason partial
tests/text/test_paragraph.py 13 of 59 46, each with its own reason partial
tests/text/test_run.py 10 of 79 69, each with its own reason partial

The other 54 upstream test modules and 67 feature files remain excluded by rule. Before the table and text admissions, the gate exercised 2 of 59 test modules and passed 26 of 53 collected nodes, excluding 27 nodes and 124 other modules or feature files. With both admissions, it exercises 5 of 59 modules and passes 73 of 341 collected nodes, excluding 268 nodes and 121 other modules or feature files. The newly inventoried table and text modules account for the larger excluded-node denominator; no formerly admitted node was removed. Never treat excluded cases as passing.

The table cases cover grid-coordinate cell access, row enumeration, cell grid-span and text reads (including tabs, breaks and multiple paragraphs), paragraph access, and row-sequence iteration, indexing, bounds and owning-table access. The native XML constructors import supplied XML into fresh native stories. For foreign lxml input, serialize with lxml's C serializer to avoid invoking polymorphic upstream text accessors. No upstream document, table or cell engine runs. The two native XML child-list views used by the unchanged cell-access test do not qualify the full upstream OXML object model or original input-element identity.

A separate focused edit/save/reopen scenario in tests/test_ltg_docx_alias_upstream_table_20261111.py compares the same table-edit script against the pinned python-docx checkout in an isolated process. It covers add_row, horizontal and vertical merged-cell addressing, live row sequences and slices, cell replacement, paragraph append and direct run-text edits. Preserve all direct run properties for run-text edits, including unlisted font properties. Whole-cell text replacement intentionally clears content and direct run formatting, as in python-docx. Structural merge, row deletion and column mutation remain unsupported; no paragraph-deletion fallback stands in for those operations. Check neighboring content, other tables, non-table paragraphs and unchanged package members separately.

The 23 admitted text cases were frozen before implementation: paragraph text reads (including hyperlinks, tabs and breaks), paragraph text replacement, paragraph alignment reads, run text reads, and run bold/italic tri-state reads. The bodies and pinned source files are unchanged. Other setters that assert private upstream _p.xml/_r.xml serialization remain excluded, alongside style, font, hyperlink-object, rendered-page-break and unimplemented authoring APIs. Every excluded node and file has its own recorded reason.

Separate save/reopen qualification compares mixed-run edits, paragraph replacement, add_run, bold/italic and alignment with python-docx loaded from the exact pinned source checkout. It checks line breaks, retained paragraph styles, cleared run formatting after paragraph replacement, untouched neighboring XML and byte-identical unrelated package parts. Use the native lower-level Paragraph/Run XML constructors for detached text trees; upstream OXML identity, serialization helpers and parent/part graphs remain outside the public alias contract. Native input nodes retain their builder ownership.

The eight Document cases are upstream unit tests built on mocks:

  • add_heading for levels 0, 1, 2 and 9 chooses the Title or Heading N style and delegates to add_paragraph.
  • add_heading rejects levels -1 and 10 with python-docx's message.
  • add_paragraph passes ("", None), ("", "Heading 1") and ("foo\rbar", "Body Text") to the document body and returns its result.

Each case calls the native wolfdocx_docx.document.Document. Its collaborators are mocks specified from pinned upstream classes: the patched add_paragraph method, the _body property, and the body, paragraph and document-part objects. These cases prove method contracts, not saved content. Saved content is covered separately by the native save/reopen tests in tests/test_ltg_docx_alias_upstream_document_20261111.py. They check requested content, text order, table dimensions, path and stream saves, and unchanged unrelated package members.

The alias replaces docx.shared, docx.document, docx.table, docx.text.paragraph and docx.text.run only while the upstream test modules are imported. Every symbol under test resolves to its native wolfdocx_docx module (shared, document, table or text). ElementProxy, the private _Body, _Column and _Columns are pinned upstream fixture-only symbols: _Body serves only as a mock specification and as the subject of excluded cases; _Column and _Columns occur only in excluded column cases. Upstream fixtures, the lxml element builder and mock specifications, load from the pinned checkout during verification only. The fixtures call the lower-level Document(element, part) constructor; it imports the element into a fresh native builder and does not use the part. The following are not qualified:

  • private internals: the body object, the OPC part graph, _block_width, and the constructor's upstream object-graph contract
  • drop-in compatibility with python-docx

For each admitted case, the verifier traces setup, call and teardown. It fails if native code calls upstream python-docx code, if a call runs no native code, or if the test module or declared document/table fixture holds an object that is not native. Collection must import no further upstream module while the alias is active.

The retained verification receipt records the passing and excluded node IDs, per-module and total denominators, per-case runtime provenance, and the complete file exclusion inventory. It also records source, environment and pinned-input identities, plus SHA-256 digests of the native implementation files.

Separate consumer-facing tests cover Document, paragraph, run and table behavior in tests/test_document.py, using independent package readers and python-docx as a test-only output oracle.

From this package directory, in a POSIX shell:

uv run python tools/verify_upstream.py fetch
uv run --with lxml --with typing_extensions --with pyparsing python tools/verify_upstream.py verify \
  --report "$HOME/.cache/wolfdocx-docx/upstream/verify-report.json" \
  --portable-report upstream/verification.json
uv run pytest tests/test_shared.py tests/test_document.py \
  tests/test_ltg_docx_alias_upstream_document_20261111.py \
  tests/test_ltg_docx_alias_upstream_table_20261111.py \
  tests/test_ltg_docx_alias_upstream_text_20261111.py

Only fetch uses the network; verify runs offline against a clean external cache. Choose the cache with --cache-dir. --report writes the raw receipt with local paths; keep it outside the repository. --portable-report writes the same receipt with repository-relative and external-upstream-cache paths for retention.

WolfDocx agent-edit extensions

Use document.wolf for the following WolfDocx-only APIs. These are extensions, not python-docx behavior. In particular, python-docx has no tracked-edit review, thread reply/resolution, or persistent paragraph/run/table address API. Its own comment API is not implemented by this alias; use the range API below instead.

import wolfdocx_docx as docx

document = docx.Document("review.docx")
paragraph = document.wolf.identify(document.paragraphs[0])
run = document.wolf.identify(document.paragraphs[1].runs[0])
table = document.wolf.identify(document.tables[0])
metadata = {"author": "Editor", "date": "2026-11-09T12:00:00Z"}
# Replace a character range with native tracked deletion and insertion records.
document.wolf.track(paragraph, 0, 4, "Revised", **metadata)
document.save("tracked.docx")

reopened = docx.Document("tracked.docx")
for revision in reopened.wolf.revisions():
    reopened.wolf.accept(revision)  # or reject(revision)
comment = reopened.wolf.add_comment(paragraph, 0, 7, "Review wording", **metadata)
reopened.wolf.reply(comment, "Confirmed", **metadata)
reopened.wolf.resolve_comment(comment)
reopened.save("reviewed.docx")

final = docx.Document("reviewed.docx")
assert final.wolf.resolve(comment)["resolved"]
final.wolf.resolve(run).bold = True
final.wolf.resolve(table).cell(0, 0).text = "Address reused"
assert final.wolf.identify(final.wolf.resolve(paragraph)) == paragraph
final.save("reviewed.docx")
API Contract
identify(object) / resolve(identifier) Persist and reuse identities for alias paragraphs, runs, tables, and listed comments, including after save/reopen. Refuse foreign/stale proxies, absent IDs, and ambiguous IDs.
track(paragraph_id, start, end, text, author=..., date=...) Native tracked replacement in a main-story paragraph (including table cells); a zero-width range inserts, empty replacement text deletes. Return current revision records.
revisions() / accept(record) / reject(record) List native main-story revisions and eligibility; decide exactly one discovered revision. Refuse stale or unsupported records through native review validation.
add_comment(paragraph_id, start, end, text, author=..., date=..., initials=None) Anchor a new comment to a character range; return its comment:N address.
comments() / reply(comment_id, text, author=..., date=..., initials=None) List comment records and anchors, parent IDs, and resolution state; return the address of a new reply.
resolve_comment(comment_id, resolved=True) Resolve the native thread; pass False to reopen it.

Offsets are zero-based native visible-text character offsets, with an exclusive end. Supply a timezone-bearing ISO timestamp. Unsupported native contexts are refused with NodeEditError; no formatting or annotation fallback is substituted. Paragraph text and runs retain python-docx semantics: text inside tracked wrappers is excluded until the review decision makes it direct paragraph content.

Review/comment mutations replace the in-memory snapshot. Re-resolve identifiers afterwards; old proxies are stale. Identifiers on paragraphs, runs, and tables are stored as ignorable namespaced XML attributes only when requested, not inferred from ordinal positions or text. If a range operation splits an addressed run, retain the identity on its first surviving fragment. An entirely removed object has no live address. Comment IDs come from native package comment identities. The preservation contract applies to this alias, not arbitrary third-party tools that discard unknown XML attributes or renumber comments.

Focused agent workflow tests exercise insertion/deletion accept and reject, anchored reply/resolve threads, and reuse of all four address types after save/reopen, with unrelated content and opaque members unchanged. These extension tests are separate from the pinned upstream-suite coverage.

Speed

This package makes no speed claim and runs no speed benchmarks. Retained checkpoint-1 native timings remain historical.

Metadata

Release files for wolfdocx-docx 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wolfdocx-docx 0.1.0
File Size Uploaded Provenance Actions
wolfdocx_docx-0.1.0.tar.gz 22.2 kB With provenance Details for wolfdocx_docx-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wolfdocx-docx 0.1.0
File Interpreter ABI Platform Actions
wolfdocx_docx-0.1.0-py3-none-any.whl Python 3 none any Details for wolfdocx_docx-0.1.0-py3-none-any.whl

Total release size: 49.4 kB

Release files / wolfdocx_docx-0.1.0.tar.gz

Download URL wolfdocx_docx-0.1.0.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8944448859e7f1c8662698141ca77457f6a300bb43eed64563fda78d1f8ac2db
BLAKE2b-256 checksum
How to use checksums
78ab8ffd21e9b3e3765512eb3da969638b4995d8ad78fb2491f563e2dbc9c3b9
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 Nov 19, 2026.

Transparency log

Release files / wolfdocx_docx-0.1.0-py3-none-any.whl

Download URL wolfdocx_docx-0.1.0-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce6d751687ee0f8219276848d5b5e437cb81627056a2c26007837ae346e16f8f
BLAKE2b-256 checksum
How to use checksums
af1f93c167905a0bab8c7970201e3f0b2411f069282221b7d49246f988a0db29
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 Nov 19, 2026.

Transparency log

Security for wolfdocx-docx 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.

Select from 2 files

Attestation for wolfdocx_docx-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 Nov 19, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page