One-call PDF table extraction returning clean lists of dicts, with heuristic detection, multi-page merging, and confidence scoring.
Project description
pdfmonkey
One-call PDF table extraction that returns clean Python data instead of jumbled text. pdfplumber handles ruled tables; a position-based heuristic reconstructs borderless ones; multi-page tables are stitched back together; every table comes with a confidence score.
import pdfmonkey
tables = pdfmonkey.extract_tables("report.pdf")
tables[0].to_dicts()
# [{'Name': 'Alice', 'Age': '30', 'City': 'London'},
# {'Name': 'Bob', 'Age': '25', 'City': 'Paris'}]
Why
Existing tools (pdfplumber, PyMuPDF, pdfminer) produce output where columns
bleed, rows split, headers detach, and multi-page tables fragment. Closing that
gap takes 100–200 lines of heuristic glue every time. pdfmonkey is that glue,
packaged: raw PDF in, clean list[dict] out.
Install
pip install pdfmonkey # core (pdfplumber only)
pip install pdfmonkey[enrich] # + enrich=True column types & text cleaning
pip install pdfmonkey[pandas] # + Table.to_dataframe()
pip install pdfmonkey[dev] # + test toolchain
The enrich extra pulls in the monkey ecosystem (cleanmonkey, datemonkey,
typemonkey). The core install does not require them: enrich=True records a
diagnostic and leaves column_types empty when they are absent, and text
extraction attempts cleanmonkey only via a guarded import before falling back
to a built-in cleaner.
Requires Python 3.11+.
Library API
import pdfmonkey
# Headline one-call API -> list[Table]
tables = pdfmonkey.extract_tables(
"report.pdf",
pages="1-3,5", # None/"all", "3", "2-5", "1,3,5-7"
merge=True, # stitch tables continued across pages (matching headers)
merge_headerless=False, # also stitch a headerless continuation (looser; opt-in)
enrich=False, # annotate Table.column_types via the monkey ecosystem
min_confidence=0.0, # drop tables scoring below this
)
# Rich result with diagnostics -> ExtractionResult
result = pdfmonkey.extract("report.pdf")
result.strategy_used # 'pdfplumber' | 'heuristic' | 'mixed' | 'none'
result.tables # list[Table]
# Clean text, paragraph-preserving -> str
text = pdfmonkey.extract_text("report.pdf", pages="1")
Each Table converts to whatever shape you need:
table.to_dicts() # list[dict] (dsvmonkey input, pgmonkey CSV import)
table.to_lists() # list[list[str]] (header row first)
table.to_csv() # str
table.to_json() # str
table.to_dataframe() # pandas.DataFrame (needs the [pandas] extra)
CLI
pdfmonkey extract report.pdf # CSV to stdout
pdfmonkey extract report.pdf -f json -p 1-3 # JSON, pages 1–3
pdfmonkey extract report.pdf --text # clean text instead of tables
pdfmonkey inspect report.pdf # shape/confidence/strategy, no data dump
inspect is the "should I trust this extraction?" command — it reports each
table's pages, shape, confidence, detecting strategy, and diagnostics without
printing the data.
Ecosystem
Built to interoperate with the monkey toolkit: to_dicts() feeds dsvmonkey,
to_csv() imports via pgmonkey, two tables compare with diffmonkey. With
enrich=True, cleanmonkey normalises cells and datemonkey/typemonkey
populate Table.column_types.
Scope
In scope: table detection, extraction, multi-page merging, structural analysis, text extraction. Out of scope: PDF creation/editing, form filling, image extraction, OCR, merging/splitting files.
Design tradeoffs
See LIMITATIONS.md for deliberate design tradeoffs (e.g. missing-vs-empty cells, header detection, conservative multi-page merge) before filing what looks like a bug.
Using with AI assistants
SKILL.md is an LLM-consumable guide (decision tree, worked examples, anti-patterns) so assistants reach for pdfmonkey instead of hand-rolling pdfplumber glue.
Changelog
Release history is in CHANGELOG.md.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
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 pdfmonkey-1.0.0.tar.gz.
File metadata
- Download URL: pdfmonkey-1.0.0.tar.gz
- Upload date:
- Size: 49.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d7a94ab3a6ad788c93605211ea7d9c52021650fb86db9d90be952d12bb1d894
|
|
| MD5 |
ae42cbd5b5a8e2faf0258d6017a8b852
|
|
| BLAKE2b-256 |
c1f291153aef526c65a28c4d83d8bbb4a640cdda287bed6d0b26ade8364ab8e8
|
File details
Details for the file pdfmonkey-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pdfmonkey-1.0.0-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2225f682294bac58021fdce7f461b23023c274e02185931532d8dc04f89be88b
|
|
| MD5 |
3f14d506d90250157d4fb854b2d9b800
|
|
| BLAKE2b-256 |
4944cd22d8b9dd5de5d6d77824fbcfdab27cb7a5115cbf8912275f0b981f49b8
|