Skip to main content
Pre-release

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, not python_docx_ng — use import docx. python-docx-ng and python-docx therefore 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.footnotes and Run.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 .docx for 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 lxml parser 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

python_docx_ng-2.0.0.dev0.tar.gz (6.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_docx_ng-2.0.0.dev0-py3-none-any.whl (383.4 kB view details)

Uploaded Python 3

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

Hashes for python_docx_ng-2.0.0.dev0.tar.gz
Algorithm Hash digest
SHA256 b2f8bcc2f4eaa6d718fc053ed46badb2ec895885695182c406552009eeb840dd
MD5 449ab81c2f107d0c0876e751f719d6fa
BLAKE2b-256 57b2d88bab62043bbd63dde7a3044f2e97ad7abea6e3585b89d8b9996bb0450e

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_docx_ng-2.0.0.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_docx_ng-2.0.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 896aaa986a9b91472f8346e1e89a26049b5c6ab10507066d71ed9d87545e9621
MD5 9bffcde89f29195fd1be7e1b61efa50e
BLAKE2b-256 0c654ce5e87bc540453cd1df04143cfb3d3f495619bb0b47485b8f5615396ec3

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

2.1.0

2 files

2.0.0

2 files

This release

2.0.0.dev0 This release

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

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