A Python client for the ReadPDFs API
Project description
ReadPDFs
A Python client for the ReadPDFs API that allows you to process PDF files and convert them to markdown.
Installation
pip install readpdfs
Usage
Basic Client Usage
from readpdfs import ReadPDFs
# Initialize the client
client = ReadPDFs(api_key="your_api_key")
# Process a PDF from a URL
result = client.process_pdf(pdf_url="https://example.com/document.pdf")
# Process a local PDF file
result = client.process_pdf(file_path="path/to/local/document.pdf")
# Process from file content
with open("document.pdf", "rb") as f:
content = f.read()
result = client.process_pdf(file_content=content, filename="document.pdf")
# Fetch markdown content
markdown = client.fetch_markdown(url="https://api.readpdfs.com/documents/123/markdown")
# Get user documents
documents = client.get_user_documents(clerk_id="user_123")
FastAPI Integration
from fastapi import FastAPI, File, UploadFile, HTTPException
from readpdfs import ReadPDFs
from typing import Optional
app = FastAPI()
client = ReadPDFs(api_key="your_api_key")
@app.post("/process-pdf")
async def process_pdf(
pdf_url: Optional[str] = None,
file: Optional[UploadFile] = File(None),
quality: str = "standard"
):
try:
if pdf_url and file:
raise HTTPException(
status_code=400,
detail="Provide either pdf_url or file, not both"
)
if pdf_url:
result = client.process_pdf(pdf_url=pdf_url, quality=quality)
elif file:
content = await file.read()
result = client.process_pdf(
file_content=content,
filename=file.filename,
quality=quality
)
else:
raise HTTPException(
status_code=400,
detail="Either pdf_url or file must be provided"
)
return result
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
Features
- Process PDFs from URLs, local files, or file content
- Convert PDFs to markdown
- Fetch markdown content
- Retrieve user documents
- Configurable processing quality
- FastAPI integration support
Requirements
- Python 3.7+
- requests library
For FastAPI integration:
- fastapi
- python-multipart
- uvicorn
API Examples
cURL
# Process PDF from URL
curl -X POST "http://localhost:8000/process-pdf?pdf_url=https://example.com/document.pdf&quality=high"
# Upload PDF file
curl -X POST "http://localhost:8000/process-pdf?quality=high" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/local/document.pdf"
Python Requests
import requests
# URL method
response = requests.post(
"http://localhost:8000/process-pdf",
params={"pdf_url": "https://example.com/document.pdf", "quality": "high"}
)
# File upload method
with open("document.pdf", "rb") as f:
response = requests.post(
"http://localhost:8000/process-pdf",
params={"quality": "high"},
files={"file": f}
)
result = response.json()
License
This project is licensed under the MIT License - see the LICENSE file for details.
This update:
1. Added the new file content processing method
2. Included a complete FastAPI integration example
3. Added API examples using cURL and Python requests
4. Updated the requirements section to include FastAPI-related packages
5. Reorganized the usage section to separate basic client usage from FastAPI integration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
readpdfs-0.1.4.tar.gz
(4.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file readpdfs-0.1.4.tar.gz.
File metadata
- Download URL: readpdfs-0.1.4.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed2a2b18a5fc15344c9260f868a2f4f424b3323ed9579517bb318de6a32aa7f8
|
|
| MD5 |
35919239e47168f37fea6334a9c8c57f
|
|
| BLAKE2b-256 |
87dbf0c68a641400371db8e4a82a00b541ae4111501c45d9434c86bc50d2e94e
|
File details
Details for the file readpdfs-0.1.4-py3-none-any.whl.
File metadata
- Download URL: readpdfs-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fffb2ae4dd4363144dddd096c438dadb7f66ddba849eeef4291717cef91dc319
|
|
| MD5 |
4258f752544c4e9d0b4e4d7a8fb7bde2
|
|
| BLAKE2b-256 |
f4a342c1924e883e7416684198dcfbd6175296f9c45a8d94743522775e1c5098
|