Datagrunt Documentation
This documentation provides comprehensive guidance for installing, using, and understanding Datagrunt - a Python library designed to simplify the way you work with CSV, Excel, Parquet, and PDF files.
Note
The current stable release is v5.7.0, introducing an optional, self-hostable Model Context Protocol (MCP) server (datagrunt[mcp], datagrunt-mcp) with deterministic CSV, Excel, Parquet, and PDF tools, symlink-safe root sandboxing, hardened read-only DuckDB SQL execution, and fail-closed Streamable HTTP hosting (release notes).
Installation
Datagrunt 5.0+ requires Python 3.11 or newer (supporting Python 3.11–3.15; 4.x supported Python 3.10). We recommend using uv as the default package manager.
To install Datagrunt using uv:
uv pip install datagruntOptional PDF & Rationalization Support
PDF parsing ships as an optional extra. Install basic PDF support with the pdf extra:
uv pip install "datagrunt[pdf]"For schema-driven PDF extraction (rationalize(), rationalize_many()), install the [pdf,rationalize] extras:
uv pip install "datagrunt[pdf,rationalize]"The pdf extra installs pypdfium2 (PDFium) and Pillow. The rationalize extra adds pydantic (schema validation) and httpx (provider communication). import datagrunt, the Key marker, PassSpec, load_bundle(), load_corpus(), load_corpus_documents(), CorpusManifest, CorpusEntry, CorpusFailure, prepare_batch(), ingest_batch(), BatchPlan, and BatchItem work without any extra installed.
OCR of scanned pages additionally requires the Tesseract program, with its English (eng) and orientation (osd) data:
- macOS:
brew install tesseract - Debian/Ubuntu:
apt-get install tesseract-ocr - Windows: install via the UB-Mannheim build (
winget install UB-Mannheim.TesseractOCR,choco install tesseract, orscoop install tesseract), then add its install directory toPATH
Datagrunt runs the tesseract it finds in an absolute directory on your PATH, never one in the working directory; there is no Python wrapper to install. Digital PDFs — text, tables, and embedded images — work without Tesseract: it is only needed for pages read by OCR. See Scanned pages and OCR.
Optional MCP Server Support
Datagrunt 5.7.0+ ships an optional, self-hostable Model Context Protocol (MCP) server (datagrunt-mcp) that exposes deterministic CSV, Excel, Parquet, and PDF tools for AI agents:
# Tabular MCP tools only
uv pip install "datagrunt[mcp]"
# Tabular + deterministic PDF MCP tools
uv pip install "datagrunt[mcp,pdf]"The mcp extra adds mcp (>=2.0.0, official Python MCP SDK v2). import datagrunt and import datagrunt.mcp stay lightweight and do not eagerly import mcp, starlette, uvicorn, duckdb, or polars — config, exception, and PathSandbox types are always available, while create_server(), create_streamable_http_app(), and run_server() load lazily when [mcp] is installed. See the MCP Server Guide for stdio and Streamable HTTP hosting, security defaults, and the full tool catalog.
Quick Start
Datagrunt makes reading and writing CSV, Excel, Parquet, and PDF files incredibly simple. Here is a 2-minute guide showing how to use the primary classes.
Reading Files
from pathlib import Path
from datagrunt import CSVReader, ExcelReader, ParquetReader, PDFReader
# 1. Read CSV (supports 'polars', 'duckdb', and 'pyarrow' engines)
reader_csv = CSVReader("data.csv", engine="polars")
df_csv = reader_csv.to_dataframe()
# 2. Read Excel worksheets (powered by Polars + calamine)
reader_excel = ExcelReader("data.xlsx")
df_excel = reader_excel.to_dataframe(sheet="Sheet1") # Sheet name or index
# 3. Read Parquet (powered by Polars)
reader_parquet = ParquetReader("data.parquet")
df_parquet = reader_parquet.to_dataframe()
# 4. Read PDF (requires PDF support)
reader_pdf = PDFReader("data.pdf")
df_pdf = reader_pdf.to_dataframe() # One row per element: headings, paragraphs, tables, ...
markdown_pdf = reader_pdf.to_markdown()Writing & Converting Files
from datagrunt import CSVWriter, ExcelWriter, ParquetWriter, PDFWriter
# 1. Export CSV data to other formats (CSV, Excel, JSON, Parquet)
writer_csv = CSVWriter("data.csv")
writer_csv.write_parquet("data.parquet")
# 2. Export Excel workbook sheets
writer_excel = ExcelWriter("data.xlsx")
writer_excel.write_csv("sheet.csv", sheet="Sheet1")
# 3. Export/Compress Parquet data
writer_parquet = ParquetWriter("data.parquet")
writer_parquet.write_excel("data.xlsx")
# 4. Write PDF results, extract images, and render pages —
# the PDF is extracted once, and every write reuses it
writer_pdf = PDFWriter("data.pdf")
writer_pdf.write_json("output.json")
writer_pdf.write_markdown("report.md")
writer_pdf.extract_images("extracted_images")
writer_pdf.render_pages_as_images("page_images", dpi=300)
# 5. Write all of the above as one checked directory that PDFReader loads back
writer_pdf.write_bundle("report_bundle")Every CSV, Excel, and Parquet reader can also run SQL directly against your file via DuckDB — see Querying with DuckDB.
Next Steps
- API Reference — Every class, constructor signature, and method in one place.
- Guides — Task-oriented walkthroughs: engine selection, messy CSV handling, Excel worksheets, Parquet options, PDF parsing, DuckDB queries, concurrency, and the MCP server.
- Studio Reference — Datagrunt Studio, the web workbench built on this library: setup, importing, querying, cleansing, AI PDF extraction, and exporting.