pdfgate 0.0.2__tar.gz → 0.0.3__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.
Files changed (35) hide show
  1. {pdfgate-0.0.2 → pdfgate-0.0.3}/.github/workflows/publish-to-pypi.yml +4 -4
  2. {pdfgate-0.0.2 → pdfgate-0.0.3}/PKG-INFO +77 -59
  3. {pdfgate-0.0.2 → pdfgate-0.0.3}/README.md +75 -57
  4. {pdfgate-0.0.2 → pdfgate-0.0.3}/docs/getting_started.md +23 -23
  5. {pdfgate-0.0.2 → pdfgate-0.0.3}/pyproject.toml +1 -2
  6. pdfgate-0.0.3/src/pdfgate/__about__.py +6 -0
  7. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/__init__.py +37 -29
  8. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/config.py +1 -0
  9. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/dict_keys_converter.py +15 -0
  10. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/errors.py +4 -0
  11. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/params.py +70 -88
  12. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/pdfgate.py +170 -86
  13. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/request_builder.py +61 -75
  14. pdfgate-0.0.3/src/pdfgate/response_builder.py +29 -0
  15. pdfgate-0.0.3/src/pdfgate/responses.py +129 -0
  16. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/url_builder.py +40 -0
  17. pdfgate-0.0.3/src/pdfgate/webhooks.py +84 -0
  18. pdfgate-0.0.3/tests/test_pdfgate.py +689 -0
  19. {pdfgate-0.0.2 → pdfgate-0.0.3}/tests/test_pdfgate_acceptance.py +181 -141
  20. pdfgate-0.0.2/src/pdfgate/__about__.py +0 -6
  21. pdfgate-0.0.2/src/pdfgate/response_builder.py +0 -23
  22. pdfgate-0.0.2/src/pdfgate/responses.py +0 -37
  23. pdfgate-0.0.2/tests/test_pdfgate.py +0 -255
  24. {pdfgate-0.0.2 → pdfgate-0.0.3}/.github/workflows/main.yml +0 -0
  25. {pdfgate-0.0.2 → pdfgate-0.0.3}/.gitignore +0 -0
  26. {pdfgate-0.0.2 → pdfgate-0.0.3}/.pre-commit-config.yaml +0 -0
  27. {pdfgate-0.0.2 → pdfgate-0.0.3}/LICENSE +0 -0
  28. {pdfgate-0.0.2 → pdfgate-0.0.3}/docs/assets/images/favicon.png +0 -0
  29. {pdfgate-0.0.2 → pdfgate-0.0.3}/docs/assets/images/logo.svg +0 -0
  30. {pdfgate-0.0.2 → pdfgate-0.0.3}/docs/index.md +0 -0
  31. {pdfgate-0.0.2 → pdfgate-0.0.3}/docs/reference.md +0 -0
  32. {pdfgate-0.0.2 → pdfgate-0.0.3}/mkdocs.yml +0 -0
  33. {pdfgate-0.0.2 → pdfgate-0.0.3}/src/pdfgate/http_client.py +0 -0
  34. {pdfgate-0.0.2 → pdfgate-0.0.3}/tests/__init__.py +0 -0
  35. {pdfgate-0.0.2 → pdfgate-0.0.3}/tests/test_dict_keys_converter.py +0 -0
@@ -6,7 +6,7 @@ on:
6
6
  branches:
7
7
  - main
8
8
  tags:
9
- - "v[0-9]+.[0-9]+.[0-9]+*"
9
+ - "v*"
10
10
 
11
11
  jobs:
12
12
  build:
@@ -47,7 +47,7 @@ jobs:
47
47
 
48
48
  environment:
49
49
  name: testpypi
50
- url: https://test.pypi.org/p/pdfgate-sdk-python
50
+ url: https://test.pypi.org/p/pdfgate
51
51
 
52
52
  permissions:
53
53
  id-token: write # IMPORTANT: mandatory for trusted publishing
@@ -67,14 +67,14 @@ jobs:
67
67
  name: Publish distribution 📦 to PyPI
68
68
  if: >-
69
69
  ((github.event_name == 'workflow_dispatch') || (github.event_name == 'push')) &&
70
- startsWith(github.ref, 'refs/tags/v')
70
+ startsWith(github.ref, 'refs/tags/v') && !endsWith(github.ref, '-beta')
71
71
  needs:
72
72
  - build
73
73
  runs-on: ubuntu-latest
74
74
 
75
75
  environment:
76
76
  name: pypi
77
- url: https://pypi.org/p/pdfgate-sdk-python
77
+ url: https://pypi.org/p/pdfgate
78
78
 
79
79
  permissions:
80
80
  id-token: write # IMPORTANT: mandatory for trusted publishing
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pdfgate
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: PDFGate's official Python SDK
5
5
  Project-URL: Documentation, https://github.com/pdfgate/pdfgate-sdk-python#readme
6
6
  Project-URL: Issues, https://github.com/pdfgate/pdfgate-sdk-python/issues
7
7
  Project-URL: Source, https://github.com/pdfgate/pdfgate-sdk-python
8
- Author-email: Fernando Gasperi <fgasperijabalera@gmail.com>, Demetra Theodorou <demtra@pdfgate.com>
8
+ Author-email: PDFGate <support@pdfgate.com>
9
9
  License-Expression: MIT
10
10
  License-File: LICENSE
11
11
  Classifier: Development Status :: 4 - Beta
@@ -23,20 +23,15 @@ Description-Content-Type: text/markdown
23
23
 
24
24
  # PDFGate's official Python SDK
25
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
26
+ The PDFGate Python SDK provides convenient access to the PDFGate API from applications written in Python. It includes typed parameter objects, synchronous and asynchronous clients, response helpers, and webhook signature verification for common PDF generation, processing, and signing workflows.
32
27
 
33
28
  📘 Documentation: https://pdfgate.com/documentation<br>
34
29
  🔑 Dashboard & API keys: https://dashboard.pdfgate.com
35
30
 
36
- ## pdfgate-sdk-python
31
+ ## pdfgate
37
32
 
38
- [![PyPI - Version](https://img.shields.io/pypi/v/pdfgate-sdk-python.svg)](https://pypi.org/project/pdfgate-sdk-python)
39
- [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pdfgate-sdk-python.svg)](https://pypi.org/project/pdfgate-sdk-python)
33
+ [![PyPI - Version](https://img.shields.io/pypi/v/pdfgate.svg)](https://pypi.org/project/pdfgate)
34
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pdfgate.svg)](https://pypi.org/project/pdfgate)
40
35
 
41
36
 
42
37
  ## Table of Contents
@@ -45,6 +40,7 @@ PDFGate lets you generate, process, and secure PDFs via a simple API:
45
40
  - [Quick start](#quick-start)
46
41
  - [Sync & Async](#sync--async)
47
42
  - [Responses](#responses)
43
+ - [Webhook Verification](#webhook-verification)
48
44
  - [Examples](#examples)
49
45
  - [Development](#development)
50
46
  - [Support](#support)
@@ -64,12 +60,11 @@ import os
64
60
  from pdfgate import PDFGate, GeneratePDFParams
65
61
 
66
62
 
67
- client = PDFGate(api_key=os.getenv("PDFGATE_API_KEY"))
63
+ client = PDFGate(api_key=os.environ["PDFGATE_API_KEY"])
68
64
  params = GeneratePDFParams(url="https://example.com")
69
- pdf = client.generate_pdf(params)
65
+ document = client.generate_pdf(params)
70
66
 
71
- with open("output.pdf", "wb") as f:
72
- f.write(pdf)
67
+ print(document["id"])
73
68
  ```
74
69
 
75
70
  # Sync & Async
@@ -88,11 +83,34 @@ Other than that, nothing changes and the interfaces are the same.
88
83
 
89
84
  # Responses
90
85
 
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:
86
+ The SDK returns a `PDFGateDocument` for all processing endpoints:
87
+
88
+ - `generate_pdf`
89
+ - `flatten_pdf`
90
+ - `compress_pdf`
91
+ - `watermark_pdf`
92
+ - `protect_pdf`
93
+ - `upload_file`
94
+
95
+ To get raw PDF bytes, call `get_file` with a document ID.
96
+
97
+ # Webhook Verification
98
+
99
+ Use `verify_signature` with the raw request body and the
100
+ `x-pdfgate-signature` header value received from PDFGate:
101
+
102
+ ```python
103
+ from pdfgate import verify_signature
104
+
105
+
106
+ event = verify_signature(
107
+ secret="whsecret_...",
108
+ signature_header=request.headers["x-pdfgate-signature"],
109
+ payload=request_body,
110
+ )
93
111
 
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.
112
+ event_id = event["event_id"]
113
+ ```
96
114
 
97
115
  # Examples
98
116
 
@@ -100,10 +118,8 @@ PDF file or the documents metadata that you can use to query or download later:
100
118
 
101
119
  ```python
102
120
  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)
121
+ document = client.generate_pdf(params)
122
+ print(document["id"])
107
123
  ```
108
124
 
109
125
  ## Get document metadata
@@ -111,14 +127,9 @@ with open("output.pdf", "wb") as f:
111
127
  ```python
112
128
  document_response = client.get_document(GetDocumentParams(document_id=document_id))
113
129
 
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
- }
130
+ print(document_response["id"])
131
+ print(document_response["status"])
132
+ print(document_response.get("file_url"))
122
133
  ```
123
134
 
124
135
  ## Download a stored PDF file
@@ -127,14 +138,23 @@ assert document_response = {
127
138
  file_content = client.get_file(GetFileParams(document_id=document_id))
128
139
 
129
140
  with open("output.pdf", "wb") as f:
130
- f.write(pdf)
141
+ f.write(file_content)
142
+ ```
143
+
144
+ ## Upload a PDF file
145
+
146
+ ```python
147
+ file_param = FileParam.pdf(name="input.pdf", data=pdf_file_bytes)
148
+ document_response = client.upload_file(UploadFileParams(file=file_param))
131
149
  ```
132
150
 
151
+ If both `file` and `url` are provided, `file` is prioritized and the request is sent as multipart.
152
+
133
153
  ## Flatten a PDF (make form-fields non-editable)
134
154
 
135
155
  ```python
136
- flatten_pdf_params = FlattenPDFDocumentParams(
137
- document_id=document_id, json_response=True
156
+ flatten_pdf_params = FlattenPDFParams(
157
+ document_id=document_id
138
158
  )
139
159
  flattened_document = client.flatten_pdf(flatten_pdf_params)
140
160
  ```
@@ -142,8 +162,8 @@ flattened_document = client.flatten_pdf(flatten_pdf_params)
142
162
  ## Compress a PDF
143
163
 
144
164
  ```python
145
- compress_pdf_params = CompressPDFByDocumentIdParams(
146
- document_id=document_id, json_response=True
165
+ compress_pdf_params = CompressPDFParams(
166
+ document_id=document_id
147
167
  )
148
168
  response = client.compress_pdf(compress_pdf_params)
149
169
  ```
@@ -151,22 +171,21 @@ response = client.compress_pdf(compress_pdf_params)
151
171
  ## Watermark a PDF
152
172
 
153
173
  ```python
154
- watermark_pdf_params = WatermarkPDFByFileParams(
155
- file=FileParam(name="input.pdf", data=pdf_file),
174
+ watermark_pdf_params = WatermarkPDFParams(
175
+ document_id=document_id,
156
176
  type=WatermarkType.IMAGE,
157
177
  watermark=FileParam(name="watermark.jpg", data=jpg_file),
158
178
  )
159
- watermarked_pdf = cast(PDFGateDocument, client.watermark_pdf(watermark_pdf_params))
179
+ watermarked_pdf = client.watermark_pdf(watermark_pdf_params)
160
180
  ```
161
181
 
162
182
  ## Protect (encrypt) a PDF
163
183
 
164
184
  ```python
165
- protect_pdf_params = ProtectPDFByDocumentIdParams(
185
+ protect_pdf_params = ProtectPDFParams(
166
186
  document_id=document_id,
167
- user_password=str(uuid.uuid4()),
168
- owner_password=str(uuid.uuid4()),
169
- json_response=True,
187
+ user_password="user-password",
188
+ owner_password="owner-password",
170
189
  )
171
190
  response = client.protect_pdf(protect_pdf_params)
172
191
  ```
@@ -175,19 +194,19 @@ response = client.protect_pdf(protect_pdf_params)
175
194
 
176
195
  ```python
177
196
  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
- """
197
+ <form>
198
+ <input type="text" name="first_name" value="John" />
199
+ <input type="text" name="last_name" value="Doe" />
200
+ </form>
201
+ """
183
202
  generate_pdf_params = GeneratePDFParams(
184
- html=html_form, enable_form_fields=True, json_response=True
203
+ html=html_form, enable_form_fields=True
185
204
  )
186
- document_response = cast(PDFGateDocument, client.generate_pdf(generate_pdf_params))
187
- document_id = cast(str, document_response.get("id"))
205
+ document_response = client.generate_pdf(generate_pdf_params)
206
+ document_id = document_response["id"]
188
207
 
189
- extract_form_params = ExtractPDFFormDataByDocumentIdParams(document_id=document_id)
190
- response = cast(dict[str, Any], client.extract_pdf_form_data(extract_form_params))
208
+ extract_form_params = ExtractPDFFormDataParams(document_id=document_id)
209
+ response = client.extract_pdf_form_data(extract_form_params)
191
210
  ```
192
211
 
193
212
  # Development
@@ -234,7 +253,7 @@ hatch run dev:ruff format .
234
253
 
235
254
  ## Type checking
236
255
 
237
- Manually mypy for type checking:
256
+ Run mypy manually:
238
257
 
239
258
  ```sh
240
259
  hatch run dev:check
@@ -242,7 +261,7 @@ hatch run dev:check
242
261
 
243
262
  ## Docs
244
263
 
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:
264
+ Docs are built 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
265
 
247
266
  ```sh
248
267
  hatch run docs:serve
@@ -254,11 +273,10 @@ Changes to `docs/**` and `mkdocs.yml` trigger a new deployment of the docs site.
254
273
  hatch run docs:mkdocs gh-deploy
255
274
  ```
256
275
 
257
- # Support
276
+ ## Support
258
277
 
259
- 📧 Email: support@pdfgate.com<br>
260
- 📘 Docs: https://pdfgate.com/documentation
278
+ For support, contact [support@pdfgate.com](mailto:support@pdfgate.com).
261
279
 
262
280
  ## License
263
281
 
264
- `pdfgate-sdk-python` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
282
+ `pdfgate` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -1,19 +1,14 @@
1
1
  # PDFGate's official Python SDK
2
2
 
3
- PDFGate lets you generate, process, and secure PDFs via a simple API:
4
-
5
- - HTML or URL to PDF
6
- - Fillable forms
7
- - Flatten, compress, watermark, protect PDFs
8
- - Extract PDF form data
3
+ The PDFGate Python SDK provides convenient access to the PDFGate API from applications written in Python. It includes typed parameter objects, synchronous and asynchronous clients, response helpers, and webhook signature verification for common PDF generation, processing, and signing workflows.
9
4
 
10
5
  📘 Documentation: https://pdfgate.com/documentation<br>
11
6
  🔑 Dashboard & API keys: https://dashboard.pdfgate.com
12
7
 
13
- ## pdfgate-sdk-python
8
+ ## pdfgate
14
9
 
15
- [![PyPI - Version](https://img.shields.io/pypi/v/pdfgate-sdk-python.svg)](https://pypi.org/project/pdfgate-sdk-python)
16
- [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pdfgate-sdk-python.svg)](https://pypi.org/project/pdfgate-sdk-python)
10
+ [![PyPI - Version](https://img.shields.io/pypi/v/pdfgate.svg)](https://pypi.org/project/pdfgate)
11
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pdfgate.svg)](https://pypi.org/project/pdfgate)
17
12
 
18
13
 
19
14
  ## Table of Contents
@@ -22,6 +17,7 @@ PDFGate lets you generate, process, and secure PDFs via a simple API:
22
17
  - [Quick start](#quick-start)
23
18
  - [Sync & Async](#sync--async)
24
19
  - [Responses](#responses)
20
+ - [Webhook Verification](#webhook-verification)
25
21
  - [Examples](#examples)
26
22
  - [Development](#development)
27
23
  - [Support](#support)
@@ -41,12 +37,11 @@ import os
41
37
  from pdfgate import PDFGate, GeneratePDFParams
42
38
 
43
39
 
44
- client = PDFGate(api_key=os.getenv("PDFGATE_API_KEY"))
40
+ client = PDFGate(api_key=os.environ["PDFGATE_API_KEY"])
45
41
  params = GeneratePDFParams(url="https://example.com")
46
- pdf = client.generate_pdf(params)
42
+ document = client.generate_pdf(params)
47
43
 
48
- with open("output.pdf", "wb") as f:
49
- f.write(pdf)
44
+ print(document["id"])
50
45
  ```
51
46
 
52
47
  # Sync & Async
@@ -65,11 +60,34 @@ Other than that, nothing changes and the interfaces are the same.
65
60
 
66
61
  # Responses
67
62
 
68
- The two response types for most endpoints are either the raw bytes of the
69
- PDF file or the documents metadata that you can use to query or download later:
63
+ The SDK returns a `PDFGateDocument` for all processing endpoints:
64
+
65
+ - `generate_pdf`
66
+ - `flatten_pdf`
67
+ - `compress_pdf`
68
+ - `watermark_pdf`
69
+ - `protect_pdf`
70
+ - `upload_file`
71
+
72
+ To get raw PDF bytes, call `get_file` with a document ID.
73
+
74
+ # Webhook Verification
75
+
76
+ Use `verify_signature` with the raw request body and the
77
+ `x-pdfgate-signature` header value received from PDFGate:
78
+
79
+ ```python
80
+ from pdfgate import verify_signature
81
+
82
+
83
+ event = verify_signature(
84
+ secret="whsecret_...",
85
+ signature_header=request.headers["x-pdfgate-signature"],
86
+ payload=request_body,
87
+ )
70
88
 
71
- - file: this is represented by `bytes` and it can be saved directly into a file.
72
- - `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.
89
+ event_id = event["event_id"]
90
+ ```
73
91
 
74
92
  # Examples
75
93
 
@@ -77,10 +95,8 @@ PDF file or the documents metadata that you can use to query or download later:
77
95
 
78
96
  ```python
79
97
  params = GeneratePDFParams(html="<h1>Hello from PDFGate!</h1>")
80
- pdf = client.generate_pdf(params)
81
-
82
- with open("output.pdf", "wb") as f:
83
- f.write(pdf)
98
+ document = client.generate_pdf(params)
99
+ print(document["id"])
84
100
  ```
85
101
 
86
102
  ## Get document metadata
@@ -88,14 +104,9 @@ with open("output.pdf", "wb") as f:
88
104
  ```python
89
105
  document_response = client.get_document(GetDocumentParams(document_id=document_id))
90
106
 
91
- assert document_response = {
92
- "id" : "6642381c5c61"
93
- "status" : DocumentStatus.COMPLETED
94
- "type" : DocumentType.FROM_HTML,
95
- "file_url" : "https://api.pdfgate.com/file/open/:preSignedUrlToken"
96
- "size" : 1620006
97
- "createdAt" : datetime(2024,02,13, 15, 56, 12, 607)"
98
- }
107
+ print(document_response["id"])
108
+ print(document_response["status"])
109
+ print(document_response.get("file_url"))
99
110
  ```
100
111
 
101
112
  ## Download a stored PDF file
@@ -104,14 +115,23 @@ assert document_response = {
104
115
  file_content = client.get_file(GetFileParams(document_id=document_id))
105
116
 
106
117
  with open("output.pdf", "wb") as f:
107
- f.write(pdf)
118
+ f.write(file_content)
119
+ ```
120
+
121
+ ## Upload a PDF file
122
+
123
+ ```python
124
+ file_param = FileParam.pdf(name="input.pdf", data=pdf_file_bytes)
125
+ document_response = client.upload_file(UploadFileParams(file=file_param))
108
126
  ```
109
127
 
128
+ If both `file` and `url` are provided, `file` is prioritized and the request is sent as multipart.
129
+
110
130
  ## Flatten a PDF (make form-fields non-editable)
111
131
 
112
132
  ```python
113
- flatten_pdf_params = FlattenPDFDocumentParams(
114
- document_id=document_id, json_response=True
133
+ flatten_pdf_params = FlattenPDFParams(
134
+ document_id=document_id
115
135
  )
116
136
  flattened_document = client.flatten_pdf(flatten_pdf_params)
117
137
  ```
@@ -119,8 +139,8 @@ flattened_document = client.flatten_pdf(flatten_pdf_params)
119
139
  ## Compress a PDF
120
140
 
121
141
  ```python
122
- compress_pdf_params = CompressPDFByDocumentIdParams(
123
- document_id=document_id, json_response=True
142
+ compress_pdf_params = CompressPDFParams(
143
+ document_id=document_id
124
144
  )
125
145
  response = client.compress_pdf(compress_pdf_params)
126
146
  ```
@@ -128,22 +148,21 @@ response = client.compress_pdf(compress_pdf_params)
128
148
  ## Watermark a PDF
129
149
 
130
150
  ```python
131
- watermark_pdf_params = WatermarkPDFByFileParams(
132
- file=FileParam(name="input.pdf", data=pdf_file),
151
+ watermark_pdf_params = WatermarkPDFParams(
152
+ document_id=document_id,
133
153
  type=WatermarkType.IMAGE,
134
154
  watermark=FileParam(name="watermark.jpg", data=jpg_file),
135
155
  )
136
- watermarked_pdf = cast(PDFGateDocument, client.watermark_pdf(watermark_pdf_params))
156
+ watermarked_pdf = client.watermark_pdf(watermark_pdf_params)
137
157
  ```
138
158
 
139
159
  ## Protect (encrypt) a PDF
140
160
 
141
161
  ```python
142
- protect_pdf_params = ProtectPDFByDocumentIdParams(
162
+ protect_pdf_params = ProtectPDFParams(
143
163
  document_id=document_id,
144
- user_password=str(uuid.uuid4()),
145
- owner_password=str(uuid.uuid4()),
146
- json_response=True,
164
+ user_password="user-password",
165
+ owner_password="owner-password",
147
166
  )
148
167
  response = client.protect_pdf(protect_pdf_params)
149
168
  ```
@@ -152,19 +171,19 @@ response = client.protect_pdf(protect_pdf_params)
152
171
 
153
172
  ```python
154
173
  html_form = """
155
- <form>
156
- <input type='text' name='first_name' value='John'/>
157
- <input type='text' name='last_name' value='Doe'/>
158
- </form>
159
- """
174
+ <form>
175
+ <input type="text" name="first_name" value="John" />
176
+ <input type="text" name="last_name" value="Doe" />
177
+ </form>
178
+ """
160
179
  generate_pdf_params = GeneratePDFParams(
161
- html=html_form, enable_form_fields=True, json_response=True
180
+ html=html_form, enable_form_fields=True
162
181
  )
163
- document_response = cast(PDFGateDocument, client.generate_pdf(generate_pdf_params))
164
- document_id = cast(str, document_response.get("id"))
182
+ document_response = client.generate_pdf(generate_pdf_params)
183
+ document_id = document_response["id"]
165
184
 
166
- extract_form_params = ExtractPDFFormDataByDocumentIdParams(document_id=document_id)
167
- response = cast(dict[str, Any], client.extract_pdf_form_data(extract_form_params))
185
+ extract_form_params = ExtractPDFFormDataParams(document_id=document_id)
186
+ response = client.extract_pdf_form_data(extract_form_params)
168
187
  ```
169
188
 
170
189
  # Development
@@ -211,7 +230,7 @@ hatch run dev:ruff format .
211
230
 
212
231
  ## Type checking
213
232
 
214
- Manually mypy for type checking:
233
+ Run mypy manually:
215
234
 
216
235
  ```sh
217
236
  hatch run dev:check
@@ -219,7 +238,7 @@ hatch run dev:check
219
238
 
220
239
  ## Docs
221
240
 
222
- 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:
241
+ Docs are built 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:
223
242
 
224
243
  ```sh
225
244
  hatch run docs:serve
@@ -231,11 +250,10 @@ Changes to `docs/**` and `mkdocs.yml` trigger a new deployment of the docs site.
231
250
  hatch run docs:mkdocs gh-deploy
232
251
  ```
233
252
 
234
- # Support
253
+ ## Support
235
254
 
236
- 📧 Email: support@pdfgate.com<br>
237
- 📘 Docs: https://pdfgate.com/documentation
255
+ For support, contact [support@pdfgate.com](mailto:support@pdfgate.com).
238
256
 
239
257
  ## License
240
258
 
241
- `pdfgate-sdk-python` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
259
+ `pdfgate` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -14,10 +14,9 @@ from pdfgate import PDFGate, GeneratePDFParams
14
14
 
15
15
  client = PDFGate(api_key=os.getenv("PDFGATE_API_KEY"))
16
16
  params = GeneratePDFParams(url="https://example.com")
17
- pdf = client.generate_pdf(params)
17
+ document = client.generate_pdf(params)
18
18
 
19
- with open("output.pdf", "wb") as f:
20
- f.write(pdf)
19
+ print(document["id"])
21
20
  ```
22
21
 
23
22
  # Sync & Async
@@ -36,11 +35,15 @@ Other than that, nothing changes and the interfaces are the same.
36
35
 
37
36
  # Responses
38
37
 
39
- The two response types for most endpoints are either the raw bytes of the
40
- PDF file or the documents metadata that you can use to query or download later:
38
+ The SDK returns a `PDFGateDocument` for all processing endpoints:
39
+
40
+ - `generate_pdf`
41
+ - `flatten_pdf`
42
+ - `compress_pdf`
43
+ - `watermark_pdf`
44
+ - `protect_pdf`
41
45
 
42
- - file: this is represented by `bytes` and it can be saved directly into a file.
43
- - `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.
46
+ To get raw PDF bytes, call `get_file` with a document ID.
44
47
 
45
48
  # Examples
46
49
 
@@ -48,10 +51,8 @@ PDF file or the documents metadata that you can use to query or download later:
48
51
 
49
52
  ```python
50
53
  params = GeneratePDFParams(html="<h1>Hello from PDFGate!</h1>")
51
- pdf = client.generate_pdf(params)
52
-
53
- with open("output.pdf", "wb") as f:
54
- f.write(pdf)
54
+ document = client.generate_pdf(params)
55
+ print(document["id"])
55
56
  ```
56
57
 
57
58
  ## Get document metadata
@@ -75,14 +76,14 @@ assert document_response = {
75
76
  file_content = client.get_file(GetFileParams(document_id=document_id))
76
77
 
77
78
  with open("output.pdf", "wb") as f:
78
- f.write(pdf)
79
+ f.write(file_content)
79
80
  ```
80
81
 
81
82
  ## Flatten a PDF (make form-fields non-editable)
82
83
 
83
84
  ```python
84
- flatten_pdf_params = FlattenPDFDocumentParams(
85
- document_id=document_id, json_response=True
85
+ flatten_pdf_params = FlattenPDFParams(
86
+ document_id=document_id
86
87
  )
87
88
  flattened_document = client.flatten_pdf(flatten_pdf_params)
88
89
  ```
@@ -90,8 +91,8 @@ flattened_document = client.flatten_pdf(flatten_pdf_params)
90
91
  ## Compress a PDF
91
92
 
92
93
  ```python
93
- compress_pdf_params = CompressPDFByDocumentIdParams(
94
- document_id=document_id, json_response=True
94
+ compress_pdf_params = CompressPDFParams(
95
+ document_id=document_id
95
96
  )
96
97
  response = client.compress_pdf(compress_pdf_params)
97
98
  ```
@@ -99,22 +100,21 @@ response = client.compress_pdf(compress_pdf_params)
99
100
  ## Watermark a PDF
100
101
 
101
102
  ```python
102
- watermark_pdf_params = WatermarkPDFByFileParams(
103
- file=FileParam(name="input.pdf", data=pdf_file),
103
+ watermark_pdf_params = WatermarkPDFParams(
104
+ document_id=document_id,
104
105
  type=WatermarkType.IMAGE,
105
106
  watermark=FileParam(name="watermark.jpg", data=jpg_file),
106
107
  )
107
- watermarked_pdf = cast(PDFGateDocument, client.watermark_pdf(watermark_pdf_params))
108
+ watermarked_pdf = client.watermark_pdf(watermark_pdf_params)
108
109
  ```
109
110
 
110
111
  ## Protect (encrypt) a PDF
111
112
 
112
113
  ```python
113
- protect_pdf_params = ProtectPDFByDocumentIdParams(
114
+ protect_pdf_params = ProtectPDFParams(
114
115
  document_id=document_id,
115
116
  user_password=str(uuid.uuid4()),
116
117
  owner_password=str(uuid.uuid4()),
117
- json_response=True,
118
118
  )
119
119
  response = client.protect_pdf(protect_pdf_params)
120
120
  ```
@@ -129,11 +129,11 @@ html_form = """
129
129
  </form>
130
130
  """
131
131
  generate_pdf_params = GeneratePDFParams(
132
- html=html_form, enable_form_fields=True, json_response=True
132
+ html=html_form, enable_form_fields=True
133
133
  )
134
134
  document_response = cast(PDFGateDocument, client.generate_pdf(generate_pdf_params))
135
135
  document_id = cast(str, document_response.get("id"))
136
136
 
137
- extract_form_params = ExtractPDFFormDataByDocumentIdParams(document_id=document_id)
137
+ extract_form_params = ExtractPDFFormDataParams(document_id=document_id)
138
138
  response = cast(dict[str, Any], client.extract_pdf_form_data(extract_form_params))
139
139
  ```
@@ -11,8 +11,7 @@ requires-python = ">=3.9"
11
11
  license = "MIT"
12
12
  keywords = []
13
13
  authors = [
14
- { name = "Fernando Gasperi", email = "fgasperijabalera@gmail.com" },
15
- { name = "Demetra Theodorou", email = "demtra@pdfgate.com" },
14
+ { name = "PDFGate", email = "support@pdfgate.com" },
16
15
  ]
17
16
  classifiers = [
18
17
  "Development Status :: 4 - Beta",
@@ -0,0 +1,6 @@
1
+ """Package metadata for pdfgate."""
2
+
3
+ # SPDX-FileCopyrightText: 2026-present PDFGate <support@pdfgate.com>
4
+ #
5
+ # SPDX-License-Identifier: MIT
6
+ __version__ = "0.0.3"