# langchain-pdfmux

[![PyPI version](https://img.shields.io/pypi/v/langchain-pdfmux.svg)](https://pypi.org/project/langchain-pdfmux/)
[![Python versions](https://img.shields.io/pypi/pyversions/langchain-pdfmux.svg)](https://pypi.org/project/langchain-pdfmux/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

LangChain document loader for [pdfmux](https://pdfmux.com) -- self-healing PDF extraction for RAG pipelines.

## Why pdfmux?

Most PDF loaders use a single extraction method and silently fail on complex layouts. pdfmux routes each page through the best extraction pipeline automatically:

- **Smart routing** -- selects the optimal parser per page (text-heavy, scanned, tables, mixed)
- **Confidence scoring** -- every chunk includes a confidence score so your RAG pipeline can filter or re-rank
- **Self-healing** -- retries with alternative extractors when the primary one returns low-quality output

## Install

```bash
pip install langchain-pdfmux
```

## Usage

```python
from langchain_pdfmux import PDFMuxLoader

docs = PDFMuxLoader("report.pdf").load()
```

Each `Document` includes metadata with extraction quality signals:

```python
loader = PDFMuxLoader("report.pdf", quality="high")
for doc in loader.lazy_load():
    print(doc.metadata)
    # {
    #   "source": "report.pdf",
    #   "title": "Q4 Results",
    #   "page_start": 1,
    #   "page_end": 3,
    #   "tokens": 820,
    #   "confidence": 0.94
    # }
```

### Options

```python
# Quality presets: "fast", "standard" (default), "high"
loader = PDFMuxLoader("report.pdf", quality="high")

# Load all PDFs in a directory
loader = PDFMuxLoader("./papers/")

# Custom glob pattern
loader = PDFMuxLoader("./papers/", glob="**/*.pdf")

# Streaming with lazy_load
for doc in PDFMuxLoader("large.pdf").lazy_load():
    process(doc)
```

## License

MIT
