Skip to main content

rdocx-py

Native rdocx for Python

rdocx gives Python applications a native DOCX workflow for creating, opening, editing, comparing, laying out, and rendering Word documents. It works directly with OOXML packages and does not require Microsoft Word, LibreOffice, a conversion service, or a Java or .NET runtime.

The package runs the Rust rdocx document engine locally, presents a typed Python API, and needs no remote service for editing, layout, or rendering. Review workflows cover comments, tracked revisions, comparison, and table of contents rebuilding. Complete package saves preserve safe producer XML and parts that the focused Python surface does not model.

Installation

Install the current release from PyPI:

python -m pip install rdocx

rdocx requires CPython 3.9 or newer. Its platform wheels use the Python 3.9 stable ABI, so one wheel supports multiple compatible Python versions. Source installation requires a Rust toolchain and maturin.

Quick start

from rdocx import Document

doc = Document()
doc.add_paragraph("Hello from Python")
doc.save("hello.docx")

pdf = doc.to_pdf()
with open("report.pdf", "wb") as output:
    output.write(pdf)

Capabilities

  • File and byte-based DOCX input and output.
  • Paragraphs, runs, fonts, tables, rows, cells, sections, and styles.
  • Rich per-section headers and footers, related stories, and hyperlinks resolved, retargeted, or removed in any story.
  • Paragraph text replacement that keeps paragraph formatting, comments, and bookmarks.
  • Counted literal replacement with Paragraph.replace_text, Cell.replace_text and Document.replace_text_at, scoped to the selected owner and preserving run formatting. expect checks the local count before publishing any edit.
  • Paragraph style assignment by style ID or name, checked against the styles the document defines.
  • New documents with Word's usual styles, such as Heading 2, Title, List Paragraph, Caption, and Table Grid.
  • Style creation with a font, spacing, and indentation through Document.add_style, checked updates through Document.set_style, plus style removal and default selection.
  • Numbering definitions and instances built from ListLevel values, and paragraph styles linked to a numbering level.
  • Core document properties such as title, author, and revision, read and written through Document.core_properties under python-docx's names.
  • Picture replacement and resizing by image relationship.
  • Complete paragraph and run formatting, multilingual and vertical typography, conditional and floating tables, section semantics, settings, fields, forms, equations, drawings, comments, and metadata.
  • Tracked comparison, main-body comment threads, bookmarks, revision resolution, and TOC insertion and rebuilding.
  • Deterministic layout fragments, page geometry, and PDF, PDF/A, SVG, PNG, JPEG, and TIFF output through the native document engine, with caller fonts or a font directory for PDF. PDF and raster methods accept keyword-only revision_view="tracked" to show tracked changes.
  • Python collections with negative indexes, slices, iteration, and explicit stale-handle errors after structural changes.

Measured footprint and speed

Measurement Value Version Platform Build mode Input Command Statistic Measured on
Large-document layout throughput minimum 250 pages/s, observed 31,019.1 pages/s rdocx 0.14.0 macOS 26.6.2, Apple M5 Max, arm64 release, one test thread 1,000 one-page paragraphs with deterministic fonts cargo test -p rdocx --test regression_test --release a_thousand_page_document_paginates_and_renders_within_the_declared_limits -- --ignored --exact --nocapture --test-threads=1 pages per wall-clock second 2026-09-19
Large-document layout peak allocation maximum 64 MiB, observed 29.03 MiB rdocx 0.14.0 macOS 26.6.2, Apple M5 Max, arm64 release, one test thread 1,000 one-page paragraphs with deterministic fonts cargo test -p rdocx --test regression_test --release a_thousand_page_document_paginates_and_renders_within_the_declared_limits -- --ignored --exact --nocapture --test-threads=1 peak live allocation 2026-09-19
Large-document PDF throughput minimum 1,000 pages/s, observed 60,058.0 pages/s rdocx 0.14.0 macOS 26.6.2, Apple M5 Max, arm64 release, one test thread 1,000 deterministic layout pages cargo test -p rdocx --test regression_test --release a_thousand_page_document_paginates_and_renders_within_the_declared_limits -- --ignored --exact --nocapture --test-threads=1 pages per wall-clock second 2026-09-19
Large-document PDF peak allocation maximum 16 MiB, observed 1.73 MiB rdocx 0.14.0 macOS 26.6.2, Apple M5 Max, arm64 release, one test thread 1,000 deterministic layout pages cargo test -p rdocx --test regression_test --release a_thousand_page_document_paginates_and_renders_within_the_declared_limits -- --ignored --exact --nocapture --test-threads=1 peak live allocation 2026-09-19

Use it when

Use rdocx when a Python service, desktop application, or automation task needs to work with Word documents locally. It is suited to template updates, document assembly, review workflows, comparison, and deterministic output.

Relationship

The Python API is intentionally focused. It is source compatible with the documented rdocx surface, but it is not a drop-in replacement for every python-docx method or private lxml object.

Example

Open and update an existing document:

from rdocx import Document

document = Document("template.docx")
document.add_paragraph("Approved")
document.save("approved.docx")

Package XML escape hatch

For an unmodelled package part, edit the DOCX ZIP with lxml, then reopen it with rdocx. Keep the original ZIP members and update package relationships and content types if an edit adds or removes a part. For example, to change an existing application property:

from io import BytesIO
from zipfile import ZipFile
from lxml import etree
from rdocx import Document

source = Document("report.docx").to_bytes()
output = BytesIO()
with ZipFile(BytesIO(source)) as original, ZipFile(output, "w") as edited:
    for member in original.infolist():
        data = original.read(member.filename)
        if member.filename == "docProps/app.xml":
            root = etree.fromstring(data)
            ns = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
            root.find(f"{{{ns}}}Application").text = "Report service"
            data = etree.tostring(root, xml_declaration=True, encoding="UTF-8")
        edited.writestr(member, data)
document = Document.from_bytes(output.getvalue())
document.save("report-edited.docx")

The typed API handles style formatting, comments, fields, relationships and other modeled operations. set_style keeps properties not supplied in the call and cannot clear an existing theme font or theme colour.

Type checking

The distribution includes hand-written extension stubs and a py.typed marker. Editors and type checkers can inspect concrete document, paragraph, run, table, section, story, comment, comparison, and layout types.

python -m pip install mypy
python -m mypy your_application.py

The release gate validates the installed package with strict mypy and stubtest in addition to its runtime suite.

Document.set_header(text) and Document.set_footer(text) replace a complete story through one checked transaction. Removing a complete owned comment thread cleans its definitions and companion metadata. Partial ranges or malformed ownership raise RdocxError and preserve the document and live handles. Successful replacement invalidates earlier handles once.

License

Licensed under either the MIT License or the Apache License 2.0, at your option.

Metadata

Release files for rdocx 0.16.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 rdocx 0.16.0
File Size Uploaded Provenance Actions
rdocx-0.16.0.tar.gz 10.6 MB With provenance Details for rdocx-0.16.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for rdocx 0.16.0
File Actions
rdocx-0.16.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for rdocx-0.16.0-cp39-abi3-win_amd64.whl
rdocx-0.16.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for rdocx-0.16.0-cp39-abi3-musllinux_1_2_x86_64.whl
rdocx-0.16.0-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details for rdocx-0.16.0-cp39-abi3-manylinux_2_28_x86_64.whl
rdocx-0.16.0-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for rdocx-0.16.0-cp39-abi3-manylinux_2_28_aarch64.whl
rdocx-0.16.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for rdocx-0.16.0-cp39-abi3-macosx_11_0_arm64.whl
rdocx-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for rdocx-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 96.3 MB

Release files / rdocx-0.16.0.tar.gz

Download URL rdocx-0.16.0.tar.gz
Size 10.6 MB
Tags Source
SHA-256 checksum
How to use checksums
699c4fb1fa9b8f056faf539e41e293363ae83efb2ba53ed106217e937e2a01ad
BLAKE2b-256 checksum
How to use checksums
87259bb5b7b4c89f2960f1f3d3a117811242eb76cae1cdba46698b8865ac27d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 9, 2026.

Transparency log

Release files / rdocx-0.16.0-cp39-abi3-win_amd64.whl

Download URL rdocx-0.16.0-cp39-abi3-win_amd64.whl
Size 14.7 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4b74ea6895989ca5c954c5e496a1a498009191ed68cd2cc729a696779a43dc3f
BLAKE2b-256 checksum
How to use checksums
1307c20ddf448c5be24ab0afc3095b624d27f86349304657ede0df32f5a22193
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 9, 2026.

Transparency log

Release files / rdocx-0.16.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL rdocx-0.16.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 14.7 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
b247a97d215981060783ebad1102e5f037b514781b3be35eb40416bd75e3f578
BLAKE2b-256 checksum
How to use checksums
c37a670e2033ace3e86097ebbeccc3431bbe98e3180cd20b21cd422a7bc8807e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 9, 2026.

Transparency log

Release files / rdocx-0.16.0-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL rdocx-0.16.0-cp39-abi3-manylinux_2_28_x86_64.whl
Size 14.5 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
5b7c6793577b40d92ead21755bf4e807a44f9760c74a844c915873b2e33afe04
BLAKE2b-256 checksum
How to use checksums
a15d1c980dda4be4e855613ffd55ecaedd86f0ea89eda11a2d10dfec975169ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 9, 2026.

Transparency log

Release files / rdocx-0.16.0-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL rdocx-0.16.0-cp39-abi3-manylinux_2_28_aarch64.whl
Size 13.9 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
9c57cc02ed64df8f2047c5e7cd3088e68ef5ccc3372f7876d27530aa84eeeecc
BLAKE2b-256 checksum
How to use checksums
9ed6b48a55b8ed940c18796eddf9ca2f3e9ff94e3557c5d08f7a08b2353998d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 9, 2026.

Transparency log

Release files / rdocx-0.16.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL rdocx-0.16.0-cp39-abi3-macosx_11_0_arm64.whl
Size 13.8 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b226e651a6fc2d673f2c9945bcc99dc3971990c5bb3f34f70eeb7d9132b0fefb
BLAKE2b-256 checksum
How to use checksums
30d3fa237757fbad9b3983580b9bfaf871f922b48ae65cdea5ba28ef78020a12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 9, 2026.

Transparency log

Release files / rdocx-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL rdocx-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 14.2 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e20454fc11bed9971a3e45e37e6bfc5ed9f669e8fc8a6dcae7653bfd90e1c5a0
BLAKE2b-256 checksum
How to use checksums
a5a5a9f38de4debef0e6e94451d6b6337a865bc554932036c09aafcd19d4643f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 9, 2026.

Transparency log

Security for rdocx 0.16.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

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for rdocx-0.16.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 9, 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.

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