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.16.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.16.0
File Size Uploaded Provenance Actions
raw_docx-0.16.0.tar.gz 43.2 kB Without provenance Details for raw_docx-0.16.0.tar.gz

Built distribution (wheel)

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

Total release size: 91.3 kB

Release files / raw_docx-0.16.0.tar.gz

Download URL raw_docx-0.16.0.tar.gz
Size 43.2 kB
Tags Source
SHA-256 checksum
How to use checksums
be117e308c2325c32adb0412f7d30b33f8af60a95c3fad516f844f7b4ac5720b
BLAKE2b-256 checksum
How to use checksums
d64daf14230a6281795e15f4916abf870daad42b0d375fad1882993f8a523c07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

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

Download URL raw_docx-0.16.0-py3-none-any.whl
Size 48.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6de3104c7bfed414b58e625eca924e4c8d501220723001719aae9cad4d3e8d1c
BLAKE2b-256 checksum
How to use checksums
fa0c3269b13ad0b7f6198ab0aa80ad5b4b2f3192e76274a24aaab54178d95ff6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

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