Skip to main content

PrettyPipeline

PrettyPipeline — PDF, JSON, and CSV through a pipeline into OCR

PyPI Python License: MIT

Latest release: v0.5.0 · Requires pip install prettypipeline-ocr (add [ocr] for Baidu OCR)

Turn PDFs into structured JSON. Text comes from embedded PDF content or local OCR. Figures are segregated and sent directly to GPT-5.4 — never the whole PDF as one image. Export to CSV and common LLM fine-tuning formats.

Architecture

                         ┌─────────────────────────────────────┐
                         │              PDF input              │
                         └─────────────────┬───────────────────┘
                                           │
              ┌────────────────────────────┼────────────────────────────┐
              │                            │                            │
              ▼                            ▼                            ▼
     ┌────────────────┐         ┌──────────────────┐         ┌──────────────────┐
     │ Embedded text  │         │ Embedded figures │         │ Scan-only pages  │
     │ (digital PDF)  │         │ (PyMuPDF crop)   │         │ (low-res fallback│
     └───────┬────────┘         └────────┬─────────┘         │  120 DPI max)    │
             │                           │                   └────────┬─────────┘
             │                           │                            │
             │              ┌────────────┴────────────┐               │
             │              │  NOT full-page images   │               │
             │              │  detail=low by default  │               │
             │              └────────────┬────────────┘               │
             │                           │                            │
             └───────────────────────────┼────────────────────────────┘
                                         │
                                         ▼
              ┌────────────────────────┐
              │   Embedded PDF text    │
              └───────────┬────────────┘
                          │ merge (dedupe)
              ┌───────────▼────────────┐
              │ Baidu Unlimited-OCR    │  ← default: always runs ([ocr] extra)
              │ (full document)        │
              └───────────┬────────────┘
                          │
                          ▼
              ┌────────────────────────┐
              │  Combined document text │
              │  + segregated figures   │──► GPT-5.4 nano
              └────────────────────────┘
                          │
          ┌───────────────┼───────────────┐
          ▼               ▼               ▼
     ┌─────────┐   ┌─────────────┐  ┌──────────────┐
     │  JSON   │   │needs_review │  │Export formats│
     │ + _meta │   │   flags     │  │ csv alpaca…  │
     └─────────┘   └─────────────┘  └──────────────┘

Local OCR (Unlimited-OCR) runs on every document by default (requires [ocr] extra), merged with embedded PDF text so nothing is missed — text in images, stamps, scan layers. Use --embedded-only to skip OCR (faster). Use --force-ocr for OCR-only.

Why this is cheap

  • Digital PDFs — embedded text is free and accurate; no GPU needed.
  • Figures only — segregated embedded images go to GPT vision at detail=low (not full-page raster).
  • Baidu OCR + merge — full-document OCR merged with embedded text by default ([ocr] extra).
  • GPT-5.4 nano — ~$0.20 / 1M input tokens for structuring (pricing).

Install

Python 3.10–3.13 (3.12 recommended).

# Digital PDFs + GPT vision (smallest install)
pip install prettypipeline-ocr

# + local OCR for scans
pip install prettypipeline-ocr[ocr]

From this repo:

python3.12 -m venv .venv && source .venv/bin/activate
pip install -e ".[ocr,dev]"

NVIDIA Linux:

pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
pip install prettypipeline-ocr[ocr]

Docker (CUDA): see Dockerfile.cuda.

Quick start

export OPENAI_API_KEY=sk-...

# Extract JSON (text + segregated figures → GPT)
prettypipeline run invoice.pdf --schema examples/invoice.schema.json

# Also export fine-tuning formats
prettypipeline run invoice.pdf --schema examples/invoice.schema.json \
  -o out.json --export csv,alpaca,sharegpt,openai,qa

# Convert existing JSON to a training file
prettypipeline export out.json --schema examples/invoice.schema.json \
  --format sharegpt -o train.jsonl

Demo invoice:

prettypipeline run tests/fixtures/sample_invoice.pdf \
  --schema examples/invoice.schema.json -o out.json

Figure segregation (vision)

PrettyPipeline does not rasterize entire PDF pages for GPT unless a page is scan-only with no embedded figures.

Page type Text source Vision sent to GPT
Digital + figures Embedded PDF text Embedded figures only (detail=low)
Digital, no figures Embedded PDF text Nothing
Scan, no figures Local OCR or low-res page One low-res page image (120 DPI)
--no-vision Same as above Disabled

Images are visual context only — no CSV or table dump is generated from figures.

Local Ollama (WIP)

Run structuring against a local Ollama server — no OpenAI key required.

ollama serve
ollama pull llama3.2-vision   # or llava, gemma3, etc.

prettypipeline run invoice.pdf --schema examples/invoice.schema.json --ollama
prettypipeline run invoice.pdf --schema examples/invoice.schema.json \
  --ollama --ollama-host http://localhost:11434 --model llama3.2-vision

How it works (per Ollama vision docs):

  • Native /api/chat endpoint (not experimental OpenAI shim for images)
  • Figures sent as raw base64 in the message images[] array (official REST format)
  • Structured JSON via Ollama format JSON schema (structured outputs)

This backend is WIP — schema enforcement and vision quality vary by model. Use a vision-capable model.

Environment: OLLAMA_HOST (default http://localhost:11434), OLLAMA_MODEL (default llama3.2-vision).

You can also point --base-url http://localhost:11434/v1 at Ollama's OpenAI-compatible API with --model llama3.2, but vision images must be base64 data URIs there; the native --ollama path is recommended.

Export formats (LLM training)

Format File Use case
csv .csv Spreadsheets, flat field/value
alpaca .alpaca.jsonl Instruction tuning (LLaMA-Factory, Axolotl)
sharegpt .sharegpt.jsonl Multi-turn chat fine-tuning
openai .openai.jsonl OpenAI fine-tuning messages format
qa .qa.jsonl Simple question/answer pairs

ShareGPT and OpenAI JSONL are preferred for chat models in 2026; Alpaca for single-turn extraction tasks.

Schema examples

File Use case
examples/invoice.schema.json Invoices
examples/receipt.schema.json Receipts
examples/purchase_order.schema.json Purchase orders

CLI

prettypipeline run FILE.pdf --schema SCHEMA.json
  -o, --output PATH           JSON output (also printed)
  --export csv,alpaca,...     comma-separated training exports
  --no-vision                 skip figure images to GPT
  --image-detail low|auto|high  vision token budget (default: low)
  --embedded-only             skip Baidu OCR supplement (embedded text only)
  --force-ocr                 OCR only — ignore embedded text
  --model, --base-url         OpenAI LLM settings
  --ollama                    local Ollama /api/chat (WIP)
  --ollama-host URL           Ollama server (default localhost:11434)

prettypipeline batch FILES... --schema SCHEMA.json --output-dir DIR
prettypipeline export RESULT.json --schema SCHEMA.json --format FORMAT -o OUT

Environment: OPENAI_API_KEY, PRETTYPIPELINE_MODEL, PRETTYPIPELINE_BASE_URL, OLLAMA_HOST, OLLAMA_MODEL.

Output

{
  "data": { "invoice_number": "INV-3337", "total": 93.5 },
  "needs_review": [],
  "source": "pdf_text",
  "_meta": {
    "version": "0.5.0",
    "elapsed_ms": 3200,
    "pages": 1,
    "vision_images": 1,
    "segments": { "text_chars": 842, "figures": 1 },
    "token_usage": { "prompt_tokens": 1100, "completion_tokens": 95, "total_tokens": 1195 }
  }
}

Programmatic use

from prettypipeline import run, segment_pdf, to_csv

result = run("invoice.pdf", "examples/invoice.schema.json", export_formats=["alpaca"], export_stem=Path("out.json"))
seg = segment_pdf("invoice.pdf")  # inspect text vs figures before calling GPT

Hardware

Device Role
NVIDIA CUDA Recommended for local OCR ([ocr] extra)
Apple Silicon MPS OCR supported; --force-ocr may degrade
CPU OCR works, slow
None Digital PDFs + GPT vision work without GPU

Development

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

License

MIT. Unlimited-OCR is also MIT.

Fixtures: Sliced Invoices sample, IRS Form W-9.

Metadata

Release files for prettypipeline-ocr 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prettypipeline-ocr 0.5.0
File Size Uploaded Provenance Actions
prettypipeline_ocr-0.5.0.tar.gz 62.9 kB Without provenance Details for prettypipeline_ocr-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prettypipeline-ocr 0.5.0
File Interpreter ABI Platform Actions
prettypipeline_ocr-0.5.0-py3-none-any.whl Python 3 none any Details for prettypipeline_ocr-0.5.0-py3-none-any.whl

Total release size: 87.6 kB

Release files / prettypipeline_ocr-0.5.0.tar.gz

Download URL prettypipeline_ocr-0.5.0.tar.gz
Size 62.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4a321f7602df62d103ddf9ce2e9f986ee54df35b952524eb16b5d49d1f4abb8d
BLAKE2b-256 checksum
How to use checksums
318b74a6eaa0e1477a46c5b209851a556ab211b93ff21a5cd6c7157a2e6ba7d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release files / prettypipeline_ocr-0.5.0-py3-none-any.whl

Download URL prettypipeline_ocr-0.5.0-py3-none-any.whl
Size 24.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
759c5d89e13b2579ee33c44c7487f5b08927ccf5f7ff6b65b0ee37cb604da210
BLAKE2b-256 checksum
How to use checksums
d5d6ee8ea3f6122db38e3164ca92a5c16cb9a2e4cf4652bc85801c5a2787d98c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Security for prettypipeline-ocr 0.5.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page