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.3.tar.gz (56.7 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.3-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdfmonkey-1.0.3.tar.gz
  • Upload date:
  • Size: 56.7 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.3.tar.gz
Algorithm Hash digest
SHA256 fd79d593eaf3b90a008ea7743c407ca1ba69b6e6d7c4173d0c3b5a08c8e45e7e
MD5 16d9c50b3832f8984f6f6653cdd93261
BLAKE2b-256 11f4f6f0175d8da854dee579b8ff0f42645c69de0e42a9331baf4c0796bc0fdb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdfmonkey-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 30.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d69a075f0dee5deb6abcdcb5a4cb7a1d2df53e31723a39541af267caabe4e2e1
MD5 4059007c4d9a21797ec01a805d8bfcd3
BLAKE2b-256 29dac726ad01cb6a14ab955fa16d7b8b89f725c317f4cea13f6549f7f119b3db

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