Skip to content

SDK

NextPDF Python

Citation-ready PDF extraction for Python — AI-agent-native, pure Python.

Free · MITPython 3.10+ · httpx · pydantic >= 2.0 · anyio >= 4.0 · click >= 8.0 · pypdf >= 4.0

Python

nextpdf extracts text, tables, and semantic structure from any PDF. Every extracted block carries a citation anchor with page index, confidence score, and optional bounding box. It defaults to a remote backend that talks to a NextPDF Connect server, with a beta local pypdf backend, and ships an MCP server for AI-agent integration.

How it fits

Built into your workflow

Citations on every block

The Python SDK extracts text, tables, and semantic structure from any PDF, and every block it returns carries a citation anchor: its page index, a confidence score, and an optional bounding box. Semantic AST extraction reads a tagged PDF's StructTree so structure travels with the content. Nothing is returned that you cannot trace back to its source.

Two interchangeable backends

Extraction runs through one of two interchangeable backends. The remote backend is the default and talks to a NextPDF Connect server over HTTP; the local pypdf backend (beta) runs fully offline. Swap between them without changing how you call the SDK.

Built for AI agents

The SDK ships an MCP server that exposes its extraction tools directly to AI agents. For high throughput, AsyncNextPDF builds on httpx.AsyncClient with connection pooling to drive concurrent requests, and a CLI (nextpdf extract, info, ast) covers scripted and terminal workflows.

Get started

Install

terminal
pip install nextpdf

In code

How it works

Quick start (remote backend)

python
from nextpdf import NextPDF

client = NextPDF(base_url="http://localhost:8080", api_key="your-key")

with open("document.pdf", "rb") as f:
    blocks = client.ast.extract_cited_text(f.read())

for block in blocks:
    page = block.citation.page_index
    conf = block.citation.confidence
    print(f"[page {page}, confidence {conf:.2f}] {block.text[:100]}")

MCP server config (Claude Code)

json
{
  "mcpServers": {
    "nextpdf": {
      "command": "python",
      "args": ["-m", "nextpdf.mcp"],
      "env": {
        "NEXTPDF_BASE_URL": "http://localhost:8080",
        "NEXTPDF_API_KEY": "your-key"
      }
    }
  }
}

CLI extraction

bash
# Extract text as JSON
nextpdf extract text document.pdf --base-url http://localhost:8080 --api-key your-key

# Extract tables as CSV
nextpdf extract tables invoice.pdf --format csv --base-url http://localhost:8080 --api-key your-key

Capabilities

What you get

  • Citation anchors — every block carries page index, confidence score, and optional bounding box
  • Semantic AST extraction — headings, sections, and lists from a PDF StructTree
  • Remote backend (default) — sends PDF bytes to a NextPDF Connect server over HTTP
  • Local backend (beta) — offline pypdf extraction with no remote server required
  • MCP server — pip install nextpdf[mcp] gives AI agents native PDF extraction tools
  • Async client — AsyncNextPDF uses httpx.AsyncClient with connection pooling
  • CLI — nextpdf extract/info/ast commands for terminal extraction

When to use it

Use the Python SDK when you need citation-tracked, structured extraction for AI pipelines, RAG systems, or document analysis where provenance matters. The remote backend (a NextPDF Connect server) is the recommended production path; a beta local backend works offline.