Datagrunt 5.5.0: Python 3.15 Support, Hybrid-Page OCR, Blank-Row Bands & Frozen Workers

November 23, 2026by Martin Graham

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

  1. Python 3.15 Support & CI Matrix — Adds Python 3.15 package metadata classifiers and full CI compatibility testing alongside 3.11–3.14 (keeping requires-python >= 3.11 and the abi3-py311 native Rust extension).
  2. Hybrid-Page Unmapped-Region OCR — Automatically crops and OCRs unmapped or invalid character tokens (such as unmapped non-AGL ligatures) on hybrid pages, merging OCR words back by position while keeping replaced span segments flagged superseded.
  3. Blank-Row-Aligned OCR Bands — Updates ocr.bands() so 900 px horizontal OCR seams snap upward to blank pixel rows within a bounded search window when tall headings or lines straddle a cut.
  4. PyInstaller & Frozen Executable Support (datagrunt.pdf.freeze_support()) — Exports opt-in freeze_support() from datagrunt.pdf so frozen binaries can re-enter as allowlisted, memory-capped PDF workers.
  5. 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 across workers.
  6. Dropped-Text Recovery, Dash-Array Bound & Source Identity Verification — Places dropped-text recovery slots clear of MediaBox and stationary page objects, resets enclosing zero-scale Form XObjects, caps dash-array reads at 256 entries, and verifies source file bytes before and after PDFWriter.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.15 classifier to pyproject.toml.
  • Added "3.15" to the python-compat matrix in CI (using COVERAGE_CORE=sysmon on Python 3.12+, including 3.15).
  • The Rust-accelerated extension (datagrunt._native) continues to build against abi3-py311, and requires-python remains >=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:

  1. Invalid-character tokens are partitioned from surrounding valid text without disturbing clean spans.
  2. Up to 32 unmapped regions per page are cropped from a bounded render at vision_dpi, padded with a 16-pixel white margin, and read with tesseract within the page’s shared OCR budget.
  3. Returned OCR words are mapped back to page coordinates and merged into the page’s pieces before lattice table detection and layout assembly.
  4. Every replaced span segment is preserved and flagged "superseded" in hidden_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 _MEIPASS entries on sys.path, run the allowlisted worker (figures, pages, or render) under its memory cap, and exit cleanly without re-running main().
  • Fail-closed default: Frozen executables that do not call freeze_support() continue to raise DatagruntPDFError.

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_key records the stream SHA-256 alongside filter pipeline, pixel dimensions, bits per pixel, colour space, and a bounded SHA-256 of any ICCBased profile (up to 16 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 /ICCBased profiles 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 workers threads 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_dropped now places moved dropped-text recovery objects outside the union of MediaBox and 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 caps FPDFPageObj_GetDashArray copies at _MAX_DASH_COUNT = 256; stroked paths with longer dash arrays are classified as dashed in O(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 cached SourceIdentity and SHA-256 both before and after rendering, raising PDFSourceChangedError if 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 release job to .github/workflows/publish-to-pypi.yml scoped with contents: write that automatically creates the GitHub Release after a production PyPI publish succeeds (skipping TestPyPI smoke runs).
  • Workflow Action Bumps: Updated astral-sh/setup-uv from 10.3.3 to 10.4.0 and actions/create-github-app-token from 3.3.0 to 3.4.0 in GitHub Actions workflows.
  • Benchmark Test Stabilization: Stabilized the linear-scaling consensus benchmark tests in tests/rationalization_tests/test_consensus.py using warm-up passes and interleaved GC-paused rounds (_interleaved_pair) with a 2.6x gate 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.