Metadata-Version: 2.4
Name: pyreflow
Version: 0.4.0
Summary: State-of-the-art document to HTML converter using deep learning
License: MIT License
        
        Copyright (c) 2025 Khushiyant Chauhan
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: converter,document,docx,html,layout-detection,ocr,pdf
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.12
Requires-Dist: brotli>=1.1.0
Requires-Dist: click>=8.1.0
Requires-Dist: fonttools[woff]>=4.50.0
Requires-Dist: jinja2>=3.1.0
Requires-Dist: pdfplumber>=0.11.0
Requires-Dist: pillow>=10.0.0
Requires-Dist: pymupdf>=1.25.0
Requires-Dist: python-docx>=1.1.0
Provides-Extra: dev
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Provides-Extra: ml
Requires-Dist: surya-ocr>=0.8.0; extra == 'ml'
Requires-Dist: torch>=2.2.0; extra == 'ml'
Requires-Dist: transformers>=4.40.0; extra == 'ml'
Description-Content-Type: text/markdown

# Reflow

State-of-the-art PDF/DOCX to semantic HTML converter with strong layout preservation.

## Install

```bash
pip install -e .
```

Optional ML features (layout detection, OCR, table transformer):

```bash
pip install -e '.[ml]'
```

## Quick Start

```bash
reflow convert input.pdf -o output.html
```

With OCR and guardrails:

```bash
reflow convert input.pdf \
	--ocr \
	--max-pages 200 \
	--max-output-mb 50 \
	--max-raster-mp 40 \
	--device cpu \
	-o output.html
```

## Reliability Guardrails

Reflow now supports resource limits to make production behavior predictable:

- `max_pages`: fail fast when document scope is too large.
- `max_output_bytes`: fail fast when generated HTML exceeds configured size.
- `max_raster_megapixels`: caps raster operations to avoid memory spikes.
- Atomic output writes: output files are written safely via temp-file replace.

## Observability

- Structured diagnostics callback (`diagnostics_callback`) can capture stage timings and pipeline stats.
- CLI prints timing/stats summary by default (`--emit-stats` / `--no-emit-stats`).

## Edge Case Handling

- Invalid page selections are validated against document page count.
- Scanned pages can trigger OCR automatically when no extractable text is found.
- Layout/table/OCR model failures degrade gracefully with warnings instead of hard crash.
- Broken text encoding spans are rasterized to preserve visual fidelity.

## API

```python
import reflow

html = reflow.convert(
		"sample.pdf",
		ocr=True,
		layout_detection=True,
		table_recognition=True,
		max_pages=100,
		max_output_bytes=20 * 1024 * 1024,
)
```

## Testing

```bash
pytest -q
```

With coverage gate (same as CI):

```bash
pytest --cov=reflow --cov-report=term-missing --cov-fail-under=80
```

Golden snapshot tests:

```bash
pytest -m golden
```

Update golden snapshots intentionally:

```bash
REFLOW_UPDATE_GOLDENS=1 pytest -m golden
```

## Benchmarking

Single document:

```bash
reflow benchmark sample.pdf --repeat 3 --output-json bench.json
```

Directory benchmark:

```bash
reflow benchmark ./pdfs --glob "*.pdf" --repeat 2 --output-json bench.json
```

Benchmark output includes min/median/max latency, output-size stats, and per-run stage diagnostics.

## CI

GitHub Actions CI is configured in [.github/workflows/ci.yml](.github/workflows/ci.yml) and runs tests with coverage threshold enforcement.

## Notes

- Python 3.12+
- Best results for complex layouts require optional ML dependencies.
