Skip to main content

python docx parser

Project description

DXPARS

A fast and simple Python library for analyzing and parsing Microsoft Word (DOCX) files, written in pure Python. DXPARS provides an intuitive API for extracting text content, working with formatting, tables, and converting documents to plain text or json.

License: MIT Python Version

Key Features

  • Zero Dependencies: Written in pure Python with no external dependencies
  • Format Support: Extract and work with document formatting styles (headings, alignment, etc.)
  • Table Handling: Parse and extract data from complex table structures
  • Text Conversion: Easy conversion to plain text files
  • Performance: Fast parsing of large documents
  • Simple API: Intuitive interface for document manipulation

Installation

DXPARS requires Python 3.9 or higher. You can install it using pip:

pip install dxpars

Or install from source:

git clone https://github.com/stmyst/dxpars.git
cd dxpars
pip install .

Usage

Basic Usage

import json

from dxpars.document import Document

# Load a document
document = Document('path/document.docx')

# Get full document text
print(document.text)

# Save as plain text (filename is optional)
document.to_txt(folder='path_to_folder', filename='doc.txt')

# json serialization with formatting
json.dumps(document.to_dict)

Working with Formatting

# Extract headings
for paragraph in document.paragraphs:
    if paragraph.pstyle is not None:
        if 'Heading' in paragraph.pstyle:
            print(f'Heading: {paragraph.text}')

# Get formatted data
for paragraph in document.paragraphs:
    for run in paragraph.parts:
        if run.bold:
            print(f'Bold text: {run.text}')

Working with Tables

for table in document.tables:
    # Display table structure
    print(table.show)  
    
    # Get all table text
    print(table.text)
    
    # Access cells by position
    cell = table.parts[0].parts[0]
    print(f'First cell: {cell.text}')

For more examples check out the examples directory.

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

dxpars-0.0.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

dxpars-0.0.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dxpars-0.0.1.tar.gz
Algorithm Hash digest
SHA256 86199f06a5312a5353fef14fd9bffa748f63de72e6711daa8bc6b4e35326e6ea
MD5 60ad0bf9e43eb81a0df2d9e86d3df0a6
BLAKE2b-256 013997c327040f2242f81db102edd4f243096fe873582a4a8480b63b0fc9e829

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dxpars-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 48ab21bb0dfaa8db6fcb71daceb7326d75b529cc10e2fe37f529363159fcccd1
MD5 00a784bf731060d7e5a969b4583a36b8
BLAKE2b-256 8e96ab9616b90b0f4dc7114c23e3defcdb580cb93cd33c624164416eda39b3e8

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