Skip to main content

spacypdfreader

Easy PDF to text to spaCy text extraction in Python.

Package version PyPI - Downloads pytest


Documentation: https://samedwardes.github.io/spacypdfreader/

Source code: https://github.com/SamEdwardes/spacypdfreader

PyPi: https://pypi.org/project/spacypdfreader/

spaCy universe: https://spacy.io/universe/project/spacypdfreader


spacypdfreader is a python library for extracting text from PDF documents into spaCy Doc objects. When you use spacypdfreader the token and doc objects from spacy are annotated with additional information about the pdf.

The key features are:

  • PDF to spaCy Doc object: Convert a PDF document directly into a spaCy Doc object.
  • Custom spaCy attributes and methods:
    • token._.page_number
    • doc._.page_range
    • doc._.first_page
    • doc._.last_page
    • doc._.pdf_file_name
    • doc._.page(int)
  • Multiple parsers: Select between multiple built in PDF to text parsers or bring your own PDF to text parser.

Installation

Install spacypdfreader using pip:

pip install spacypdfreader

To install with the required pytesseract dependencies:

pip install 'spacypdfreader[pytesseract]'

Usage

import spacy

from spacypdfreader import pdf_reader

nlp = spacy.load("en_core_web_sm")
doc = pdf_reader("tests/data/test_pdf_01.pdf", nlp)

# Get the page number of any token.
print(doc[0]._.page_number)  # 1
print(doc[-1]._.page_number)  # 4

# Get page meta data about the PDF document.
print(doc._.pdf_file_name)  # "tests/data/test_pdf_01.pdf"
print(doc._.page_range)  # (1, 4)
print(doc._.first_page)  # 1
print(doc._.last_page)  # 4

# Get all of the text from a specific PDF page.
print(doc._.page(4))  # "able to display the destination page (unless..."

What is spaCy?

spaCy is a natural language processing (NLP) tool. It can be used to perform a variety of NLP tasks. For more information check out the excellent documentation at https://spacy.io.

Implementation Notes

spaCyPDFreader behaves a little bit different than your typical spaCy custom component. Typically a spaCy component should receive and return a spacy.tokens.Doc object.

spaCyPDFreader breaks this convention because the text must first be extracted from the PDF. Instead pdf_reader takes a path to a PDF file and a spacy.Language object as parameters and returns a spacy.tokens.Doc object. This allows users an easy way to extract text from PDF files while still allowing them use and customize all of the features spacy has to offer by allowing you to pass in the spacy.Language object.

Example of a "traditional" spaCy pipeline component negspaCy:

import spacy
from negspacy.negation import Negex

nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("negex", config={"ent_types": ["PERSON", "ORG"]})
doc = nlp("She does not like Steve Jobs but likes Apple products.")

Example of spaCyPDFreader usage:

import spacy

from spacypdfreader import pdf_reader

nlp = spacy.load("en_core_web_sm")

doc = pdf_reader("tests/data/test_pdf_01.pdf", nlp)

Note that the nlp.add_pipe is not used by spaCyPDFreader.

Metadata

Release files for spacypdfreader 0.4.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 spacypdfreader 0.4.0
File Size Uploaded Provenance
spacypdfreader-0.4.0.tar.gz 6.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spacypdfreader 0.4.0
File Interpreter ABI Platform
spacypdfreader-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / spacypdfreader-0.4.0.tar.gz

Download URL spacypdfreader-0.4.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c94b812511507c932cb0f14c615d67d246c86227071c03547dbffc76848b646c
BLAKE2b-256 checksum
How to use checksums
e8186ba1275ce957a132f77797c73eef70c2438bd2703d8673d5dfb7d9eaaedf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release files / spacypdfreader-0.4.0-py3-none-any.whl

Download URL spacypdfreader-0.4.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24f87da16b4f2cf09caf817560d960c453f056a3dff631d07ac5d072cfcd3296
BLAKE2b-256 checksum
How to use checksums
ff3962a0cb4ba4f064aaa92efe66987b452c4b928739ca7f58d74f4444a7ebfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Security for spacypdfreader 0.4.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.

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