AIPDF: Minimalistic PDF to Markdown (and others), with GPT-like Multimodal Models
AIPDF is a stand-alone, minimalistic, yet powerful pure Python library that leverages multi-modal gen AI models (OpenAI, llama3 or compatible alternatives) to extract data from PDFs and convert it Markdown.
Installation
pip install aipdf
Quick Start
from aipdf import ocr
# Your API key
# This can also be via the environment variable AIPDF_API_KEY
api_key = 'your_api_key'
file = open('somepdf.pdf', 'rb')
markdown_pages = ocr(file, api_key)
By default, AIPDF attempts to determine which pages to send to the LLM based on their content and whether they can be processed using traditional text parsing. This is done to improve performance, and the behavior can be overridden by setting the use_llm_for_all parameter to True:
markdown_pages = ocr(file, api_key, use_llm_for_all=True)
Every call to the LLM is made in parallel, so the processing time is significantly reduced. The above function will make these parallel calls using threading, however, it is also possible to make asynchronous calls instead by using the ocr_async function:
from aipdf import ocr_async
import asyncio
# Your API key
# This can also be via the environment variable AIPDF_API_KEY
api_key = 'your_api_key'
file = open('somepdf.pdf', 'rb')
async def main():
markdown_pages = await ocr_async(file, api_key)
return markdown_pages
markdown_pages = asyncio.run(main())
The maximum number of concurrent requests made to the LLM can also be controlled via the AIPDF_MAX_CONCURRENT_REQUESTS environment variable. By default, there is no limit set.
Ollama
You can use with any ollama multi-modal models
ocr(pdf_file, api_key='ollama', model="llama3.2", base_url= 'http://localhost:11434/v1', prompt=...)
Any file system
We chose that you pass a file object, because that way it is flexible for you to use this with any type of file system, s3, localfiles, urls etc
From url
pdf_file = io.BytesIO(requests.get('https://arxiv.org/pdf/2410.02467').content)
# extract
pages = ocr(pdf_file, api_key, prompt="extract tables, return each table in json")
From S3
s3 = boto3.client('s3', config=Config(signature_version='s3v4'),
aws_access_key_id=access_token,
aws_secret_access_key='', # Not needed for token-based auth
aws_session_token=access_token)
pdf_file = io.BytesIO(s3.get_object(Bucket=bucket_name, Key=object_key)['Body'].read())
# extract
pages = ocr(pdf_file, api_key, prompt="extract charts data, turn it into tables that represent the variables in the chart")
Why AIPDF?
- Simplicity: AIPDF provides a straightforward function, it requires minimal setup, dependencies and configuration.
- Power of AI: Leverages state-of-the-art multi modal models (gpt, llama, ..).
- Customizable: Tailor the extraction process to your specific needs with custom prompts.
- Efficient: Utilizes parallel processing for faster extraction of multi-page PDFs.
Requirements
- Python 3.7+
We will keep this super clean, only 2 required libraries:
- openai library to talk to completion endpoints
- PyMuPDF library for traditional text parsing and image conversion
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any problems or have any questions, please open an issue on the GitHub repository.
AIPDF makes PDF data extraction simple, flexible, and powerful. Try it out and simplify your PDF processing workflow today!
Metadata
Release files for aipdf 0.0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aipdf-0.0.7.2.tar.gz | 6.5 MB | Without provenance | Details for aipdf-0.0.7.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aipdf-0.0.7.2-py3-none-any.whl | Python 3 | none | any | Details for aipdf-0.0.7.2-py3-none-any.whl |
Total release size: 6.5 MB
Release files / aipdf-0.0.7.2.tar.gz
| Download URL | aipdf-0.0.7.2.tar.gz |
|---|---|
| Size | 6.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b45a8a6472bc7087adf45e2578df9397a43c5d129742609c887ce1990cec884a
|
|
BLAKE2b-256 checksum How to use checksums |
756bd36c1950a61fb8e7b56d72500cbc29e7f4e325563b53065597bd3ed340f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / aipdf-0.0.7.2-py3-none-any.whl
| Download URL | aipdf-0.0.7.2-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5885021eea1fd66a5c18799cd954dc4a534a7555225386fae6b14eb2e4033515
|
|
BLAKE2b-256 checksum How to use checksums |
de14bc12c0cb71d34c65c62ee9c0bfe6714f2e6514de16ea1959f4d7c1705cff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Security for aipdf 0.0.7.2
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.