pdfgate 0.0.2__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.
- pdfgate-0.0.2/.github/workflows/main.yml +26 -0
- pdfgate-0.0.2/.github/workflows/publish-to-pypi.yml +89 -0
- pdfgate-0.0.2/.gitignore +207 -0
- pdfgate-0.0.2/.pre-commit-config.yaml +22 -0
- pdfgate-0.0.2/LICENSE +21 -0
- pdfgate-0.0.2/PKG-INFO +264 -0
- pdfgate-0.0.2/README.md +241 -0
- pdfgate-0.0.2/docs/assets/images/favicon.png +0 -0
- pdfgate-0.0.2/docs/assets/images/logo.svg +1 -0
- pdfgate-0.0.2/docs/getting_started.md +139 -0
- pdfgate-0.0.2/docs/index.md +13 -0
- pdfgate-0.0.2/docs/reference.md +5 -0
- pdfgate-0.0.2/mkdocs.yml +21 -0
- pdfgate-0.0.2/pyproject.toml +81 -0
- pdfgate-0.0.2/src/pdfgate/__about__.py +6 -0
- pdfgate-0.0.2/src/pdfgate/__init__.py +81 -0
- pdfgate-0.0.2/src/pdfgate/config.py +18 -0
- pdfgate-0.0.2/src/pdfgate/dict_keys_converter.py +54 -0
- pdfgate-0.0.2/src/pdfgate/errors.py +9 -0
- pdfgate-0.0.2/src/pdfgate/http_client.py +76 -0
- pdfgate-0.0.2/src/pdfgate/params.py +308 -0
- pdfgate-0.0.2/src/pdfgate/pdfgate.py +370 -0
- pdfgate-0.0.2/src/pdfgate/request_builder.py +252 -0
- pdfgate-0.0.2/src/pdfgate/response_builder.py +23 -0
- pdfgate-0.0.2/src/pdfgate/responses.py +37 -0
- pdfgate-0.0.2/src/pdfgate/url_builder.py +81 -0
- pdfgate-0.0.2/tests/__init__.py +0 -0
- pdfgate-0.0.2/tests/test_dict_keys_converter.py +62 -0
- pdfgate-0.0.2/tests/test_pdfgate.py +255 -0
- pdfgate-0.0.2/tests/test_pdfgate_acceptance.py +390 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Deploy PDFGate Python SDK documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- 'docs/**'
|
|
9
|
+
- 'mkdocs.yml'
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
inputs:
|
|
12
|
+
logLevel:
|
|
13
|
+
description: 'Log level'
|
|
14
|
+
required: true
|
|
15
|
+
default: 'warning'
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
deploy:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: 3.x
|
|
25
|
+
- run: pip install mkdocs mkdocs-material "mkdocstrings[python]"
|
|
26
|
+
- run: mkdocs gh-deploy --force
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
name: Publish package to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch: {}
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
tags:
|
|
9
|
+
- "v[0-9]+.[0-9]+.[0-9]+*"
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
name: Build distribution 📦
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout code
|
|
18
|
+
uses: actions/checkout@v6
|
|
19
|
+
with:
|
|
20
|
+
persist-credentials: false
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@v6
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.x"
|
|
25
|
+
- name: Install hatch
|
|
26
|
+
run: >-
|
|
27
|
+
python3 -m
|
|
28
|
+
pip install
|
|
29
|
+
hatch
|
|
30
|
+
--user
|
|
31
|
+
- name: Build package
|
|
32
|
+
run: hatch build
|
|
33
|
+
- name: Store the distribution packages
|
|
34
|
+
uses: actions/upload-artifact@v5
|
|
35
|
+
with:
|
|
36
|
+
name: python-package-distributions
|
|
37
|
+
path: dist/
|
|
38
|
+
|
|
39
|
+
publish-to-testpypi:
|
|
40
|
+
name: Publish distribution 📦 to TestPyPI
|
|
41
|
+
if: >-
|
|
42
|
+
((github.event_name == 'workflow_dispatch') || (github.event_name == 'push')) &&
|
|
43
|
+
startsWith(github.ref, 'refs/tags/v') && endsWith(github.ref, '-beta')
|
|
44
|
+
needs:
|
|
45
|
+
- build
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
|
|
48
|
+
environment:
|
|
49
|
+
name: testpypi
|
|
50
|
+
url: https://test.pypi.org/p/pdfgate-sdk-python
|
|
51
|
+
|
|
52
|
+
permissions:
|
|
53
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
54
|
+
|
|
55
|
+
steps:
|
|
56
|
+
- name: Download all the dists
|
|
57
|
+
uses: actions/download-artifact@v6
|
|
58
|
+
with:
|
|
59
|
+
name: python-package-distributions
|
|
60
|
+
path: dist/
|
|
61
|
+
- name: Publish distribution 📦 to TestPyPI
|
|
62
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
63
|
+
with:
|
|
64
|
+
repository-url: https://test.pypi.org/legacy/
|
|
65
|
+
|
|
66
|
+
publish-to-pypi:
|
|
67
|
+
name: Publish distribution 📦 to PyPI
|
|
68
|
+
if: >-
|
|
69
|
+
((github.event_name == 'workflow_dispatch') || (github.event_name == 'push')) &&
|
|
70
|
+
startsWith(github.ref, 'refs/tags/v')
|
|
71
|
+
needs:
|
|
72
|
+
- build
|
|
73
|
+
runs-on: ubuntu-latest
|
|
74
|
+
|
|
75
|
+
environment:
|
|
76
|
+
name: pypi
|
|
77
|
+
url: https://pypi.org/p/pdfgate-sdk-python
|
|
78
|
+
|
|
79
|
+
permissions:
|
|
80
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
81
|
+
|
|
82
|
+
steps:
|
|
83
|
+
- name: Download all the dists
|
|
84
|
+
uses: actions/download-artifact@v6
|
|
85
|
+
with:
|
|
86
|
+
name: python-package-distributions
|
|
87
|
+
path: dist/
|
|
88
|
+
- name: Publish distribution 📦 to PyPI
|
|
89
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
pdfgate-0.0.2/.gitignore
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
.vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v6.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: trailing-whitespace
|
|
6
|
+
- id: end-of-file-fixer
|
|
7
|
+
- id: check-merge-conflict
|
|
8
|
+
- id: check-added-large-files
|
|
9
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
10
|
+
rev: v0.9.0
|
|
11
|
+
hooks:
|
|
12
|
+
- id: ruff
|
|
13
|
+
args: [--fix]
|
|
14
|
+
- id: ruff-format
|
|
15
|
+
- repo: local
|
|
16
|
+
hooks:
|
|
17
|
+
- id: hatch-mypy
|
|
18
|
+
name: hatch mypy
|
|
19
|
+
language: system
|
|
20
|
+
entry: hatch run dev:check
|
|
21
|
+
types: [python]
|
|
22
|
+
pass_filenames: false # Mypy usually works better on the whole project
|
pdfgate-0.0.2/LICENSE
ADDED
|
@@ -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.
|
pdfgate-0.0.2/PKG-INFO
ADDED
|
@@ -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.
|