This release is a pre-release and may not be stable for production use.
python-docx-ng
python-docx-ng is a Python library for reading, creating, and updating Microsoft Word 2007+ (.docx) files.
It is a downstream superset of python-docx by scanny: everything upstream does, plus features upstream has not adopted. As of 2.0.0 this project tracks upstream v1.2.0 directly, so it builds on upstream's typed and tested core rather than a 2021 snapshot of it.
- Documentation: https://toxicphreak.github.io/python-docx-ng/
- Repo: https://github.com/toxicphreAK/python-docx-ng
- Releases: https://github.com/toxicphreAK/python-docx-ng/releases
- PyPI: https://pypi.org/project/python-docx-ng/
Installation
pip install python-docx-ng
Note: the importable package is
docx, notpython_docx_ng— useimport docx.python-docx-ngandpython-docxtherefore cannot be installed side by side.
Example
>>> from docx import Document
>>> document = Document()
>>> document.add_paragraph("It was a dark and stormy night.")
<docx.text.paragraph.Paragraph object at 0x10f19e760>
>>> document.save("dark-and-stormy.docx")
>>> document = Document("dark-and-stormy.docx")
>>> document.paragraphs[0].text
'It was a dark and stormy night.'
Documentation
https://toxicphreak.github.io/python-docx-ng/
- User guide — documents, text, tables, sections, styles
- How-to pages — the features listed below, each with worked examples
- API reference — every module, generated from the source
- Migrating from 0.9.x
The upstream python-docx documentation also covers the shared core.
For language models
The site publishes llms.txt and llms-full.txt. Any tool that reads the format can consume them — for example mcpdoc, which serves them to an editor over MCP:
uvx --from mcpdoc mcpdoc --urls python-docx-ng:https://toxicphreak.github.io/python-docx-ng/llms.txt
What this adds over python-docx
Everything upstream v1.2.0 does, plus:
Editing and review
- Tracked changes — read revisions, and accept or reject them individually or in bulk
- Comments, footnotes, and cross-run search and replace that survives Word's run splitting
- A deletion API —
.delete()on paragraphs, runs, tables, rows and columns
Content people ask for
- Fields and a table of contents —
Paragraph.add_field(), with builders for PAGE, TOC, REF, SEQ and the rest - List numbering — read a paragraph's number, apply a list, restart it
- Bookmarks,
Paragraph.add_hyperlink(), and captions via SEQ - Watermarks, text and image, written into the header where Word expects them
- Floating (anchored) images with text wrapping, alongside inline ones
- Legacy form fields — read and fill text inputs, check boxes and drop-downs
- AltChunk — embed HTML, RTF or another
.docxfor Word to import on open
Formatting
- Table and cell borders —
Table.borders["top"].line = WD_LINE_STYLE.SINGLE - Paragraph and run shading, including the pattern and its colour
- Multi-column section layout, and row
dont_split - Outline level — drives the outline shown in navigation panes and PDF bookmarks
- Font scaling, theme typefaces, East Asian and complex-script typefaces
- Copying a style between documents, with its
basedOn/next/linkclosure and numbering
Files and formats
.docm(macro-enabled) and.dotx/.dotm(template) support- SVG, EMF, WMF and WebP image support
- Custom and extended document properties (
docProps/custom.xml,docProps/app.xml) - Reproducible documents — the same input produces byte-identical output
- Accepts
pathlib.Pathanywhere a path is taken
Accessibility
- Alt text on pictures, inline shapes and tables
Robustness
- Tolerates oversized attribute values the default
lxmlparser rejects - Corrupt, truncated and password-protected files raise something that says which
- Custom namespaces in
xpath()calls
Some things are deliberately not here yet — reading ISO Strict documents, endnotes, equations, embedded OLE objects and charts among them. See the issue tracker for what is planned, and HISTORY.rst for the full changelog.
Upgrading from 0.9.x
2.0.0 rebases onto upstream v1.2.0 and contains breaking changes. Several 0.9.x additions were dropped in favour of upstream implementations of the same features, which are better tested and differently shaped — notably comments, hyperlinks, and table cell access. Read the migration guide before upgrading.
Development
Requires uv.
uv sync # create the environment
uv run pytest # unit tests
make accept # acceptance tests (behave)
uv run pyright # type check
uv run ruff check . # lint
License
MIT — see LICENSE. Originally developed by Steve Canny as python-docx.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_docx_ng-2.0.0rc1.tar.gz.
File metadata
- Download URL: python_docx_ng-2.0.0rc1.tar.gz
- Upload date:
- Size: 6.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
800dd48f4b8983b5cd05a8955feab82f83c47c75651463122f353d5c3872d516
|
|
| MD5 |
3c571b4b832baef0d52e414b429f14d6
|
|
| BLAKE2b-256 |
577b420890a1f3f0865e12999f15975f2ddb579600ef4e5337f0e724615e4279
|
Provenance
The following attestation bundles were made for python_docx_ng-2.0.0rc1.tar.gz:
Publisher:
python-publish.yml on toxicphreAK/python-docx-ng
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_docx_ng-2.0.0rc1.tar.gz -
Subject digest:
800dd48f4b8983b5cd05a8955feab82f83c47c75651463122f353d5c3872d516 - Sigstore transparency entry: 2343023149
- Sigstore integration time:
-
Permalink:
toxicphreAK/python-docx-ng@4fcf5dd53ededda61d75f2fe493ecbd83ac8cacd -
Branch / Tag:
refs/tags/v2.0.0rc1 - Owner: https://github.com/toxicphreAK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4fcf5dd53ededda61d75f2fe493ecbd83ac8cacd -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_docx_ng-2.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: python_docx_ng-2.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 350.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91a5e9c82a8b13511472a761d16a0297defd9014400f02c3eb39140fd38c553e
|
|
| MD5 |
e90d5b8806c66003dcd9ccd709f3f217
|
|
| BLAKE2b-256 |
0afce015ef277a02b88003ac2451fdcaa7be59b170b6bc85db26dc9794ce187b
|
Provenance
The following attestation bundles were made for python_docx_ng-2.0.0rc1-py3-none-any.whl:
Publisher:
python-publish.yml on toxicphreAK/python-docx-ng
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_docx_ng-2.0.0rc1-py3-none-any.whl -
Subject digest:
91a5e9c82a8b13511472a761d16a0297defd9014400f02c3eb39140fd38c553e - Sigstore transparency entry: 2343023153
- Sigstore integration time:
-
Permalink:
toxicphreAK/python-docx-ng@4fcf5dd53ededda61d75f2fe493ecbd83ac8cacd -
Branch / Tag:
refs/tags/v2.0.0rc1 - Owner: https://github.com/toxicphreAK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4fcf5dd53ededda61d75f2fe493ecbd83ac8cacd -
Trigger Event:
push
-
Statement type: