Skip to main content

A more intuitive interface for working with PDFs

Project description

Natural PDF

CI

A friendly library for working with PDFs, built on top of pdfplumber.

Natural PDF lets you find and extract content from PDFs using simple code that makes sense.

Installation

pip install natural-pdf

Need OCR, layout models, or other add-ons? Install what you need:

pip install easyocr                 # EasyOCR engine
pip install "natural-pdf[paddle]"   # PaddleOCR stack
pip install "surya-ocr<0.15"         # Surya OCR engine
pip install doclayout_yolo          # YOLO layout detection
pip install "natural-pdf[export]"   # PDF export, deskew
pip install "natural-pdf[all]"      # Everything

More details in the installation guide.

Quick Start

from natural_pdf import PDF

# Open a PDF
pdf = PDF('https://github.com/jsoma/natural-pdf/raw/refs/heads/main/pdfs/01-practice.pdf')
page = pdf.pages[0]

# Extract all of the text on the page
page.extract_text()

# Find elements using CSS-like selectors
heading = page.find('text:contains("Summary"):bold')

# Extract content below the heading
content = heading.below().extract_text()

# Examine all the bold text on the page
page.find_all('text:bold').show()

# Exclude parts of the page from selectors/extractors
header = page.find('text:contains("CONFIDENTIAL")').above()
footer = page.find_all('line')[-1].below()
page.add_exclusion(header)
page.add_exclusion(footer)

# Extract clean text from the page ignoring exclusions
clean_text = page.extract_text()

And as a fun bonus, page.viewer() will provide an interactive method to explore the PDF.

Key Features

Natural PDF offers a range of features for working with PDFs:

  • CSS-like Selectors: Find elements using intuitive query strings (page.find('text:bold')).
  • Spatial Navigation: Select content relative to other elements (heading.below(), element.select_until(...)).
  • Text & Table Extraction: Get clean text or structured table data, automatically handling exclusions.
  • OCR Integration: Extract text from scanned documents using engines like EasyOCR, PaddleOCR, or Surya.
  • Layout Analysis: Detect document structures (titles, paragraphs, tables) using various engines (e.g., YOLO, Paddle, LLM via API).
  • Document QA: Ask natural language questions about your document's content.
  • Semantic Search: Index PDFs and find relevant pages or documents based on semantic meaning using Haystack.
  • Visual Debugging: Highlight elements and use an interactive viewer or save images to understand your selections.

Learn More

Dive deeper into the features and explore advanced usage in the Complete Documentation.

Extending Natural PDF

Natural PDF now exposes its pluggable engines through small helper functions so you rarely have to touch the core registry directly. Two handy entry points:

from natural_pdf.tables import register_table_function

def table_delim(region, *, context=None, **kwargs):
    # return a TableResult or list-of-lists
    ...

register_table_function("table_delim", table_delim)
from natural_pdf.selectors import register_selector_engine

class DebugSelectorEngine:
    def query(self, *, context, selector, options):
        ...

register_selector_engine("debug", lambda **_: DebugSelectorEngine())

Best friends

Natural PDF sits on top of a lot of fantastic tools and mdoels, some of which are:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

natural_pdf-0.5.4.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

natural_pdf-0.5.4-py3-none-any.whl (826.6 kB view details)

Uploaded Python 3

File details

Details for the file natural_pdf-0.5.4.tar.gz.

File metadata

  • Download URL: natural_pdf-0.5.4.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for natural_pdf-0.5.4.tar.gz
Algorithm Hash digest
SHA256 842ca335977ef858486eb8479785ee29e49d90c69509a0577a5ec9336d20d1e2
MD5 fa87090bb0d512446e5ef2303235aadd
BLAKE2b-256 940d343624a24c87efc78a716eeac37dbf1705076dc93fae8bf83b56a7ae9005

See more details on using hashes here.

File details

Details for the file natural_pdf-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: natural_pdf-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 826.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for natural_pdf-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5cee2486832632dfeb01bde6fdd2d370528e94bea9987f35c66db88e7555e61a
MD5 9668f9b7dc6d5ea46d863dd243d60cd0
BLAKE2b-256 f61b1da2716901a017f55836a9e5c5d05b846c04261c0ec201fac906894021fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page