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 for paragraphs and table cells, 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, alignment, merged cells, and revision metadata.
Install latest from pypi
$ pip install docxlitefrom 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')
docHello from docxlite
add_md parses a small markdown subset and adds formatted runs.
DocxDocument.add_paragraph() uses the same markdown path, so you can
create formatted paragraphs directly. It supports bold, italic,
bold-italic, and underline.
p = doc.add_paragraph('This has **bold**, *italic*, and <u>underline</u>.')
pThis has bold, italic, and underline.
Tables render as markdown tables. add_row accepts cell values
directly, and table cells support add_md too. If you pass fewer values
than the table has columns, the last provided value is merged across the
remaining cells.
tbl = doc.add_table(rows=0, cols=3)
tbl.add_row('Name', 'Value', 'Notes')
tbl.add_row('Apples', '42', '**crisp**')
tbl.add_row('Merged footer')
tbl| Name | Value | Notes |
|---|---|---|
| Apples | 42 | crisp |
| Merged footer |
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])Paragraph Hello from docxlite
Paragraph This has bold, italic, and underline.
Table Name Value Notes
Apples 42 crisp
Merged
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.
apply_base copies paragraph-level formatting and base run defaults
from an existing paragraph. Use markdown for explicit emphasis such as
bold, italic, and underline; use apply_base when you want a new
paragraph to inherit local Word formatting.
base = doc.search('This has')[0]
new_heading = doc.add_paragraph('<u>**A formatted heading**</u>')
new_heading.apply_base(base)A formatted heading
docxlite.skill also exports the common python-docx alignment enums,
so agents can set paragraph, cell, and table alignment without reaching
through undocumented constants.
new_heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
new_headingA formatted heading
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. The LLM skill defaults to Docxlite as the
tracked-change author.
set_tracking('Docxlite')
hits[0].insert_after('Inserted with tracking enabled.')
docHello from docxlite
This has bold, italic, and underline.
Inserted with tracking enabled.
| Name | Value | Notes |
|---|---|---|
| Apples | 42 | crisp |
| Merged footer |
A formatted heading
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()
docHello from docxlite
This has bold, italic, and underline.
Inserted with tracking enabled.
| Name | Value | Notes |
|---|---|---|
| Apples | 42 | crisp |
| Merged footer |
A formatted heading
docxlite ships with a pyskills integration for LLM agents. Importing
docxlite.skill exposes the document classes, common Word alignment
enums, and editing methods to the tool system. It also enables tracked
changes with set_tracking('Docxlite') 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, align, merge,
and save .docx files while preserving revision metadata.
skill_doc = DocxDocument()
skill_doc.add_paragraph('Inserted through the docxlite pyskill')
skill_docInserted through the docxlite pyskill
Save the edited document with the normal python-docx API.
doc.save('example.docx')