Skip to main content

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.

Contributing & quality

CONTRIBUTING.md is the project's quality contract — the testing philosophy and the competitive multi-model review methodology pdfmonkey is hardened with. The release decision is made explicit and measurable: RELEASE_READINESS.md defines the rubric, python scripts/readiness.py computes the score, and REVIEW_HISTORY.md records the panel trajectory. The portable source of this methodology lives in review-kit/.

Changelog

Release history is in CHANGELOG.md.

License

MIT — see LICENSE.

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

pdfmonkey-1.0.2.tar.gz (54.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdfmonkey-1.0.2-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file pdfmonkey-1.0.2.tar.gz.

File metadata

  • Download URL: pdfmonkey-1.0.2.tar.gz
  • Upload date:
  • Size: 54.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pdfmonkey-1.0.2.tar.gz
Algorithm Hash digest
SHA256 79bba6f9978d0bf365fa38b9fdf8b633457b6a76b210b898f30308a355b6d02e
MD5 d0d3e2ca91a1fb3f40f107372c3bfc14
BLAKE2b-256 6aba10cf6a4b2846f0a4d3d274080e2a5afa2c58d181f96267cf1ca3adf5635d

See more details on using hashes here.

File details

Details for the file pdfmonkey-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pdfmonkey-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pdfmonkey-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7ef3a71161b2e86ef6597c78d0b9bbeac392efe3f3652252946f0577f52c285a
MD5 43a61f4eeb153f3313c31cc576b7e215
BLAKE2b-256 2a46743fe875e0b0afa9587a777d3bb02769ea8fd0bd5513830d0b2dd1105183

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page