pdf-invoice-extractor 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pdf_invoice_extractor-0.1.0/PKG-INFO +43 -0
- pdf_invoice_extractor-0.1.0/README.md +32 -0
- pdf_invoice_extractor-0.1.0/pdf_invoice_extractor/__init__.py +3 -0
- pdf_invoice_extractor-0.1.0/pdf_invoice_extractor/client.py +110 -0
- pdf_invoice_extractor-0.1.0/pdf_invoice_extractor.egg-info/PKG-INFO +43 -0
- pdf_invoice_extractor-0.1.0/pdf_invoice_extractor.egg-info/SOURCES.txt +9 -0
- pdf_invoice_extractor-0.1.0/pdf_invoice_extractor.egg-info/dependency_links.txt +1 -0
- pdf_invoice_extractor-0.1.0/pdf_invoice_extractor.egg-info/requires.txt +1 -0
- pdf_invoice_extractor-0.1.0/pdf_invoice_extractor.egg-info/top_level.txt +1 -0
- pdf_invoice_extractor-0.1.0/pyproject.toml +18 -0
- pdf_invoice_extractor-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pdf-invoice-extractor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for extracting structured JSON data from PDF invoices, receipts, and URLs via RapidAPI.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://rapidapi.com
|
|
7
|
+
Keywords: pdf,invoice,receipt,ocr,parser,accounting,rapidapi
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: requests>=2.28.0
|
|
11
|
+
|
|
12
|
+
# PDF Invoice & Receipt Data Extractor (Python SDK)
|
|
13
|
+
|
|
14
|
+
Extract vendor details, invoice numbers, dates, line items, taxes, and totals from PDF files, public PDF URLs, or raw receipt text using the [PDF Invoice & Receipt Data Extractor API](https://rapidapi.com).
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
```bash
|
|
18
|
+
pip install pdf-invoice-extractor
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
1. Get a free API key from [RapidAPI](https://rapidapi.com).
|
|
23
|
+
2. Extract structured JSON from text, URLs, or local PDFs:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from pdf_invoice_extractor import PDFInvoiceExtractorClient
|
|
27
|
+
|
|
28
|
+
client = PDFInvoiceExtractorClient(api_key="YOUR_RAPIDAPI_KEY")
|
|
29
|
+
|
|
30
|
+
# 1. Extract from raw invoice/receipt text
|
|
31
|
+
data = client.parse_invoice_text("""ACME Cloud Services Inc.
|
|
32
|
+
Invoice #INV-2026-8841
|
|
33
|
+
Total Due: \$295.00 USD""")
|
|
34
|
+
print(data)
|
|
35
|
+
|
|
36
|
+
# 2. Extract from a PDF URL
|
|
37
|
+
url_data = client.parse_pdf_url("https://example.com")
|
|
38
|
+
print(url_data)
|
|
39
|
+
|
|
40
|
+
# 3. Extract from a local PDF file
|
|
41
|
+
file_data = client.parse_pdf_file("invoice.pdf")
|
|
42
|
+
print(file_data)
|
|
43
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# PDF Invoice & Receipt Data Extractor (Python SDK)
|
|
2
|
+
|
|
3
|
+
Extract vendor details, invoice numbers, dates, line items, taxes, and totals from PDF files, public PDF URLs, or raw receipt text using the [PDF Invoice & Receipt Data Extractor API](https://rapidapi.com).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```bash
|
|
7
|
+
pip install pdf-invoice-extractor
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
1. Get a free API key from [RapidAPI](https://rapidapi.com).
|
|
12
|
+
2. Extract structured JSON from text, URLs, or local PDFs:
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from pdf_invoice_extractor import PDFInvoiceExtractorClient
|
|
16
|
+
|
|
17
|
+
client = PDFInvoiceExtractorClient(api_key="YOUR_RAPIDAPI_KEY")
|
|
18
|
+
|
|
19
|
+
# 1. Extract from raw invoice/receipt text
|
|
20
|
+
data = client.parse_invoice_text("""ACME Cloud Services Inc.
|
|
21
|
+
Invoice #INV-2026-8841
|
|
22
|
+
Total Due: \$295.00 USD""")
|
|
23
|
+
print(data)
|
|
24
|
+
|
|
25
|
+
# 2. Extract from a PDF URL
|
|
26
|
+
url_data = client.parse_pdf_url("https://example.com")
|
|
27
|
+
print(url_data)
|
|
28
|
+
|
|
29
|
+
# 3. Extract from a local PDF file
|
|
30
|
+
file_data = client.parse_pdf_file("invoice.pdf")
|
|
31
|
+
print(file_data)
|
|
32
|
+
```
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import os
|
|
3
|
+
import requests
|
|
4
|
+
from typing import Any, Dict
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class InvoiceExtractorError(Exception):
|
|
8
|
+
"""Raised when the PDF Invoice & Receipt Data Extractor API returns an error."""
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PDFInvoiceExtractorClient:
|
|
13
|
+
"""Official Python wrapper for the PDF Invoice & Receipt Data Extractor API on RapidAPI."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
api_key: str,
|
|
18
|
+
host: str = "://rapidapi.com",
|
|
19
|
+
timeout: int = 30,
|
|
20
|
+
):
|
|
21
|
+
if not api_key:
|
|
22
|
+
raise ValueError("A valid RapidAPI key is required.")
|
|
23
|
+
self.base_url = f"https://{host}"
|
|
24
|
+
self.timeout = timeout
|
|
25
|
+
self.headers = {
|
|
26
|
+
"x-rapidapi-key": api_key,
|
|
27
|
+
"x-rapidapi-host": host,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def _handle_response(self, response: requests.Response) -> Dict[str, Any]:
|
|
31
|
+
try:
|
|
32
|
+
response.raise_for_status()
|
|
33
|
+
return response.json()
|
|
34
|
+
except requests.exceptions.HTTPError as e:
|
|
35
|
+
raise InvoiceExtractorError(
|
|
36
|
+
f"API HTTP Error ({response.status_code}): {response.text}"
|
|
37
|
+
) from e
|
|
38
|
+
except ValueError as e:
|
|
39
|
+
raise InvoiceExtractorError(f"Invalid JSON response: {response.text}") from e
|
|
40
|
+
|
|
41
|
+
def parse_invoice_text(self, text: str) -> Dict[str, Any]:
|
|
42
|
+
"""Extract structured invoice/receipt fields from raw OCR or plain text."""
|
|
43
|
+
if not text or not isinstance(text, str):
|
|
44
|
+
raise ValueError("A valid invoice text string is required.")
|
|
45
|
+
|
|
46
|
+
url = f"{self.base_url}/v1/parse-invoice-text"
|
|
47
|
+
headers = {**self.headers, "Content-Type": "application/json"}
|
|
48
|
+
try:
|
|
49
|
+
response = requests.post(
|
|
50
|
+
url=url,
|
|
51
|
+
headers=headers,
|
|
52
|
+
json={"text": text},
|
|
53
|
+
timeout=self.timeout,
|
|
54
|
+
)
|
|
55
|
+
return self._handle_response(response)
|
|
56
|
+
except requests.exceptions.RequestException as e:
|
|
57
|
+
raise InvoiceExtractorError(f"Network error connecting to RapidAPI: {e}") from e
|
|
58
|
+
|
|
59
|
+
def parse_pdf_url(self, pdf_url: str) -> Dict[str, Any]:
|
|
60
|
+
"""Download and extract structured invoice/receipt fields from a public PDF URL."""
|
|
61
|
+
if not pdf_url or not isinstance(pdf_url, str):
|
|
62
|
+
raise ValueError("A valid PDF URL is required.")
|
|
63
|
+
|
|
64
|
+
url = f"{self.base_url}/v1/parse-pdf-url"
|
|
65
|
+
headers = {**self.headers, "Content-Type": "application/json"}
|
|
66
|
+
try:
|
|
67
|
+
response = requests.post(
|
|
68
|
+
url=url,
|
|
69
|
+
headers=headers,
|
|
70
|
+
json={"pdf_url": pdf_url},
|
|
71
|
+
timeout=self.timeout,
|
|
72
|
+
)
|
|
73
|
+
return self._handle_response(response)
|
|
74
|
+
except requests.exceptions.RequestException as e:
|
|
75
|
+
raise InvoiceExtractorError(f"Network error connecting to RapidAPI: {e}") from e
|
|
76
|
+
|
|
77
|
+
def parse_pdf_file(
|
|
78
|
+
self,
|
|
79
|
+
file_path: str,
|
|
80
|
+
as_multipart: bool = True,
|
|
81
|
+
base64_field: str = "file_base64",
|
|
82
|
+
) -> Dict[str, Any]:
|
|
83
|
+
"""Extract structured invoice/receipt data from a local PDF file."""
|
|
84
|
+
if not os.path.isfile(file_path):
|
|
85
|
+
raise FileNotFoundError(f"PDF file not found: {file_path}")
|
|
86
|
+
|
|
87
|
+
url = f"{self.base_url}/v1/parse-pdf-file"
|
|
88
|
+
try:
|
|
89
|
+
if as_multipart:
|
|
90
|
+
with open(file_path, "rb") as f:
|
|
91
|
+
files = {"file": (os.path.basename(file_path), f, "application/pdf")}
|
|
92
|
+
response = requests.post(
|
|
93
|
+
url=url,
|
|
94
|
+
headers=self.headers,
|
|
95
|
+
files=files,
|
|
96
|
+
timeout=self.timeout,
|
|
97
|
+
)
|
|
98
|
+
else:
|
|
99
|
+
with open(file_path, "rb") as f:
|
|
100
|
+
encoded = base64.b64encode(f.read()).decode("utf-8")
|
|
101
|
+
headers = {**self.headers, "Content-Type": "application/json"}
|
|
102
|
+
response = requests.post(
|
|
103
|
+
url=url,
|
|
104
|
+
headers=headers,
|
|
105
|
+
json={base64_field: encoded, "filename": os.path.basename(file_path)},
|
|
106
|
+
timeout=self.timeout,
|
|
107
|
+
)
|
|
108
|
+
return self._handle_response(response)
|
|
109
|
+
except requests.exceptions.RequestException as e:
|
|
110
|
+
raise InvoiceExtractorError(f"Network error connecting to RapidAPI: {e}") from e
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pdf-invoice-extractor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for extracting structured JSON data from PDF invoices, receipts, and URLs via RapidAPI.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://rapidapi.com
|
|
7
|
+
Keywords: pdf,invoice,receipt,ocr,parser,accounting,rapidapi
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: requests>=2.28.0
|
|
11
|
+
|
|
12
|
+
# PDF Invoice & Receipt Data Extractor (Python SDK)
|
|
13
|
+
|
|
14
|
+
Extract vendor details, invoice numbers, dates, line items, taxes, and totals from PDF files, public PDF URLs, or raw receipt text using the [PDF Invoice & Receipt Data Extractor API](https://rapidapi.com).
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
```bash
|
|
18
|
+
pip install pdf-invoice-extractor
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
1. Get a free API key from [RapidAPI](https://rapidapi.com).
|
|
23
|
+
2. Extract structured JSON from text, URLs, or local PDFs:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from pdf_invoice_extractor import PDFInvoiceExtractorClient
|
|
27
|
+
|
|
28
|
+
client = PDFInvoiceExtractorClient(api_key="YOUR_RAPIDAPI_KEY")
|
|
29
|
+
|
|
30
|
+
# 1. Extract from raw invoice/receipt text
|
|
31
|
+
data = client.parse_invoice_text("""ACME Cloud Services Inc.
|
|
32
|
+
Invoice #INV-2026-8841
|
|
33
|
+
Total Due: \$295.00 USD""")
|
|
34
|
+
print(data)
|
|
35
|
+
|
|
36
|
+
# 2. Extract from a PDF URL
|
|
37
|
+
url_data = client.parse_pdf_url("https://example.com")
|
|
38
|
+
print(url_data)
|
|
39
|
+
|
|
40
|
+
# 3. Extract from a local PDF file
|
|
41
|
+
file_data = client.parse_pdf_file("invoice.pdf")
|
|
42
|
+
print(file_data)
|
|
43
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
pdf_invoice_extractor/__init__.py
|
|
4
|
+
pdf_invoice_extractor/client.py
|
|
5
|
+
pdf_invoice_extractor.egg-info/PKG-INFO
|
|
6
|
+
pdf_invoice_extractor.egg-info/SOURCES.txt
|
|
7
|
+
pdf_invoice_extractor.egg-info/dependency_links.txt
|
|
8
|
+
pdf_invoice_extractor.egg-info/requires.txt
|
|
9
|
+
pdf_invoice_extractor.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.28.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pdf_invoice_extractor
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pdf-invoice-extractor"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python SDK for extracting structured JSON data from PDF invoices, receipts, and URLs via RapidAPI."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["pdf", "invoice", "receipt", "ocr", "parser", "accounting", "rapidapi"]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"requests>=2.28.0"
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://rapidapi.com"
|