Skip to main content

docxlite

docxlite is a small layer on top of python-docx for reading, previewing, searching, and editing Word documents from Python. It gives .docx files a notebook-friendly markdown preview, adds simple markdown insertion, and supports tracked insertions and deletions with author attribution.

It is designed for document automation workflows where an agent or notebook needs to make precise edits to Word files without losing the structure that matters: paragraphs, tables, runs, formatting, and revision metadata.

Installation

Install latest from pypi

$ pip install docxlite

How to use

from docxlite import *

Create or open a Word document using DocxDocument. In a notebook or solveit dialog, the document renders as markdown so you can inspect its contents without downloading and opening Word.

doc = DocxDocument()
p = doc.add_paragraph('Hello from docxlite')
doc

Hello from docxlite

add_md parses a small markdown subset and adds formatted runs to an existing paragraph. It supports bold, italic, bold-italic, and underline.

p = doc.add_paragraph()
p.add_md('This has **bold**, *italic*, and <u>underline</u>.')

This has bold, italic, and underline.

Tables render as markdown tables, and add_row accepts cell values directly. Cell contents can use the same inline markdown formatting as paragraphs.

tbl = doc.add_table(rows=0, cols=3)
tbl.add_row('Name', 'Value', 'Notes')
tbl.add_row('Apples', '42', '**crisp**')
tbl
Name Value Notes
Apples 42 crisp

Documents are iterable in body order. That matters because python-docx exposes doc.paragraphs and doc.tables separately, which loses the interleaving of paragraphs and tables in the original file.

for block in doc:
    print(type(block).__name__, block._text[:40] if hasattr(block, '_text') else '')
Paragraph Hello from docxlite
Paragraph This has bold, italic, and underline.
Table Name  Value   Notes
Apples  42  crisp

search returns the matching document blocks themselves, not detached search results. You can search for text, then edit the returned paragraph or table directly.

hits = doc.search('bold')
hits[0]

This has bold, italic, and underline.

Tracked changes

Call set_tracking(author) to make insertions and deletions appear as Word tracked changes. Use set_tracking(None) when you want edits to be applied directly.

set_tracking('AI Editor')
hits[0].insert_after('Inserted with tracking enabled.')
doc

Hello from docxlite

This has bold, italic, and underline.

Inserted with tracking enabled.

Name Value Notes
Apples 42 crisp

Deleting with tracking enabled marks content as deleted instead of removing it. Deleted text appears in the markdown preview using revision spans, and Word will show it as a tracked deletion.

doc.search('Hello')[0].delete()
doc

Hello from docxlite

This has bold, italic, and underline.

Inserted with tracking enabled.

Name Value Notes
Apples 42 crisp

LLM Integration

docxlite ships with a pyskills integration for LLM agents. Importing docxlite.skill exposes the document classes and editing methods to the tool system, and enables tracked changes with set_tracking('AI Editor') by default so agent edits are reviewable in Word.

from docxlite.skill import *

The skill uses the same API as regular docxlite; the difference is that the relevant classes and methods are registered for safe tool access. That lets an LLM search, preview, insert, delete, and save .docx files while preserving revision metadata.

skill_doc = DocxDocument()
skill_doc.add_paragraph('Inserted through the docxlite pyskill')
skill_doc

Saving

Save the edited document with the normal python-docx API.

doc.save('example.docx')

Release files for docxlite 0.0.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 docxlite 0.0.1
File Size Uploaded
docxlite-0.0.1.tar.gz 15.6 kB Details

Built distribution (wheel)

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

Total release size: 30.9 kB

Release files / docxlite-0.0.1.tar.gz

Download URL docxlite-0.0.1.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4964b3f6f028b888d04dc4265ae12c6ff3d9f51d53adb20f3d1c59de8b3eba8a
BLAKE2b-256 checksum
How to use checksums
fe1395f2087858b9f84459fdbd8335f3ae72de1762007ccce3d86f7b6214d2a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / docxlite-0.0.1-py3-none-any.whl

Download URL docxlite-0.0.1-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
072e3ecf763250d13f12459de0681a75cb6a75d75fbda5942b5fb45487745f60
BLAKE2b-256 checksum
How to use checksums
23f6b15360714ffe29a0f25cf53126301e05734cb4d4ad7439cbf9984a6914b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release 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