pdfgate 0.0.2__py3-none-any.whl
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.
- pdfgate/__about__.py +6 -0
- pdfgate/__init__.py +81 -0
- pdfgate/config.py +18 -0
- pdfgate/dict_keys_converter.py +54 -0
- pdfgate/errors.py +9 -0
- pdfgate/http_client.py +76 -0
- pdfgate/params.py +308 -0
- pdfgate/pdfgate.py +370 -0
- pdfgate/request_builder.py +252 -0
- pdfgate/response_builder.py +23 -0
- pdfgate/responses.py +37 -0
- pdfgate/url_builder.py +81 -0
- pdfgate-0.0.2.dist-info/METADATA +264 -0
- pdfgate-0.0.2.dist-info/RECORD +16 -0
- pdfgate-0.0.2.dist-info/WHEEL +4 -0
- pdfgate-0.0.2.dist-info/licenses/LICENSE +21 -0
pdfgate/url_builder.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""URL construction for PDFGate API endpoints."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class URLBuilder:
|
|
5
|
+
"""Helper class to build URLs for the PDFGate API."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, domain: str):
|
|
8
|
+
"""Create a URL builder using the provided API domain."""
|
|
9
|
+
self.domain = domain
|
|
10
|
+
|
|
11
|
+
def get_document_url(self, document_id: str) -> str:
|
|
12
|
+
"""Build the URL for accessing a document.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
document_id:
|
|
16
|
+
ID of the document.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
Full URL to access the document.
|
|
20
|
+
"""
|
|
21
|
+
return f"{self.domain}/document/{document_id}"
|
|
22
|
+
|
|
23
|
+
def get_file_url(self, document_id: str) -> str:
|
|
24
|
+
"""Build the URL for downloading a document.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
document_id:
|
|
28
|
+
ID of the document.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
Full URL to download the document.
|
|
32
|
+
"""
|
|
33
|
+
return f"{self.domain}/file/{document_id}"
|
|
34
|
+
|
|
35
|
+
def generate_pdf_url(self) -> str:
|
|
36
|
+
"""Build the URL for generating a PDF.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Full URL to generate a PDF.
|
|
40
|
+
"""
|
|
41
|
+
return f"{self.domain}/v1/generate/pdf"
|
|
42
|
+
|
|
43
|
+
def flatten_pdf_url(self) -> str:
|
|
44
|
+
"""Build the URL for flattening a PDF.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
Full URL to flatten a PDF.
|
|
48
|
+
"""
|
|
49
|
+
return f"{self.domain}/forms/flatten"
|
|
50
|
+
|
|
51
|
+
def extract_pdf_form_data_url(self) -> str:
|
|
52
|
+
"""Build the URL for extracting PDF form data.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
Full URL to extract PDF form data.
|
|
56
|
+
"""
|
|
57
|
+
return f"{self.domain}/forms/extract-data"
|
|
58
|
+
|
|
59
|
+
def protect_pdf_url(self) -> str:
|
|
60
|
+
"""Build the URL for encrypting a PDF.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
Full URL to encrypt a PDF.
|
|
64
|
+
"""
|
|
65
|
+
return f"{self.domain}/protect/pdf"
|
|
66
|
+
|
|
67
|
+
def compress_pdf_url(self) -> str:
|
|
68
|
+
"""Build the URL for compressing a PDF.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Full URL to compress a PDF.
|
|
72
|
+
"""
|
|
73
|
+
return f"{self.domain}/compress/pdf"
|
|
74
|
+
|
|
75
|
+
def watermark_pdf_url(self) -> str:
|
|
76
|
+
"""Build the URL for watermarking a PDF.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Full URL to watermark a PDF.
|
|
80
|
+
"""
|
|
81
|
+
return f"{self.domain}/watermark/pdf"
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pdfgate
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: PDFGate's official Python SDK
|
|
5
|
+
Project-URL: Documentation, https://github.com/pdfgate/pdfgate-sdk-python#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/pdfgate/pdfgate-sdk-python/issues
|
|
7
|
+
Project-URL: Source, https://github.com/pdfgate/pdfgate-sdk-python
|
|
8
|
+
Author-email: Fernando Gasperi <fgasperijabalera@gmail.com>, Demetra Theodorou <demtra@pdfgate.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Requires-Dist: httpx
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# PDFGate's official Python SDK
|
|
25
|
+
|
|
26
|
+
PDFGate lets you generate, process, and secure PDFs via a simple API:
|
|
27
|
+
|
|
28
|
+
- HTML or URL to PDF
|
|
29
|
+
- Fillable forms
|
|
30
|
+
- Flatten, compress, watermark, protect PDFs
|
|
31
|
+
- Extract PDF form data
|
|
32
|
+
|
|
33
|
+
📘 Documentation: https://pdfgate.com/documentation<br>
|
|
34
|
+
🔑 Dashboard & API keys: https://dashboard.pdfgate.com
|
|
35
|
+
|
|
36
|
+
## pdfgate-sdk-python
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/pdfgate-sdk-python)
|
|
39
|
+
[](https://pypi.org/project/pdfgate-sdk-python)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Table of Contents
|
|
43
|
+
|
|
44
|
+
- [Installation](#installation)
|
|
45
|
+
- [Quick start](#quick-start)
|
|
46
|
+
- [Sync & Async](#sync--async)
|
|
47
|
+
- [Responses](#responses)
|
|
48
|
+
- [Examples](#examples)
|
|
49
|
+
- [Development](#development)
|
|
50
|
+
- [Support](#support)
|
|
51
|
+
- [License](#license)
|
|
52
|
+
|
|
53
|
+
# Installation
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
pip install pdfgate
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
# Quick start
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import os
|
|
63
|
+
|
|
64
|
+
from pdfgate import PDFGate, GeneratePDFParams
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
client = PDFGate(api_key=os.getenv("PDFGATE_API_KEY"))
|
|
68
|
+
params = GeneratePDFParams(url="https://example.com")
|
|
69
|
+
pdf = client.generate_pdf(params)
|
|
70
|
+
|
|
71
|
+
with open("output.pdf", "wb") as f:
|
|
72
|
+
f.write(pdf)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
# Sync & Async
|
|
76
|
+
|
|
77
|
+
There are sync and async versions of all methods, the only difference is that the method name has an `async` suffix:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
document_response = client.get_document(GetDocumentParams(document_id=document_id))
|
|
81
|
+
|
|
82
|
+
# VS
|
|
83
|
+
|
|
84
|
+
document_response = await client.get_document_async(GetDocumentParams(document_id=document_id))
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Other than that, nothing changes and the interfaces are the same.
|
|
88
|
+
|
|
89
|
+
# Responses
|
|
90
|
+
|
|
91
|
+
The two response types for most endpoints are either the raw bytes of the
|
|
92
|
+
PDF file or the documents metadata that you can use to query or download later:
|
|
93
|
+
|
|
94
|
+
- file: this is represented by `bytes` and it can be saved directly into a file.
|
|
95
|
+
- `PDFGateDocument`: this is a `TypedDict` that holds all the metadata of the file including its `id`, and a `file_url` to download it if it was requested by specifying `pre_signed_url_expires_in` in the request.
|
|
96
|
+
|
|
97
|
+
# Examples
|
|
98
|
+
|
|
99
|
+
## Generate PDF
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
params = GeneratePDFParams(html="<h1>Hello from PDFGate!</h1>")
|
|
103
|
+
pdf = client.generate_pdf(params)
|
|
104
|
+
|
|
105
|
+
with open("output.pdf", "wb") as f:
|
|
106
|
+
f.write(pdf)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Get document metadata
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
document_response = client.get_document(GetDocumentParams(document_id=document_id))
|
|
113
|
+
|
|
114
|
+
assert document_response = {
|
|
115
|
+
"id" : "6642381c5c61"
|
|
116
|
+
"status" : DocumentStatus.COMPLETED
|
|
117
|
+
"type" : DocumentType.FROM_HTML,
|
|
118
|
+
"file_url" : "https://api.pdfgate.com/file/open/:preSignedUrlToken"
|
|
119
|
+
"size" : 1620006
|
|
120
|
+
"createdAt" : datetime(2024,02,13, 15, 56, 12, 607)"
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Download a stored PDF file
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
file_content = client.get_file(GetFileParams(document_id=document_id))
|
|
128
|
+
|
|
129
|
+
with open("output.pdf", "wb") as f:
|
|
130
|
+
f.write(pdf)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Flatten a PDF (make form-fields non-editable)
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
flatten_pdf_params = FlattenPDFDocumentParams(
|
|
137
|
+
document_id=document_id, json_response=True
|
|
138
|
+
)
|
|
139
|
+
flattened_document = client.flatten_pdf(flatten_pdf_params)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Compress a PDF
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
compress_pdf_params = CompressPDFByDocumentIdParams(
|
|
146
|
+
document_id=document_id, json_response=True
|
|
147
|
+
)
|
|
148
|
+
response = client.compress_pdf(compress_pdf_params)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Watermark a PDF
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
watermark_pdf_params = WatermarkPDFByFileParams(
|
|
155
|
+
file=FileParam(name="input.pdf", data=pdf_file),
|
|
156
|
+
type=WatermarkType.IMAGE,
|
|
157
|
+
watermark=FileParam(name="watermark.jpg", data=jpg_file),
|
|
158
|
+
)
|
|
159
|
+
watermarked_pdf = cast(PDFGateDocument, client.watermark_pdf(watermark_pdf_params))
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Protect (encrypt) a PDF
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
protect_pdf_params = ProtectPDFByDocumentIdParams(
|
|
166
|
+
document_id=document_id,
|
|
167
|
+
user_password=str(uuid.uuid4()),
|
|
168
|
+
owner_password=str(uuid.uuid4()),
|
|
169
|
+
json_response=True,
|
|
170
|
+
)
|
|
171
|
+
response = client.protect_pdf(protect_pdf_params)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Extract PDF form fields values
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
html_form = """
|
|
178
|
+
<form>
|
|
179
|
+
<input type='text' name='first_name' value='John'/>
|
|
180
|
+
<input type='text' name='last_name' value='Doe'/>
|
|
181
|
+
</form>
|
|
182
|
+
"""
|
|
183
|
+
generate_pdf_params = GeneratePDFParams(
|
|
184
|
+
html=html_form, enable_form_fields=True, json_response=True
|
|
185
|
+
)
|
|
186
|
+
document_response = cast(PDFGateDocument, client.generate_pdf(generate_pdf_params))
|
|
187
|
+
document_id = cast(str, document_response.get("id"))
|
|
188
|
+
|
|
189
|
+
extract_form_params = ExtractPDFFormDataByDocumentIdParams(document_id=document_id)
|
|
190
|
+
response = cast(dict[str, Any], client.extract_pdf_form_data(extract_form_params))
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
# Development
|
|
194
|
+
|
|
195
|
+
Before doing anything, install [pre-commit](https://pre-commit.com/) by running:
|
|
196
|
+
|
|
197
|
+
```sh
|
|
198
|
+
hatch run dev:pre-commit install
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
This will run several checks every time you try to `git commit` including:
|
|
202
|
+
|
|
203
|
+
- linting and formatting with `Ruff`
|
|
204
|
+
- type checking with `mypy`
|
|
205
|
+
|
|
206
|
+
If you are on VS Code, it's recommended to install the `Ruff` extension so you'll get formatting on the fly.
|
|
207
|
+
|
|
208
|
+
Hatch is used as a build system and for dependency management, so all main actions are configured to be run with Hatch.
|
|
209
|
+
|
|
210
|
+
## Tests
|
|
211
|
+
|
|
212
|
+
Unit tests:
|
|
213
|
+
```sh
|
|
214
|
+
hatch run test:test
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Acceptance tests hit the PDFGate API so they are slower, and require an API key that is expected to be set as an env var named `PDFGATE_API_KEY`. You can set it on your Bash/zsh/fish profile or inline as in:
|
|
218
|
+
|
|
219
|
+
```sh
|
|
220
|
+
PDFGATE_API_KEY="test_123" hatch run test:test_acceptance
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Manually run Ruff
|
|
224
|
+
|
|
225
|
+
Linting:
|
|
226
|
+
```sh
|
|
227
|
+
hatch run dev:lint
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Formatting:
|
|
231
|
+
```sh
|
|
232
|
+
hatch run dev:ruff format .
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Type checking
|
|
236
|
+
|
|
237
|
+
Manually mypy for type checking:
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
hatch run dev:check
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Docs
|
|
244
|
+
|
|
245
|
+
Docs are build using [MkDocs](https://www.mkdocs.org/), they live in the `docs/` folder, and in the code. If you make any changes, and would like to see them live before publishing them, spin up a server locally with:
|
|
246
|
+
|
|
247
|
+
```sh
|
|
248
|
+
hatch run docs:serve
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Changes to `docs/**` and `mkdocs.yml` trigger a new deployment of the docs site. If you change the code's documentation and want to manually update the docs site you can do it from the _Actions_ tab of the repo or by running:
|
|
252
|
+
|
|
253
|
+
```sh
|
|
254
|
+
hatch run docs:mkdocs gh-deploy
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
# Support
|
|
258
|
+
|
|
259
|
+
📧 Email: support@pdfgate.com<br>
|
|
260
|
+
📘 Docs: https://pdfgate.com/documentation
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
`pdfgate-sdk-python` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
pdfgate/__about__.py,sha256=8ouC2JLRB99qLhOJNCPFJNs8b_GZcT_k2vXBVBYt6ug,177
|
|
2
|
+
pdfgate/__init__.py,sha256=3UuE7DAAJk49eLFXyDmlHJ20tyRlewWiWDfZs2BttLo,2025
|
|
3
|
+
pdfgate/config.py,sha256=C0p2DIon6NUW76aBLZIQ3ZRmzBnBdxS0doxhyNPo31E,572
|
|
4
|
+
pdfgate/dict_keys_converter.py,sha256=_-c737ohvEKNDbsB6lp9KqDt16ZTjIIkJ7EBcTSru-E,2105
|
|
5
|
+
pdfgate/errors.py,sha256=1xhp5gdDQeH3Lt0jweDSN8Z9vi118jS0knQCUwReYVs,233
|
|
6
|
+
pdfgate/http_client.py,sha256=0eemoVeSHwHTUFm7BKe2rG8xnGf9zxYLX1fjKuw15Jg,2764
|
|
7
|
+
pdfgate/params.py,sha256=EAmBnJIP7XbwjVD8bCDF-0Cig6Ro7hRiLamQIUgYHy8,7800
|
|
8
|
+
pdfgate/pdfgate.py,sha256=F-FkisFLkFKdPQdIDTnelSEro6WspnrEZzCbwNIblUU,15613
|
|
9
|
+
pdfgate/request_builder.py,sha256=byRy_VfuqpYiWXhvLjNZ9IumxBI_Zfa-UcFH35kpkxs,9797
|
|
10
|
+
pdfgate/response_builder.py,sha256=_3SkGziM0mrW5H-nG2iTMXtwaPFUEuLy-4bJmqF4vCc,715
|
|
11
|
+
pdfgate/responses.py,sha256=IeP_EYgkzzW97DX9YooffXWAoQz9Z15Vk83DmoZQVrw,893
|
|
12
|
+
pdfgate/url_builder.py,sha256=F_Joc8igsoYxmL7mdy7vxVnVrWJb1ekVUE1NGlD6anI,2134
|
|
13
|
+
pdfgate-0.0.2.dist-info/METADATA,sha256=nuX2NUcgmd5bC59vxey8avDE62n1Mp4BpmKEQlCEY9g,7254
|
|
14
|
+
pdfgate-0.0.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
15
|
+
pdfgate-0.0.2.dist-info/licenses/LICENSE,sha256=bbmVqXq9fdjy9HgXnraS3rnPZQh7vZCLBWyUME3mkfY,1064
|
|
16
|
+
pdfgate-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PDFGate
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|