Skip to main content

PyPI Downloads PyPI version

docxedit

Edit Word documents effortlessly without changing the original formatting.

The original docx library is great but it's missing one important feature: keeping the original formatting.

This is useful if you want to automate document writing or editing and need to adhere to strict formatting rules — a common requirement in professional settings.

Install

pip install docxedit

Dependencies

Included as a dependency: python-docx (docx)

Functionalities

Most of the functions in this module work primarily with runs, which are sequences of strings with the same formatting style. Breaking the document into runs allows us to edit the text without changing the original formatting.

  • Replace all occurrences of a string with a new string (optionally limit up to a paragraph number, and include or exclude tables)
  • Remove a paragraph or a line (and optionally a number of lines after it)
  • Add text to a table cell
  • Change the font size of a table
  • Show the line where a specific string is found

How to Use

from docx import Document
import docxedit

document = Document('path/to/your/document.docx')

# Replace all instances of 'Hello' with 'Goodbye' (including tables)
docxedit.replace_string(document, old_string='Hello', new_string='Goodbye')

# Replace all instances of 'Hello' with 'Goodbye' but only up to paragraph 10
docxedit.replace_string_up_to_paragraph(document, old_string='Hello', new_string='Goodbye',
                                        paragraph_number=10)

# Show the line where 'Hello' is found
docxedit.show_line(document, current_text='Hello')

# Remove any line that contains 'Hello' along with the next 5 lines after that
docxedit.remove_lines(document, first_line='Hello', number_of_lines=5)

# Remove a specific paragraph
docxedit.remove_paragraph(document.paragraphs[0])

# Add text in a table cell (row 1, column 1) in the first table
docxedit.add_text_in_table(document.tables[0], row_num=1, column_num=1, new_string='Hello')

# Change font size of the first table to 12pt
docxedit.change_table_font_size(document.tables[0], font_size=12)

# Save the document
document.save('path/to/your/edited/document.docx')

Logging

By default, docxedit does not produce any console output. To enable debug logging:

import logging
logging.basicConfig(level=logging.DEBUG)

Metadata

Release files for docxedit 1.2.1

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

Source distribution (sdist)

Source distribution for docxedit 1.2.1
File Size Uploaded
docxedit-1.2.1.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docxedit 1.2.1
File Interpreter ABI Platform
docxedit-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / docxedit-1.2.1.tar.gz

Download URL docxedit-1.2.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
804f86ec9f14c4494576bb7877470e4128147e1b90c2c552a42d3fcd962a4b31
BLAKE2b-256 checksum
How to use checksums
0382ace4bba63e1bb5ce3fa832055c3dd2cf8d1b9e886c21fdf3a931c8d531df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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

Transparency log

Release files / docxedit-1.2.1-py3-none-any.whl

Download URL docxedit-1.2.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32fe054c89918bb5b7dbfef01c8cf71e29c3e11f8234cd0de171929e8a794750
BLAKE2b-256 checksum
How to use checksums
9ba6302efc4e35454d7be679df283ead13d31892e50c550916f8dbcf7c90e394
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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

Transparency log

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.0.4

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.1

1 release file

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