Skip to main content

No project description provided

Project description

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')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docxlite-0.0.1.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

docxlite-0.0.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file docxlite-0.0.1.tar.gz.

File metadata

  • Download URL: docxlite-0.0.1.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for docxlite-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4964b3f6f028b888d04dc4265ae12c6ff3d9f51d53adb20f3d1c59de8b3eba8a
MD5 68d8ae4ff96cd96851e2b74d007768c4
BLAKE2b-256 fe1395f2087858b9f84459fdbd8335f3ae72de1762007ccce3d86f7b6214d2a6

See more details on using hashes here.

File details

Details for the file docxlite-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: docxlite-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for docxlite-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 072e3ecf763250d13f12459de0681a75cb6a75d75fbda5942b5fb45487745f60
MD5 7e57fb89194a1e018fc0dc6efae4633f
BLAKE2b-256 23f6b15360714ffe29a0f25cf53126301e05734cb4d4ad7439cbf9984a6914b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page