A previous version of this repo assumed a fresh or empty output directory, and would clear it before writing results.
If you pointed theoutputpath to an existing directory containing data, that data may have been removed.
✅ This behavior has now been corrected. The current version:
- Does not delete existing output folders or files
- Creates new subfolders safely and preserves existing data
If you're updating from an older version, please pull the latest code and avoid reusing sensitive directories as output targets.
This project provides a FastAPI-based API for extracting tables from documents (PDF) using multiple backends (Docling, Llamaparse, Unstructured). It supports saving extracted tables as CSV and HTML files in organized output directories.
- Extract tables from documents using Docling, Llamaparse, and Unstructured backends
- Save results as CSV and HTML in organized output folders
- Simple
/extractAPI endpoint - Configuration via
.envfile - GPU acceleration recommended for Docling for best performance
- Python 3.11+
- pip
- (Optional) NVIDIA GPU for faster Docling extraction
A folder named table_outputs will be created inside your specified output directory. For each extraction job, a unique subfolder (named with a job ID) is created inside table_outputs. All results for that job are stored in this subfolder.
- Clone the repository:
git clone https://github.com/traversaal-ai/pdf-parser-table-extraction-fast-api.git cd get-tables-fastapi - Create and activate a virtual environment:
python -m venv venv # On Windows: venv\Scripts\activate # On Unix/Mac: source venv/bin/activate
- Install dependencies:
pip install --upgrade pip pip install -r requirements.txt
Create a .env file in the project root with your API keys and endpoints:
llamaparse_api_key=your_llamaparse_key_here
unstructured_api_key=your_unstructured_key_here
openai_api_key=your_openai_api_key_here
Start the FastAPI server with Uvicorn:
uvicorn main:app --reloadThe API will be available at http://localhost:8000/docs
Extract tables from a document using one or more backends.
POST /extract
input_file_path(str): Absolute path to the input document on the serveroutput_dir(str): Absolute path to the output directory (will be created/freshened)docling(bool): Use Docling backend (true/false)llamaparse(bool): Use Llamaparse backend (true/false)unstructured(bool): Use Unstructured backend (true/false)
curl -X POST http://localhost:8000/extract \
-F "input_file_path=/absolute/path/to/input.pdf" \
-F "output_dir=/absolute/path/to/output" \
-F "docling=true" \
-F "llamaparse=false" \
-F "unstructured=true"Returns a JSON object with the extraction results for each backend.
{
"results": {
"docling": { ... },
"llamaparse": { ... },
"unstructured": { ... }
}
}
- All output files are saved in subdirectories of the provided
output_dir(e.g.,output_dir/docling/,output_dir/unstructured/). - Each backend saves its own results in its respective folder.
- The input file must exist on the server at the specified path.
- LlamaParse backend is currently a placeholder.
- For best performance with Docling, use a machine with an NVIDIA GPU.
MIT
We evaluated all three extraction tools across three fundamental criteria:
Completeness: Are all data values captured from the table?
Accuracy: Are the extracted values correct?
Structure: Is the layout (rows/columns) preserved correctly?
| Tool | Completeness | Accuracy | Structure | Average Score |
|---|---|---|---|---|
| Docling | 90.5% | 94.9% | 63.1% | 82.8 |
| Unstructured | 53.1% | 51.5% | 64.2% | 56.3 |
| LlamaParse | 96.9% | 62.0% | 80.4% | 79.8 |
Docling offers the best balance, while LlamaParse captures nearly all tables but with some accuracy trade-offs.
🎥 Video Demo
Linkedin-1080P-2X.2.mp4
A visual walkthrough showing how different tools perform table extraction on sample documents.