Skip to main content

Recursive DOCX extractor with embedded files support

Project description

DOCX Extractor

PyPI version Python 3.8+ License: MIT

Recursive DOCX extractor that handles embedded files (Excel, Word, SQL/TXT) with compact TOON output format.

Extracts:

  • ✅ DOCX paragraphs & tables (with full cell data)
  • ✅ Embedded Excel sheets (all rows/columns)
  • ✅ Nested DOCX (recursive up to 5 levels)
  • ✅ SQL/TXT files
  • ✅ Filters empty content

🚀 Quick Start

Install

pip install docx-extractor

Extract DOCX to TOON format

docx-extract input.docx -o output.toon

With options

docx-extract input.docx -o result.toon --depth 3 -v

📄 Sample TOON Output

FILE input.docx .docx L0 PARA 1 Project Summary Report TABLE 1 3rows x 4cols ROW T1.R1 Project|Q1|Q2|Q3|Total ROW T1.R2 ProjectA|100|150|200|450 ROW T1.R3 ProjectB|80|120|180|380 EMBEDDED 1 FILE sheet1.xlsx .xlsx L1 SHEET Sales 15rows ROW Sales.1 Product|Units|Price|Total ROW Sales.2 WidgetA|100|25.50|2550.00

🛠️ Installation

From PyPI

pip install docx-extractor

From Source

git clone https://github.com/yourusername/docx-extractor.git cd docx-extractor pip install -e .

🎯 Usage

docx-extract [OPTIONS] <docx_file>

Options:

-o, --output Output TOON file (default: extraction.toon) -d, --depth Max recursion depth (default: 5) -v, --verbose Show preview -h, --help Show help

🏗️ Package Structure

docx_extractor/ ├── core.py # Main extraction logic ├── processors.py # Excel/TXT handlers ├── toon_formatter.py # TOON output formatter └── init.py

🔧 Programmatic Usage

from docx_extractor import extract_docx_recursive from docx_extractor.toon_formatter import format_toon

Extract

result = extract_docx_recursive("input.docx", max_depth=3)

TOON format

toon_lines = format_toon(result)

Save

with open("output.toon", "w") as f: f.write("\n".join(toon_lines))

📊 TOON Format Specification

Tab-separated, hierarchical, token-efficient:

TYPE IDENTIFIER DATA FILE filename.docx .docx L0 PARA 1 Document title TABLE 1 3rows x 4cols ROW T1.R1 Project|Q1|Q2|Total SHEET Sales 15rows ROW Sales.1 Product|100|25.50 TEXT 1250chars First 1000 chars...

🧪 Features Tested

  • DOCX paragraphs (non-empty only)
  • DOCX tables (full cell data)
  • Embedded Excel (.xlsx/.xls)
  • Nested DOCX (recursive)
  • SQL/TXT files
  • OLE package stream extraction
  • Empty content filtering
  • TOON compact output

🔍 Dependencies

Package Purpose
python-docx DOCX parsing
openpyxl Excel reading
olefile OLE embedded extraction

⚙️ Development

Install dev dependencies

pip install -e .[dev]

Build package

python -m build

Test

pytest tests/

Publish

twine upload dist/*

📄 License

MIT License - see LICENSE for details.

🙏 Acknowledgments


Made with ❤️ for document automation

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

docx_extractor-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

docx_extractor-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file docx_extractor-1.0.0.tar.gz.

File metadata

  • Download URL: docx_extractor-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for docx_extractor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c58d8651fca2f1d94a605d3b3870458d0e877596010c15ce4b059fdc596e8b3a
MD5 2c5291b155bed365f6c2eb01c3b22506
BLAKE2b-256 c7589d323c0e180d80ddcb628fb85c4d06b7b194e4a989927ca2a346a0e1927a

See more details on using hashes here.

File details

Details for the file docx_extractor-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: docx_extractor-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for docx_extractor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81e777caca9b0b2df4b82c542d57c8d23554f876dfeb447a11b682627a865cd1
MD5 d955765d99c7ccdff29f7d1f559fc583
BLAKE2b-256 a211ef0b5ea7bbae10fd4b6c997e927a4d99f93de25d3c2317f9d12323eae50e

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