Skip to main content

LLM-powered PDF table extractor

Project description

Tabulens

Tabulens is a Python package that intelligently extracts and restructures tables from PDF files using advanced computer vision and Large Language Models (LLMs). It automatically detects table structures, manages complex hierarchical tables, and exports data into structured formats like CSV and pandas DataFrames.

Features

  • 🔍 Automatic Table Detection: Uses computer vision to identify table regions.
  • 🧠 Intelligent Restructuring: Leverages LLMs to understand and restructure hierarchical tables.
  • 📊 Multiple Output Formats: Supports CSV and pandas DataFrame outputs.
  • 🎯 High Accuracy: Combines computer vision preprocessing with LLM analysis for robust extraction.
  • 🔧 Flexible Models: Supports both OpenAI GPT and Google Gemini models.
  • 📝 Hierarchy Preservation: Flattens nested tables while maintaining parent-child relationships.
  • 🚀 Easy to Use: Simple API and command-line interface.

Installation

From PyPI:

pip install tabulens

Or directly from GitHub:

pip install git+https://github.com/astonishedrobo/tabulens.git

Quick Start

Python API

from tabulens import TableExtractor

extractor = TableExtractor(
    model_name='gpt:gpt-4o-mini', # gemini:gemini-2.0-flash
    temperature=0.7
)

dfs = extractor.extract_tables(
    file_path='path/to/document.pdf',
    save=True,
    max_tries=3,
    print_logs=True
)

for i, df in enumerate(dataframes):
    if df is not None:
        print(f"Table {i+1}")
        print(df.head())

Command Line Interface

# OpenAI 
tabulens --pdf path/to/document.pdf --model gpt:gpt-4o-mini --temperature 0.7 --max_tries 3 --log

# Gemini
tabulens --pdf path/to/document.pdf --model gemini:gemini-2.0-flash --temperature 0.7 --max_tries 3 --log

CLI Options

  • --pdf: Path to the PDF file (required)
  • --model: Model name (gpt:gpt-4o-mini, gemini:gemini-2.0-flash, gpt:gpt-4o, gemini:gemini-2.5-flash-preview-05-20, etc.) [default: gpt:gpt-4o-mini]. For OpenAI models, use the prefix gpt:, and for Gemini models, use the prefix gemini:. ⚠️ Make sure to select models that support image inputs. You can use any of the mentioned examples for convenience.
  • --temperature: Generation temperature (0.0-1.0) [default: 0.7]
  • --max_tries: Maximum retries per table extraction [default: 3] [Increase this value to enhance accuracy, as more attempts allow the system additional opportunities to correctly extract tables.]
  • --log: Print detailed logs

Environment Variable Setup

Before running the program, set the required API environment variables.

For CLI usage:

export OPENAI_API_KEY=<your_openai_api_key>
export GOOGLE_API_KEY=<your_google_api_key>

For Python API usage, load environment variables using python-dotenv:

from dotenv import load_dotenv
load_dotenv("path/to/.env")

Credits

Tabulens depends on these excellent open-source projects:

License

This project is licensed under the MIT License.

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

tabulens-0.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

tabulens-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file tabulens-0.1.1.tar.gz.

File metadata

  • Download URL: tabulens-0.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for tabulens-0.1.1.tar.gz
Algorithm Hash digest
SHA256 83ff110962ddf315ee83451afb48d598110c984980026acf98a4e4314a9d3943
MD5 c744470f80597d89563a2ac8e14d823e
BLAKE2b-256 010577ff2c2a249b5c04fa8cb99d3deb388941acf5bdada0cc1d95330650bcce

See more details on using hashes here.

File details

Details for the file tabulens-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tabulens-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for tabulens-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95fcce0b8aca77f80af9e527330a031673a3aa9d393a12f41330688001d9a56b
MD5 3d92a3f3109d4d42f54933e7ddede9e8
BLAKE2b-256 ef603e766072866bfcacd206ab26915677c41cba35b67842cb7736e0e7648784

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