Skip to content

Repository files navigation

Textractify

A Python library to parse AWS Textract responses and provide simple layout-based outputs.

Installation

pip install textractify

For development:

git clone https://github.com/devanshupathak/textractify.git
cd textractify
pip install -e ".[dev]"

Features

  • Parse AWS Textract JSON responses
  • Extract tables with proper structure
  • Extract key-value pairs from forms
  • Extract layout blocks with geometry information
  • Convert documents to markdown format
  • Identify handwritten content
  • Export structured data as JSON

Quick Start

import json
from textractify import TextractExtractor

# Load your Textract response
with open('textract_response.json', 'r') as f:
    textract_data = json.load(f)

# Initialize the extractor
extractor = TextractExtractor(textract_data)

# Extract layout blocks
layout_data = extractor.extract_layout_blocks()

# Convert to markdown
markdown = extractor.extract_layout_as_markdown()
print(markdown)

# Extract tables and key-values
tables, key_values = extractor.extract_tables_and_key_values()

# Get section headers and titles
headers, titles = extractor.get_section_headers_and_titles()

# Save to JSON
extractor.save_layout_to_json('output.json')

API Reference

TextractExtractor

Main class for extracting structured data from AWS Textract responses.

Methods

  • extract_layout_blocks(): Extract layout blocks with geometry information
  • extract_tables_and_key_values(): Extract tables and key-value pairs
  • extract_layout_as_markdown(): Convert document to markdown format
  • get_section_headers_and_titles(): Get document headers and titles
  • save_layout_to_json(output_path, page_number=None): Save layout data to JSON

Supporting Classes

  • Cell: Represents a table cell
  • Table: Represents a complete table
  • Line: Represents a line of text
  • Layout: Represents a layout block
  • Field: Represents a key-value field
  • Form: Collection of form fields

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

A Python library to parse AWS Textract responses and extract layout-based structured data including tables, forms, and document hierarchy.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages