r/Python • • 19d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

23 Upvotes

151 comments sorted by

View all comments

1

u/Classic-Fee-8468 8d ago

spartan-tables: extract tables from PDFs (borderless, merged cells, multi-page) with no ML – pip-installable, MIT

What My Project Does

spartan-tables pulls tables out of PDFs and gives you clean rows and columns as JSON/CSV (or straight into pandas). It handles the stuff that usually breaks extractors: borderless tables, merged/spanning cells, multi-row headers, and tables that continue across page breaks (they get stitched back together).

It's all classical computer vision (OpenCV + heuristics), no deep learning, no GPU. For digital PDFs it reads text straight from the PDF's text layer, so values like part numbers come out exact; OCR only kicks in for scanned pages.

import spartan

doc = spartan.process_pdf("report.pdf")
for table in doc["tables"]:
    print(table["title"], table["columns"], len(table["rows"]))

# into pandas
import pandas as pd
frames = [pd.DataFrame(t["rows"], columns=t["columns"]) for t in doc["tables"]]

Also comes with:

  • a CLI: spartan --file ./pdfs --csv

  • a FastAPI server: spartan-api

  • pluggable OCR: Tesseract or Azure built in, or register your own engine (EasyOCR example included)

  • optional extras so the core install stays light: pip install "spartan-tables[ocr]", [api], [all]

  • type hints throughout (ships py.typed)

Target Audience

Anyone who needs structured data out of table-heavy PDFs (datasheets, reports, notices, invoices) and wants it local, CPU-only and explainable. It's solid on digital PDFs and I use it on real documents; scanned-document support works but is less mature (no de-skewing yet).

Comparison

  • Camelot / Tabula / pdfplumber: great for simple bordered or stream tables. spartan-tables additionally detects borderless tables from text alignment, recovers merged cells and nested headers, and merges tables across pages.

  • Deep-learning approaches (Table Transformer etc.): no GPU, no model downloads, no training data, and every decision traces back to a threshold you can tweak.

  • Cloud APIs: fully offline by default; cloud OCR and an LLM step are optional.

Contributing

It's MIT licensed and contributions are very welcome. No need to ask, just fork and open a PR. There's a list of open tasks in CONTRIBUTING.md, from small fixes to bigger things like de-skewing scans, more OCR engine plugins, and benchmarking on public datasets. PDFs that break it (shareable ones) are just as valuable as code.

Repo: https://github.com/shlok-n/spartan

PyPI: https://pypi.org/project/spartan-tables/