Skip to main content

Raw DOCX

A Python library that extends python-docx to convert Word documents into structured, traversable Python objects with export to dictionary, HTML, and plain text formats.

Installation

pip install raw_docx

Features

  • Document hierarchy - Multi-level section numbering that mirrors Word: only headings Word actually numbers get a number; unnumbered headings (front matter, bullets, "no number" styles) are kept as sections without one
  • Rich text - Colors, highlighting, bold, italic, superscript, and subscript
  • Tables - Full support for merged cells (row and column spans)
  • Nested lists - Arbitrary nesting depth with level tracking and numId boundary detection
  • Indentation hierarchy - Infers nesting from indentation when all items share the same level
  • Bookmarks and cross-references - Bookmark anchors and field-based references
  • Image extraction - Extracts embedded images with base64 HTML embedding
  • Multiple export formats - Dictionary, HTML, and plain text
  • Search - Find text across sections, tables, and the full document
  • Error tracking - Integrated logging via simple_error_log

Quick Start

from raw_docx import RawDocx

# Load and process a document
docx = RawDocx("path/to/document.docx", work_dir="/tmp/output")

# Disable indentation-based hierarchy inference if needed
# docx = RawDocx("path/to/document.docx", infer_indent_hierarchy=False)

# Access the structured document
document = docx.target_document

# Export to dictionary
data = docx.to_dict()

# Work with sections
section = document.section_by_title("Introduction")
paragraphs = section.paragraphs()
tables = section.tables()
lists = section.lists()

# Search for content
results = section.find("keyword")

# Generate HTML
html = section.to_html()

Key Classes

Class Description
RawDocx Main entry point; loads and processes a .docx file
RawDocument Top-level container managing sections and hierarchy
RawSection A document section/heading with its content
RawParagraph A paragraph containing runs and bookmarks
RawRun A text run with formatting attributes
RawTable / RawTableRow / RawTableCell Table structure with merged cell support
RawList / RawListItem Nested list structure
RawImage Embedded image handling

Requirements

License

MIT - see LICENSE for details.

Build and Release

pytest
ruff format
ruff check
python3 -m build --sdist --wheel
twine upload dist/*

Metadata

Release files for raw-docx 0.15.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 raw-docx 0.15.0
File Size Uploaded Provenance Actions
raw_docx-0.15.0.tar.gz 33.3 kB Without provenance Details for raw_docx-0.15.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for raw-docx 0.15.0
File Interpreter ABI Platform Actions
raw_docx-0.15.0-py3-none-any.whl Python 3 none any Details for raw_docx-0.15.0-py3-none-any.whl

Total release size: 71.0 kB

Release files / raw_docx-0.15.0.tar.gz

Download URL raw_docx-0.15.0.tar.gz
Size 33.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8695d787e01a5793519320fcbfaa2459e8aa6d10a8a79c50f8ae6d3811e2d0d7
BLAKE2b-256 checksum
How to use checksums
aa2212afba339f80acf1adb9f5f9411b0bdf0e9453bb038dfb8d07c00a14b718
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / raw_docx-0.15.0-py3-none-any.whl

Download URL raw_docx-0.15.0-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ef4f89148c52dde374d5753c40a76957329007987e5685c86d7da8d4440b4fb
BLAKE2b-256 checksum
How to use checksums
98fcf6dcb03759cc29c3233e3acb00e72b18fe16ac3c0233acf600b389be70b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for raw-docx 0.15.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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