A Python library to parse AWS Textract responses and provide simple layout-based outputs.
pip install textractifyFor development:
git clone https://github.com/devanshupathak/textractify.git
cd textractify
pip install -e ".[dev]"- 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
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')Main class for extracting structured data from AWS Textract responses.
extract_layout_blocks(): Extract layout blocks with geometry informationextract_tables_and_key_values(): Extract tables and key-value pairsextract_layout_as_markdown(): Convert document to markdown formatget_section_headers_and_titles(): Get document headers and titlessave_layout_to_json(output_path, page_number=None): Save layout data to JSON
Cell: Represents a table cellTable: Represents a complete tableLine: Represents a line of textLayout: Represents a layout blockField: Represents a key-value fieldForm: Collection of form fields
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.