algorembrant/anthropic-pdf-parser
PDF Atomic Parser
Atomically parse and understand complex PDF documents using claude-opus-4-6 (Anthropic). Handles equations, graphs, algorithms, unique drawings, multi-column layouts, scanned pages, and 100+ page documents without hallucination.
Designed to be dropped into local agent pipelines as a callable module.
What Makes This Work
Claude processes PDFs natively through Anthropic's document API. Each page is sent as a base64-encoded PDF chunk (or rendered at 300 DPI in image mode) alongside a structured JSON extraction prompt. The model simultaneously sees:
- The rasterized visual content (charts, graphs, drawings, handwriting)
- The underlying text layer (searchable text, equations, captions)
This dual perception eliminates the need for separate OCR, layout parsers, or equation recognizers. The model returns fully structured JSON containing LaTeX equations, Markdown tables, verbatim algorithm code, and semantic figure descriptions per page.
Features
Requirements
- Python 3.10 or higher
- An Anthropic API key with access to
claude-opus-4-6 - No GPU required; all inference runs through the Anthropic API
External System Dependencies
PyMuPDF (installed via pip) requires no external system libraries on most platforms. On some Linux systems you may need:
sudo apt-get install -y libmupdf-devOn macOS:
brew install mupdfOn Windows: PyMuPDF ships with pre-built wheels on PyPI; no additional steps needed.
Installation
git clone https://github.com/algorembrant/pdf-atomic-parser.git
cd pdf-atomic-parser
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtSet your API key:
export ANTHROPIC_API_KEY="sk-ant-..." # Linux / macOS
set ANTHROPIC_API_KEY=sk-ant-... # Windows CMD
$env:ANTHROPIC_API_KEY="sk-ant-..." # Windows PowerShellQuick Start
Parse a PDF
python pdf_atomic_parser.py parse document.pdfOutputs document_parsed.json in the current directory.
Full Atomic Extraction (JSON + Markdown + Text)
python pdf_atomic_parser.py atomic document.pdf --output ./results/Ask a Question
python pdf_atomic_parser.py query document.pdf "What is the main loss function?"Extract Only Equations
python pdf_atomic_parser.py extract-equations document.pdfUse in an Agent Pipeline
from pdf_atomic_parser import AgentPDFInterface
agent = AgentPDFInterface(model="opus")
# Full structured parse
result = agent.parse("paper.pdf")
# Just equations as list of dicts
equations = agent.get_equations("paper.pdf")
for eq in equations:
print(f"Page {eq['page']}: {eq['latex']}")
# Just tables
tables = agent.get_tables("paper.pdf")
# Semantic query
answer = agent.ask("paper.pdf", "What datasets were used for evaluation?")
print(answer)Usage Reference
Command Overview
Global Options
parse / atomic Options
Output Schema
Each parsed document returns a DocumentResult with:
title,authors,abstract,document_summarypage_results: list ofPageResultper page
Each PageResult contains:
{
"page_number": 3,
"raw_text": "Full verbatim text...",
"summary": "This page describes...",
"section_headers": ["Introduction", "Related Work"],
"keywords": ["transformer", "attention", "BERT"],
"equations": [
{
"index": 0,
"latex": "\\mathcal{L} = -\\sum_{i} y_i \\log \\hat{y}_i",
"description": "Cross-entropy loss function",
"inline": false
}
],
"tables": [
{
"index": 0,
"markdown": "| Model | Accuracy |\n|---|---|\n| BERT | 94.2 |",
"json_data": [{"Model": "BERT", "Accuracy": "94.2"}],
"caption": "Table 1: Benchmark results"
}
],
"algorithms": [
{
"index": 0,
"name": "Algorithm 1: Backpropagation",
"language": "pseudocode",
"code": "for each layer l from L to 1:\n ...",
"description": "Gradient descent update rule"
}
],
"figures": [
{
"index": 0,
"figure_type": "line_chart",
"description": "Training loss over 100 epochs...",
"data_summary": "Y-axis: loss 0-2.0, X-axis: epoch 0-100...",
"caption": "Figure 2: Training curves"
}
]
}Choosing a Mode
Cost Estimate
Rough estimates per 100-page academic paper:
Use python pdf_atomic_parser.py estimate document.pdf for a per-document estimate.
Caching
Parsed pages are stored in ~/.cache/pdf_atomic_parser/.pdf_parser_cache.db. Re-running on the same document skips already-parsed pages automatically. The cache key is (document_SHA256, page_number, model, mode).
Project Structure
pdf-atomic-parser/
pdf_atomic_parser.py Main tool (single file, no splitting needed)
requirements.txt Python dependencies
README.md This file
model_card.yml Hugging Face model card
.gitignore
.gitattributesAuthor
algorembrant
License
MIT License. See LICENSE file.
