Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 2.47 KB

File metadata and controls

58 lines (41 loc) · 2.47 KB

Docling vs LlamaParse: How to Extract PDF Tables in Python

This folder contains the code examples for the Real Python tutorial Docling vs LlamaParse: How to Extract PDF Tables in Python.

The scripts parse sample_report.pdf, a short financial report with tables, and compare two approaches:

  • Docling runs locally and exports structured document data, including tables as pandas DataFrames.
  • LlamaParse uses the Llama Cloud API for parsing and schema-driven extraction.

Files

File Description
sample_report.pdf Sample PDF used by all scripts
docling_extraction.py Parse the PDF with Docling and print Markdown output
docling_tables.py Inspect detected tables and print selected DataFrames
docling_formats.py Export Docling results to Markdown, JSON, HTML, and DataFrames
llamaparse_extraction.py Parse the PDF with LlamaParse and print Markdown output
llamaparse_tables.py Find HTML tables in the LlamaParse Markdown and print selected tables
llamaparse_formats.py Export LlamaParse results to Markdown, plain text, and JSON
requirements.txt Pinned dependencies for this folder

Installation

Create and activate a virtual environment, then install the dependencies:

$ python3 -m venv .venv/
$ source .venv/bin/activate
(.venv) $ python -m pip install -r requirements.txt

Run the scripts from this folder so the relative path to sample_report.pdf resolves correctly.

Docling examples

Docling runs on your machine and does not require an API key.

(.venv) $ python docling_extraction.py
(.venv) $ python docling_tables.py
(.venv) $ python docling_formats.py

docling_formats.py writes output_docling.md, output_docling.json, and output_docling.html in the current directory.

LlamaParse examples

The LlamaParse scripts require a Llama Cloud API key. Export it before running:

(.venv) $ export LLAMA_CLOUD_API_KEY="your-api-key"
(.venv) $ python llamaparse_extraction.py
(.venv) $ python llamaparse_tables.py
(.venv) $ python llamaparse_formats.py

llamaparse_formats.py writes output_llamaparse.md, output_llamaparse.text, and output_llamaparse.json in the current directory.