Skip to main content

python docx parser

Project description

DXPARS

A fast and simple Python library for analyzing and parsing Microsoft Word (DOCX) files. 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

  • Minimal Dependencies: Depends only on lxml
  • 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-1.0.0.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-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dxpars-1.0.0.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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a6532a34ebe636623a9e1f79937716b1b82a93da6aaccb803db8e2ea779f3598
MD5 7e36b1b0095c2f807bf5dcbe5d83ac65
BLAKE2b-256 e670a9fb5c4ba885c8de011b09999d8f546072e5affe460db0b3de704e7932d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dxpars-1.0.0-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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f53822347824db223c52dc8614694bff36aea88aac900555d1efee145ec953a9
MD5 c73895de9c211f489966cb1389a9a54c
BLAKE2b-256 f3b98d22641c387078ba970c09672e9b05f09c6071457522cb6d9edfdc3be228

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