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 yolo based detection to identify table regions.
- 🧠 Intelligent Restructuring: Leverages LLMs to understand and restructure hierarchical tables.
- 📊 Multiple Output Formats: Supports CSV and pandas DataFrame outputs.
- 📄 Flexible Extraction: Extract tables from all pages or specific pages of your documents, as needed.
- 🎯 High Accuracy: Combines computer vision preprocessing with LLM analysis for robust extraction.
- 🔧 Flexible Models: Seamlessly integrates with API providers like OpenAI GPT, Google Gemini, and Groq.
- 📝 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
# Alternatively if you have uv installed
uv pip install tabulens
Or directly from GitHub:
pip install git+https://github.com/astonishedrobo/tabulens.git
# Alternatively if you have uv installed
uv pip git+https://github.com/astonishedrobo/tabulens.git
Quick Start
Python API
from tabulens import TableExtractor
extractor = TableExtractor(
model_name='gpt:gpt-4o', # gemini:gemini-2.0-flash | groq:meta-llama/llama-4-scout-17b-16e-instruct
temperature=0.7,
rate_limiter=True,
rate_limiter_params={
"requests_per_second": 0.5,
"check_every_n_seconds": 0.1,
"max_bucket_size": 1,
}
)
dfs = extractor.extract_tables(
file_path='path/to/document.pdf',
save=True,
max_tries=3,
verbose=True, # For console messages (by logger)
show_progress=True, # For progress bars
page_idx=None, # None (default) for all or [0,1,2]
)
for i, df in enumerate(dataframes):
if df is not None:
print(f"Table {i+1}")
print(df.head())
Command Line Interface
To extrach tables:
# OpenAI
tabulens extract --pdf path/to/document.pdf --model gpt:gpt-4o-mini --temperature 0.7 --max_tries 3 --verbose
# Gemini
tabulens extract --pdf path/to/document.pdf --model gemini:gemini-2.0-flash --temperature 0.7 --max_tries 3 --verbose
# Groq
tabulens extract --pdf path/to/document.pdf --model groq:meta-llama/llama-4-scout-17b-16e-instruct --temperature 0.7 --max_tries 3 --verbose
CLI Options
--pdf: Path to the PDF file (required)--model: Model name (gpt:gpt-4o-mini,gemini:gemini-2.0-flash,groq:meta-llama/llama-4-scout-17b-16e-instruct,gpt:gpt-4o,gemini:gemini-2.5-flash-preview-05-20, etc.) [default:gpt:gpt-4o-mini]. For OpenAI models, use the prefixgpt:, for Gemini models, use the prefixgemini:, and for Groq, use the prefixgroq:. (⚠️ 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.]--verbose: Print detailed logs--rate_limiter: Enable rate limiting for LLM calls
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>
export GROQ_API_KEY=<your_groq_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 Apache License 2.0.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tabulens-0.2.1.tar.gz.
File metadata
- Download URL: tabulens-0.2.1.tar.gz
- Upload date:
- Size: 129.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69f9f7946d9945a0dac3244bad238a7622d4c5a8e905f6740989873a71e5823b
|
|
| MD5 |
d5d9c223a48704e5207beee94916e078
|
|
| BLAKE2b-256 |
43f213cf5ff120d9857baecca9798a63ffe5d4534763abf26ebaf6d484a163bd
|
File details
Details for the file tabulens-0.2.1-py3-none-any.whl.
File metadata
- Download URL: tabulens-0.2.1-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95034b310d8195c83c9f3a73fbb73b0c4a012c3adac2f8307916b9ee1cb5e2d0
|
|
| MD5 |
e3e3c23efea1642d1a06cc9466158b5e
|
|
| BLAKE2b-256 |
166dd1cf62aaa9ebc3ede561321e4b2375771e235133a57d64446d6fb9317542
|