openfitz 🚀
A Fast, Lightweight Python Library for PDF Document Parsing, Spatial Text Extraction, and Raster Rendering Powered by Google PDFium.
Features
- Permissive MIT License: 100% free for commercial use, private SaaS backends, and microservices.
- Powered by Google PDFium: Utilizes the battle-tested, high-performance C++ engine that powers Google Chrome's PDF viewer via
pypdfium2. - Top-Left Coordinate System: Native
(x0, y0, x1, y1)bounding box coordinate mapping with zero coordinate inversion drift. - Spatial Text Extraction: Extract text bounded by exact clipping rectangles or inspect full document block, line, and span hierarchies.
- Raster Rendering & Pixel Inspection: Render pages or clipped areas directly to memory bitmaps with raw packed RGB
.samplesfor checkbox/darkness ratio analysis. - Bookmark / TOC Traversal: Fast hierarchical Table of Contents and bookmark extraction.
- Flexible Namespaces: Usable as either
import fitzorimport openfitz.
Installation
pip install openfitz
Quickstart
import fitz
# 1. Open a PDF document (from file path or bytes)
doc = fitz.open("sample.pdf")
print("Total pages:", doc.page_count)
# 2. Extract full page text or bounded text
page = doc[0]
full_text = page.get_text("text")
# Clipped extraction (top-left origin coordinates)
field_rect = fitz.Rect(50, 100, 300, 150)
field_text = page.get_text("text", clip=field_rect)
print("Extracted field:", field_text.strip())
# 3. Spatial text hierarchy (blocks, lines, spans)
page_dict = page.get_text("dict")
for block in page_dict["blocks"]:
for line in block["lines"]:
for span in line["spans"]:
print(f"Text: {span['text']} | Box: {span['bbox']} | Font: {span['font']}")
# 4. Render to Pixmap (for image export or darkness/checkbox detection)
mat = fitz.Matrix(2, 2) # 2x zoom
pix = page.get_pixmap(matrix=mat, clip=field_rect)
print("Pixel buffer length:", len(pix.samples))
pix.save("field_preview.png")
# 5. Extract Bookmarks / Table of Contents
toc = doc.get_toc(simple=True)
for level, title, page_num in toc:
print(f"Level {level}: {title} (page {page_num})")
doc.close()
Architecture
openfitz wraps Google PDFium's C++ rasterization and layout engine into clean, Pythonic classes:
| Class | Description |
|---|---|
fitz.Document |
Manages document lifecycle, page loading (doc[i]), saving, and bookmark traversal. |
fitz.Page |
Provides bounded text extraction, character spatial search, and rasterization. |
fitz.Rect |
Represents 2D bounding boxes (x0, y0, x1, y1) with intersection and union math. |
fitz.Matrix |
Represents 2D affine transformation matrices for scaling and rotation. |
fitz.Pixmap |
Contains rasterized image pixels, supporting raw .samples byte buffers and image export. |
Running Tests
git clone https://github.com/jagadeesh88705/openfitz.git
cd openfitz
pip install -e .[dev]
pytest -v
License
MIT License. Copyright (c) 2026 Jagadeesh Murugesan.
Metadata
Release files for openfitz 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| openfitz-0.1.0.tar.gz | 14.0 kB | With provenance | Details for openfitz-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openfitz-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for openfitz-0.1.0-py3-none-any.whl |
Total release size: 26.5 kB
Release files / openfitz-0.1.0.tar.gz
| Download URL | openfitz-0.1.0.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c45b38e9c9b0f1450e6cf99ded32ccca6f142fa63549040f226fb22e53cc93f1
|
|
BLAKE2b-256 checksum How to use checksums |
3b884262f46ce161bd1e41f3f3ed3d8ba428a5b0098329aa628c35129af98f63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logRelease files / openfitz-0.1.0-py3-none-any.whl
| Download URL | openfitz-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e3fb9e49fc1b6e10704d2f2bbdb54ddf3436c4ccbc0a6493f9b52fda1c78b80
|
|
BLAKE2b-256 checksum How to use checksums |
e800374677d95a4c03ad7a0e3c10f2cc2f0fd95efcb9359462fd30d5089d7e3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logSecurity for openfitz 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for openfitz-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.