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.
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.'
The python-docx documentation covers the shared core. Additions specific to this project are documented in docs.
What this adds over python-docx
Being ported onto the v1.2.0 base — see HISTORY.rst for current status and the 2.0.0 milestone for what is still to come.
- Footnotes —
Document.footnotesandRun.add_footnote_reference() - Legacy form fields — read and fill text inputs, check boxes and drop-downs
- Table and cell borders —
Table.borders["top"].line = WD_LINE_STYLE.SINGLE - AltChunk — embed HTML, RTF or another
.docxfor Word to import on open - Custom and extended document properties (
docProps/custom.xml,docProps/app.xml) - Bookmarks,
Paragraph.add_hyperlink(), and a deletion API .docm(macro-enabled) and.dotx/.dotm(template) support- SVG, EMF, WMF and WebP image support
- Outline level — drives the outline shown in navigation panes and PDF bookmarks
- Font scaling, theme typefaces, East Asian and complex-script typefaces
- Paragraph and run shading
- Multi-column section layout, and row
dont_split - Reproducible documents — the same input produces byte-identical output
- Custom namespaces in
xpath()calls - Tolerates oversized attribute values the default
lxmlparser rejects
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.0.dev0.tar.gz.
File metadata
- Download URL: python_docx_ng-2.0.0.dev0.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 |
b2f8bcc2f4eaa6d718fc053ed46badb2ec895885695182c406552009eeb840dd
|
|
| MD5 |
449ab81c2f107d0c0876e751f719d6fa
|
|
| BLAKE2b-256 |
57b2d88bab62043bbd63dde7a3044f2e97ad7abea6e3585b89d8b9996bb0450e
|
Provenance
The following attestation bundles were made for python_docx_ng-2.0.0.dev0.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.0.dev0.tar.gz -
Subject digest:
b2f8bcc2f4eaa6d718fc053ed46badb2ec895885695182c406552009eeb840dd - Sigstore transparency entry: 2339282785
- Sigstore integration time:
-
Permalink:
toxicphreAK/python-docx-ng@b2a83839381240ffddba9405192f289b6df62af6 -
Branch / Tag:
refs/tags/v2.0.0.dev0 - Owner: https://github.com/toxicphreAK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b2a83839381240ffddba9405192f289b6df62af6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_docx_ng-2.0.0.dev0-py3-none-any.whl.
File metadata
- Download URL: python_docx_ng-2.0.0.dev0-py3-none-any.whl
- Upload date:
- Size: 383.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 |
896aaa986a9b91472f8346e1e89a26049b5c6ab10507066d71ed9d87545e9621
|
|
| MD5 |
9bffcde89f29195fd1be7e1b61efa50e
|
|
| BLAKE2b-256 |
0c654ce5e87bc540453cd1df04143cfb3d3f495619bb0b47485b8f5615396ec3
|
Provenance
The following attestation bundles were made for python_docx_ng-2.0.0.dev0-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.0.dev0-py3-none-any.whl -
Subject digest:
896aaa986a9b91472f8346e1e89a26049b5c6ab10507066d71ed9d87545e9621 - Sigstore transparency entry: 2339282792
- Sigstore integration time:
-
Permalink:
toxicphreAK/python-docx-ng@b2a83839381240ffddba9405192f289b6df62af6 -
Branch / Tag:
refs/tags/v2.0.0.dev0 - Owner: https://github.com/toxicphreAK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b2a83839381240ffddba9405192f289b6df62af6 -
Trigger Event:
push
-
Statement type: