Skip to main content

Deterministic document ingestion for PDF, DOCX, Excel, and CSV with quality-aware recovery.

Project description

DocGun

Quality-aware document ingestion for Python and RAG pipelines.

DocGun logo

Publish PyPI Python Downloads License

Package name: docgun
Project name: DocGun
Install: pip install docgun
Import: from docgun import ingest

DocGun turns PDF, DOCX, Excel, and CSV files into a consistent typed document model. It combines deterministic parsing with extraction scoring, page-aware fallback, security limits, and explicit recovery states so incomplete scans do not silently look successful.

  • Native PDF text, coordinates, tables, and page provenance with PyMuPDF.
  • Ordered DOCX headings, paragraphs, lists, and tables.
  • Bounded XLSX/XLSM and batched CSV extraction.
  • Page-level Docling fallback with structured elements and provenance.
  • Injectable OCR/VLM recovery for only the pages that need it.
  • Measurable confidence reports and structured recovery attempts.
  • ZIP/Open XML validation, encrypted-PDF detection, and ingestion limits.
  • Python API, CLI, and FastAPI upload route.

Before / After

from docgun import ingest

state = ingest("mixed-report.pdf")

print(state.status)
print(state.quality.confidence)
print(len(state.document.elements))

Example output:

completed
0.9142
47

When a scan cannot be recovered, DocGun returns recovery_required with page-level markers and diagnostics instead of presenting an empty page as successfully ingested.


Why Quality-Aware Ingestion?

Document parsers can return technically valid but incomplete output: a scanned page may yield only a footer, a fallback may omit pages, or a table detector may consume nearby text. DocGun makes those failure modes visible:

Input document
  -> Validate size, signature, archive safety, and encryption
  -> Inspect pages or workbook dimensions
  -> Route to a deterministic native parser
  -> Score content, structure, tables, and provenance
  -> Compare page-level fallback candidates
  -> Recover only weak pages with Docling or an OCR/VLM backend
  -> Return typed elements, status, quality, warnings, and diagnostics

Pipeline statuses are completed, partially_completed, recovery_required, and failed.


Install

pip install docgun

For Docling and the complete fallback toolset:

pip install "docgun[full]"

For development:

pip install -e ".[dev,full]"
pytest -q
python -m build

Quick Start

Ingest a Document

from docgun import ingest

state = ingest("annual-report.pdf")

for element in state.document.elements:
    print(element.type, element.text, element.location)

Inspect Recovery Diagnostics

for attempt in state.recovery_attempts:
    print(attempt.action, attempt.status, attempt.error_message)

Configure Page-Level Vision Recovery

Implement extract_batch(rendered_pages) in your OCR or VLM adapter and inject it into the pipeline:

from docgun.agents.recovery import RecoveryEngine
from docgun.agents.vision import VisionPageRecovery
from docgun.pipeline.graph import ingest

class MyVisionBackend:
    def extract_batch(self, pages):
        return vision_client.extract(pages)

engine = RecoveryEngine(VisionPageRecovery(MyVisionBackend()))
state = ingest("scan.pdf", recovery_engine=engine)

Each backend result may contain text, type, table, bbox, and confidence fields.


CLI

Ingest a file and print the complete pipeline state as JSON:

docgun report.pdf

Print a compact summary:

docgun report.pdf --summary

Supported Formats

Format Native parser Recovery
PDF PyMuPDF Docling, then configured page-level OCR/VLM
DOCX python-docx Explicit low-confidence status
XLSX/XLSM openpyxl Explicit low-confidence status
CSV PyArrow Explicit low-confidence status

Architecture

src/docgun/
  __init__.py          # Public API
  cli.py               # Command-line interface
  agents/              # Inspection, routing, confidence, quality, recovery
  api/                 # FastAPI upload route
  chunking/            # Hierarchical and spreadsheet chunk helpers
  domain/              # Typed elements, inspections, and errors
  parsers/             # PDF, Docling, DOCX, Excel, and CSV parsers
  pipeline/            # Orchestration state and policies
  security/            # File limits and format validation
  storage/             # Document and vector storage interfaces
tests/                 # Unit and regression tests
.github/workflows/     # CI and trusted PyPI publishing
CHANGELOG.md            # Release history
pyproject.toml          # Package metadata and dependencies

FastAPI

The bundled route streams uploads to a bounded temporary file, maps ingestion errors to appropriate HTTP responses, and removes the temporary file after success or failure.

from fastapi import FastAPI
from docgun.api.routes import router

app = FastAPI()
app.include_router(router, prefix="/documents")

Development

pip install -e ".[dev,full]"
python -m pytest
python -m build
python -m twine check dist/*

License

MIT


Contributing

Contributions are welcome. Please include a representative document or minimal generated fixture, the expected elements, and a regression test for parser or recovery changes.


Citation

@software{DocGun2026,
  title={DocGun: Quality-Aware Document Ingestion for Python},
  author={Arkay92},
  url={https://github.com/Arkay92/DocGun},
  year={2026},
  version={0.1.0},
}

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docgun-0.1.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docgun-0.1.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file docgun-0.1.0.tar.gz.

File metadata

  • Download URL: docgun-0.1.0.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docgun-0.1.0.tar.gz
Algorithm Hash digest
SHA256 614cd8910f09927a9a5dec52e5f9b12a5c9f82fdcb705fcc7f50dedd207e7567
MD5 dd1afb45ddd173be712dd314e520a096
BLAKE2b-256 44a2819d67868cda44571a725efad9e9981800e239f3c21cedc61759846dc1cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for docgun-0.1.0.tar.gz:

Publisher: publish.yml on Arkay92/DocGun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docgun-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docgun-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docgun-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d3512e593a51fa2f5c0fd97dee7d2f10c8654a06320ff637e149cdd9ef2bf25
MD5 c93294c2d54f96558914ed0741f110b0
BLAKE2b-256 47ca8f6cac99260ded37b318170953c5171bf82aacbaca17f19313ecdd36ff23

See more details on using hashes here.

Provenance

The following attestation bundles were made for docgun-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Arkay92/DocGun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page