Datagrunt 5.5.0: Python 3.15 Support, Hybrid-Page OCR, Blank-Row Bands & Frozen Workers
Datagrunt 5.5.0 is now available! This minor release expands runtime support to Python 3.15 and delivers six focused improvements across PDF extraction, OCR, frozen application packaging, figure deduplication, PDFium recovery, and release automation (PR #523).
Highlights in Datagrunt 5.5.0
- Python 3.15 Support & CI Matrix — Adds Python
3.15package metadata classifiers and full CI compatibility testing alongside3.11–3.14(keepingrequires-python >= 3.11and theabi3-py311native Rust extension). - Hybrid-Page Unmapped-Region OCR — Automatically crops and OCRs unmapped or invalid character tokens (such as unmapped non-AGL ligatures) on
hybridpages, merging OCR words back by position while keeping replaced span segments flaggedsuperseded. - Blank-Row-Aligned OCR Bands — Updates
ocr.bands()so900 pxhorizontal OCR seams snap upward to blank pixel rows within a bounded search window when tall headings or lines straddle a cut. - PyInstaller & Frozen Executable Support (
datagrunt.pdf.freeze_support()) — Exports opt-infreeze_support()fromdatagrunt.pdfso frozen binaries can re-enter as allowlisted, memory-capped PDF workers. - Read Each Distinct Picture Once in
extract_images&write_bundle— Deduplicates identical embedded images by resolved picture key and PDF image-dictionary uniqueness before decoding, reusing one PDFium handle per worker batch acrossworkers. - Dropped-Text Recovery, Dash-Array Bound & Source Identity Verification — Places dropped-text recovery slots clear of
MediaBoxand stationary page objects, resets enclosing zero-scale Form XObjects, caps dash-array reads at256entries, and verifies source file bytes before and afterPDFWriter.render_pages_as_images().
1. Python 3.15 Support
Datagrunt 5.5.0 extends official support across Python 3.11–3.15:
- Added the
Programming Language :: Python :: 3.15classifier topyproject.toml. - Added
"3.15"to thepython-compatmatrix in CI (usingCOVERAGE_CORE=sysmonon Python 3.12+, including 3.15). - The Rust-accelerated extension (
datagrunt._native) continues to build againstabi3-py311, andrequires-pythonremains>=3.11.
2. Targeted OCR for Hybrid-Page Unmapped Regions
PDFs routed as hybrid (pages with readable digital text laid over scanned imagery covering more than half the page) sometimes contain spans with unmapped character codes or invalid Unicode—for example, non-AGL ligature control codes such as \x07 or \x1f recorded in RawSpan.map_errors.
In Datagrunt 5.5.0, when page.route == "hybrid", ocr != "never", and unmapped regions are detected:
- Invalid-character tokens are partitioned from surrounding valid text without disturbing clean spans.
- Up to
32unmapped regions per page are cropped from a bounded render atvision_dpi, padded with a 16-pixel white margin, and read withtesseractwithin the page’s shared OCR budget. - Returned OCR words are mapped back to page coordinates and merged into the page’s pieces before lattice table detection and layout assembly.
- Every replaced span segment is preserved and flagged
"superseded"inhidden_reasons—never dropped.
Clean digital pages, AutoCAD SHX text, and hybrid pages with zero mapping errors remain completely untouched.
import polars as pl
from datagrunt import PDFReader
reader = PDFReader("hybrid_scan.pdf")
# Visible text includes OCR replacements for unmapped hybrid tokens
visible = reader.to_dataframe().filter(pl.col("hidden_reasons").list.len() == 0)
# Replaced unmapped segments remain auditable via hidden_reasons=["superseded"]
superseded = reader.to_dataframe().filter(
pl.col("hidden_reasons").list.contains("superseded")
)3. Blank-Row-Aligned OCR Bands
Previously, vision pages were always sliced into fixed 900 px horizontal bands stepping by 840 px (sharing 60 px of overlap). Any tall heading or display line taller than 60 px that crossed a seam could be clipped across both bands.
In Datagrunt 5.5.0, ocr.bands() inspects the interior of each seam’s overlap strip. When ink spans across the seam, the cut shifts upward within a bounded window (_MAX_CUT_WINDOW = 420 rows above the nominal lower start) to the nearest blank horizontal pixel row, keeping the tall line whole in a single band while sharing up to 8 blank rows across the boundary. If no blank row lies within the window, it falls back cleanly to the exact fixed 900 px / 60 px cut; pages without straddling lines produce identical bands.
4. Frozen Application Worker Support (datagrunt.pdf.freeze_support())
Because Datagrunt isolates PDFium inside memory-capped worker subprocesses, frozen executables built with PyInstaller, cx_Freeze, or Nuitka previously had no Python interpreter to spawn and raised DatagruntPDFError.
Datagrunt 5.5.0 exports freeze_support() from datagrunt.pdf. Call it once near your application’s entry point inside if __name__ == "__main__":, mirroring multiprocessing.freeze_support():
from datagrunt import PDFReader, PDFWriter
from datagrunt.pdf import freeze_support
def main() -> None:
reader = PDFReader("report.pdf", workers=4)
print(f"Extracted {len(reader.pages)} pages")
PDFWriter(reader.document).write_markdown("report.md")
if __name__ == "__main__":
freeze_support()
main()- In a standard Python process,
freeze_support()is a no-op. - In a frozen executable, calling
freeze_support()allows Datagrunt to re-enter the binary with--datagrunt-pdf-worker, preserve_MEIPASSentries onsys.path, run the allowlisted worker (figures,pages, orrender) under its memory cap, and exit cleanly without re-runningmain(). - Fail-closed default: Frozen executables that do not call
freeze_support()continue to raiseDatagruntPDFError.
See the updated Concurrency & Environments guide for details.
5. Distinct Picture Deduplication in extract_images & write_bundle
Documents with repeated logos, stamps, or decorative icons often reference the same embedded image stream across dozens or hundreds of pages. Previously, PDFWriter.extract_images() and write_bundle() had to decode every figure into PNG bytes to verify whether two uses of the same stream shared identical rendering settings.
In Datagrunt 5.5.0:
RawImage.picture_keyrecords the stream SHA-256 alongside filter pipeline, pixel dimensions, bits per pixel, colour space, and a bounded SHA-256 of anyICCBasedprofile (up to16 MiB).- Before decoding, Datagrunt performs a fail-closed scan of PDF image dictionaries to prove when a stream is used with a unique dictionary across the document, reading each distinct picture once while still decoding figures separately whenever
/Decode,/Indexed,/Mask,/SMask,/DecodeParms,/ColorSpace, or/ICCBasedprofiles differ (or when encrypted PDFs, default colour spaces, incremental updates, or inline images are present). - Figure workers reuse a single open PDFium document per batch and fan batches across
workersthreads while returning results in deterministic document order:
from datagrunt import PDFWriter
writer = PDFWriter("catalog.pdf", workers=4)
# Deduplicated figures read each distinct picture once across 4 worker threads
image_paths = writer.extract_images("out/images")
# Bundles benefit from the same deduplicated, multi-worker figure pipeline
doc = writer.write_bundle("out/catalog_bundle")6. PDFium Recovery, Dash-Array Bound & render_pages_as_images Identity
Datagrunt 5.5.0 also hardens PDFium extraction and page rendering integrity:
- Safe Dropped-Text Recovery Placement:
isolate_droppednow places moved dropped-text recovery objects outside the union ofMediaBoxand all stationary page objects, and resets enclosing non-identity Form XObjects (such as degenerate zero-scale ancestor forms) so contained text objects recover distinctly in page coordinates. O(1)Dash-Array Bound: Path segment extraction capsFPDFPageObj_GetDashArraycopies at_MAX_DASH_COUNT = 256; stroked paths with longer dash arrays are classified as dashed inO(1)time without copying the full array.- Source Identity Verification in
render_pages_as_images():PDFWriter.render_pages_as_images()now verifies the source file’s cachedSourceIdentityand SHA-256 both before and after rendering, raisingPDFSourceChangedErrorif the file at the source path was removed, replaced with other bytes, or modified mid-render:
from datagrunt import PDFWriter
from datagrunt.pdf import PDFSourceChangedError
writer = PDFWriter("statement.pdf")
try:
page_paths = writer.render_pages_as_images("out/pages", dpi=300)
except PDFSourceChangedError as exc:
print(f"Source PDF changed before or during render: {exc}")CI, Automation & Test Stability
- Automated GitHub Releases: Added a
releasejob to.github/workflows/publish-to-pypi.ymlscoped withcontents: writethat automatically creates the GitHub Release after a production PyPI publish succeeds (skipping TestPyPI smoke runs). - Workflow Action Bumps: Updated
astral-sh/setup-uvfrom10.3.3to10.4.0andactions/create-github-app-tokenfrom3.3.0to3.4.0in GitHub Actions workflows. - Benchmark Test Stabilization: Stabilized the linear-scaling consensus benchmark tests in
tests/rationalization_tests/test_consensus.pyusing warm-up passes and interleaved GC-paused rounds (_interleaved_pair) with a2.6xgate to eliminate shared CI runner jitter (test-only change; no production rationalization code modified).
Upgrading to Datagrunt 5.5.0
Upgrade with uv:
uv pip install --upgrade "datagrunt[pdf,rationalize]"Or with pip:
pip install --upgrade "datagrunt[pdf,rationalize]"For full documentation, see the PDF Parsing Guide, Concurrency & Environments, and the Writers Reference.