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.
| 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 |
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.txtRun the scripts from this folder so the relative path to sample_report.pdf resolves correctly.
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.pydocling_formats.py writes output_docling.md, output_docling.json, and output_docling.html in the current directory.
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.pyllamaparse_formats.py writes output_llamaparse.md, output_llamaparse.text, and output_llamaparse.json in the current directory.