Skip to main content

Documment Extraction library for Python

Project description

Dextract

Dextract is a Python package designed for extracting content from any document type (PDF, DOCX, PPTX, etc.) into structured HTML and logical sections. By leveraging Apache Tika, it converts binary files into XHTML and logically oorganizes the content into a hierarchical model of headings, paragraphs, tables, and images.

Features

  • Hierarchical Extraction: Groups content into sections based on h1-h6 tags.
  • Breadcrumb Tracking: Maintains the full heading path for each section.
  • Rich Element Parsing:
    • Prose: Cleaned and normalized text from block-level tags.
    • Tables: Parsed into pipe-delimited Markdown-style text, including headers and metadata.
    • Lists: Ordered and unordered lists with appropriate prefixes.
    • Images: Extraction of src, alt, title, and dimensions.
    • Embedded Objects: Identification of Tika-embedded sub-documents and OLE objects.
    • Code Blocks: Preservation of formatting and language detection.
    • Quotes & Definitions: Structured extraction of blockquotes and definition lists.
  • Confluence Formatting: Includes a specialized formatter to convert Tika XHTML directly into Confluence Storage Format.

Installation

pip install dextract

Quick Start

File Parsing with Apache Tika

Dextract includes a utility to wrap Apache Tika for parsing binary files (like PDFs or Word documents) into XHTML, which can then be processed.

from dextract import parse_file, process_html

# Parse a binary file into HTML and metadata
# Use extract_media=True to pull out attachments/images
parsed = parse_file("report.pdf", extract_media=True)

# Process the resulting HTML into structured sections
sections = process_html(parsed["html_content"])

Basic Extraction (from HTML)

from dextract import process_html, summarise

# Raw HTML from Tika (or any other source)
html_content = """
<html>
    <body>
        <h1>Project Overview</h1>
        <p>This is a sample document.</p>
        <h2>Key Features</h2>
        <ul>
            <li>Fast extraction</li>
            <li>Structured output</li>
        </ul>
    </body>
</html>
"""

# Process the HTML into sections
sections = process_html(html_content)

# Print a summary of the extracted sections
summarise(sections)

Confluence Formatting

from dextract.formatter import ConfluenceFormatter

tika_html = "..." # Raw XHTML from Tika
attachments = {"image1.png": b"..."} # Optional attachment data

formatter = ConfluenceFormatter(tika_html, attachments)
confluence_xhtml = formatter.convert()

Package Structure

  • dextract.processor: The primary entry point (process_html).
  • dextract.parser: File parsing utilities using Apache Tika (parse_file).
  • dextract.models: Core data structures (Section, Element).
  • dextract.traversal: The engine that walks the HTML tree.
  • dextract.element_parsers: Specialized parsers for different HTML tags.
  • dextract.formatter: Confluence Storage Format conversion utilities.
  • dextract.debug: Helpers for inspection and statistics.

License

MIT

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

dextractpy-0.1.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

dextractpy-0.1.0-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file dextractpy-0.1.0.tar.gz.

File metadata

  • Download URL: dextractpy-0.1.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.10 Darwin/25.1.0

File hashes

Hashes for dextractpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8d1142f3465f0cc437de91a394ef3012432137b14d7564f0651092b1d0ee2aca
MD5 1415402d3fb5adefd9786bad128f4c92
BLAKE2b-256 555f92595681d1757be172eb62fff14d5bf79121ba7bea8751d297caad23f136

See more details on using hashes here.

File details

Details for the file dextractpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dextractpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.10 Darwin/25.1.0

File hashes

Hashes for dextractpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0dacc35b6dc949edf244134dea78c19a7dd00bdd005d175e206df3ddbe1f059f
MD5 a7ab8cb9e01110ebc0b0d73ddf194997
BLAKE2b-256 acac0d1a9deb0075f9356f49a23a63860313f992e2ace6fbc2ca7da24ff8b776

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