Metadata-Version: 2.4
Name: parsy-doc
Version: 3.0.2
Summary: High-performance, privacy-preserving document intelligence engine. Parse PDFs, DOCX, HTML and more to Markdown, JSON, HTML or CSV — fully local.
License: MIT
Project-URL: Homepage, https://github.com/yourname/parsy
Project-URL: Documentation, https://github.com/yourname/parsy#readme
Project-URL: Repository, https://github.com/yourname/parsy
Project-URL: Bug Tracker, https://github.com/yourname/parsy/issues
Keywords: pdf,parser,document,ocr,markdown,document-intelligence,fastapi,text-extraction
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Text Processing
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastapi>=0.100.0
Requires-Dist: uvicorn[standard]>=0.22.0
Requires-Dist: python-multipart>=0.0.6
Requires-Dist: sse-starlette>=1.6.0
Requires-Dist: httpx>=0.24.0
Requires-Dist: pydantic>=2.0
Requires-Dist: PyMuPDF>=1.23.0
Requires-Dist: python-docx>=0.8.11
Requires-Dist: pdfplumber>=0.10.0
Requires-Dist: beautifulsoup4>=4.12.0
Requires-Dist: lxml>=4.9.0
Requires-Dist: chardet>=5.1.0
Requires-Dist: openpyxl>=3.1.0
Requires-Dist: Pillow>=9.5.0
Requires-Dist: structlog>=23.1.0
Requires-Dist: prometheus-client>=0.17.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: anyio>=3.7.0
Provides-Extra: ml
Requires-Dist: transformers>=4.30.0; extra == "ml"
Requires-Dist: sentence-transformers>=2.2.0; extra == "ml"
Requires-Dist: scikit-learn>=1.2.0; extra == "ml"
Requires-Dist: onnxruntime>=1.15.0; extra == "ml"
Provides-Extra: ocr
Requires-Dist: pytesseract>=0.3.10; extra == "ocr"
Requires-Dist: pdf2image>=1.16.3; extra == "ocr"
Provides-Extra: queue
Requires-Dist: celery[redis]>=5.3.0; extra == "queue"
Requires-Dist: redis>=5.0.0; extra == "queue"
Requires-Dist: kombu>=5.3.0; extra == "queue"
Requires-Dist: flower>=2.0.0; extra == "queue"
Provides-Extra: all
Requires-Dist: parsy-doc[ml,ocr,queue]; extra == "all"
Dynamic: license-file

# Parsy — Document Intelligence Engine

[![PyPI](https://img.shields.io/pypi/v/parsy-doc)](https://pypi.org/project/parsy-doc/)
[![Python](https://img.shields.io/pypi/pyversions/parsy-doc)](https://pypi.org/project/parsy-doc/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

**Parsy** is a high-performance, privacy-preserving document intelligence engine.  
Parse PDFs, DOCX, HTML, TXT, CSV, JSON, and XML into clean **Markdown, JSON, HTML, or CSV** — fully locally with no data leaving your machine.

---

## ✨ Features

- ⚡ **Blazing fast** — Zero-copy PyMuPDF extraction, parallel page processing
- 🔒 **Private** — Runs 100% locally, no internet required after install
- 📄 **Multi-format** — PDF, DOCX, TXT, HTML, CSV, JSON, XML, XLSX
- 🧠 **ML-powered** (optional) — Layout regions, semantic heading clusters, table structure
- 🌊 **SSE streaming** — Real-time progressive output for large documents
- 🖥️ **CLI + Python API + REST API** — Use however you want

---

## 📦 Installation

```bash
pip install parsy-doc
```

With optional ML structural analysis:
```bash
pip install parsy-doc[ml]
```

With OCR support (requires Tesseract installed on your system):
```bash
pip install parsy-doc[ocr]
```

Full installation:
```bash
pip install parsy-doc[all]
```

---

## 🚀 Quick Start

### Python API

```python
import parsy

# Parse a PDF to Markdown
result = parsy.parse("contract.pdf")
print(result.markdown)

# Parse to JSON
result = parsy.parse("invoice.pdf", format="json")
print(result.json)

# Access tables directly
for table in result.tables:
    print(table)

# View parsing metrics
print(result.metrics)
# → {'wordCount': 4231, 'pageCount': 18, 'charCount': 24100, ...}
```

### Async API (FastAPI, asyncio)

```python
import parsy
import asyncio

async def main():
    result = await parsy.parse_async("report.pdf", format="markdown")
    print(result.markdown)

asyncio.run(main())
```

---

## 💻 Command-Line Interface

After installing, a `parsy` command is available globally:

```bash
# Parse a PDF and print to terminal
parsy parse report.pdf

# Save to file in JSON format
parsy parse invoice.pdf --format json --output invoice.json

# Parse all PDFs in a folder (batch mode)
parsy parse docs/*.pdf --format markdown --output ./results/

# Enable ML analysis
parsy parse research_paper.pdf --ml

# Launch the local REST API server + web UI
parsy serve

# Custom host and port
parsy serve --host 0.0.0.0 --port 8080

# Check version
parsy --version
```

---

## 🌐 REST API Server

Start the streaming REST API server:

```bash
parsy serve
# → http://localhost:8000
```

Then use the web UI at `http://localhost:8000` or POST to the API:

```bash
curl -X POST http://localhost:8000/parse \
  -F "file=@report.pdf" \
  -F "format=markdown"
```

The API uses Server-Sent Events (SSE) for real-time streaming progress.

---

## ⚙️ Options

| Option | Values | Default | Description |
|--------|--------|---------|-------------|
| `format` | `markdown`, `json`, `html`, `csv`, `plaintext` | `markdown` | Output format |
| `tables` | `bool` | `True` | Extract tables |
| `clean` | `bool` | `True` | Whitespace cleanup |
| `use_ml` | `bool` | `False` | Enable ML structural analysis |

---

## 🔬 Supported File Types

| Format | Extension | Notes |
|--------|-----------|-------|
| PDF (digital) | `.pdf` | Full text + table extraction |
| PDF (scanned) | `.pdf` | OCR via Tesseract (`pip install parsy-doc[ocr]`) |
| Word | `.docx` | Headings, paragraphs, tables |
| HTML | `.html`, `.htm` | Semantic extraction |
| Plain text | `.txt`, `.rtf` | Encoding auto-detected |
| Markdown | `.md` | Passthrough + re-format |
| Spreadsheet | `.xlsx`, `.csv` | Table-centric output |
| Data | `.json`, `.xml` | Structured extraction |

---

## 🏛️ Architecture

```
parsy parse() / parse_async()
        │
        ▼
  DocumentRouter          ← heuristic inspection
        │
  ┌─────┴──────────┐
  │                │
Fast Parser     Vision OCR     ← PyMuPDF / Tesseract
  │
  ▼
Normalizer                     ← Markdown, JSON, HTML, CSV
  │
  ▼
ParseResult
```

---

## 📄 License

MIT — see [LICENSE](LICENSE)
