templatefox 1.0.0__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.
@@ -0,0 +1,325 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ TemplateFox API
5
+
6
+ Generate PDFs from HTML templates via API. Design once, generate thousands.
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@pdftemplateapi.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+ import warnings
16
+ from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
17
+ from typing import Any, Dict, List, Optional, Tuple, Union
18
+ from typing_extensions import Annotated
19
+
20
+ from templatefox.models.create_pdf_request import CreatePdfRequest
21
+ from templatefox.models.create_pdf_response import CreatePdfResponse
22
+
23
+ from templatefox.api_client import ApiClient, RequestSerialized
24
+ from templatefox.api_response import ApiResponse
25
+ from templatefox.rest import RESTResponseType
26
+
27
+
28
+ class PDFApi:
29
+ """NOTE: This class is auto generated by OpenAPI Generator
30
+ Ref: https://openapi-generator.tech
31
+
32
+ Do not edit the class manually.
33
+ """
34
+
35
+ def __init__(self, api_client=None) -> None:
36
+ if api_client is None:
37
+ api_client = ApiClient.get_default()
38
+ self.api_client = api_client
39
+
40
+
41
+ @validate_call
42
+ def create_pdf(
43
+ self,
44
+ create_pdf_request: CreatePdfRequest,
45
+ _request_timeout: Union[
46
+ None,
47
+ Annotated[StrictFloat, Field(gt=0)],
48
+ Tuple[
49
+ Annotated[StrictFloat, Field(gt=0)],
50
+ Annotated[StrictFloat, Field(gt=0)]
51
+ ]
52
+ ] = None,
53
+ _request_auth: Optional[Dict[StrictStr, Any]] = None,
54
+ _content_type: Optional[StrictStr] = None,
55
+ _headers: Optional[Dict[StrictStr, Any]] = None,
56
+ _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
57
+ ) -> CreatePdfResponse:
58
+ """Generate PDF from template
59
+
60
+ Generate a PDF from a saved template with dynamic data. **Authentication:** API Key required (`x-api-key` header) ## Request Body | Field | Type | Required | Description | |-------|------|----------|-------------| | `template_id` | string | ✅ Yes | Template short ID (12 characters) | | `data` | object | ✅ Yes | Key-value data to render in template | | `export_type` | string | No | `url` (default) or `binary` | | `expiration` | integer | No | URL expiration in seconds (60-604800, default: 86400) | ## Export Types - `url` (default): PDF is uploaded to CDN, returns JSON with URL - `binary`: Returns raw PDF bytes directly **Credits:** 1 credit deducted per successful generation.
61
+
62
+ :param create_pdf_request: (required)
63
+ :type create_pdf_request: CreatePdfRequest
64
+ :param _request_timeout: timeout setting for this request. If one
65
+ number provided, it will be total request
66
+ timeout. It can also be a pair (tuple) of
67
+ (connection, read) timeouts.
68
+ :type _request_timeout: int, tuple(int, int), optional
69
+ :param _request_auth: set to override the auth_settings for an a single
70
+ request; this effectively ignores the
71
+ authentication in the spec for a single request.
72
+ :type _request_auth: dict, optional
73
+ :param _content_type: force content-type for the request.
74
+ :type _content_type: str, Optional
75
+ :param _headers: set to override the headers for a single
76
+ request; this effectively ignores the headers
77
+ in the spec for a single request.
78
+ :type _headers: dict, optional
79
+ :param _host_index: set to override the host_index for a single
80
+ request; this effectively ignores the host_index
81
+ in the spec for a single request.
82
+ :type _host_index: int, optional
83
+ :return: Returns the result object.
84
+ """ # noqa: E501
85
+
86
+ _param = self._create_pdf_serialize(
87
+ create_pdf_request=create_pdf_request,
88
+ _request_auth=_request_auth,
89
+ _content_type=_content_type,
90
+ _headers=_headers,
91
+ _host_index=_host_index
92
+ )
93
+
94
+ _response_types_map: Dict[str, Optional[str]] = {
95
+ '200': "CreatePdfResponse",
96
+ '402': None,
97
+ '403': None,
98
+ '404': None,
99
+ '422': "HTTPValidationError",
100
+ }
101
+ response_data = self.api_client.call_api(
102
+ *_param,
103
+ _request_timeout=_request_timeout
104
+ )
105
+ response_data.read()
106
+ return self.api_client.response_deserialize(
107
+ response_data=response_data,
108
+ response_types_map=_response_types_map,
109
+ ).data
110
+
111
+
112
+ @validate_call
113
+ def create_pdf_with_http_info(
114
+ self,
115
+ create_pdf_request: CreatePdfRequest,
116
+ _request_timeout: Union[
117
+ None,
118
+ Annotated[StrictFloat, Field(gt=0)],
119
+ Tuple[
120
+ Annotated[StrictFloat, Field(gt=0)],
121
+ Annotated[StrictFloat, Field(gt=0)]
122
+ ]
123
+ ] = None,
124
+ _request_auth: Optional[Dict[StrictStr, Any]] = None,
125
+ _content_type: Optional[StrictStr] = None,
126
+ _headers: Optional[Dict[StrictStr, Any]] = None,
127
+ _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
128
+ ) -> ApiResponse[CreatePdfResponse]:
129
+ """Generate PDF from template
130
+
131
+ Generate a PDF from a saved template with dynamic data. **Authentication:** API Key required (`x-api-key` header) ## Request Body | Field | Type | Required | Description | |-------|------|----------|-------------| | `template_id` | string | ✅ Yes | Template short ID (12 characters) | | `data` | object | ✅ Yes | Key-value data to render in template | | `export_type` | string | No | `url` (default) or `binary` | | `expiration` | integer | No | URL expiration in seconds (60-604800, default: 86400) | ## Export Types - `url` (default): PDF is uploaded to CDN, returns JSON with URL - `binary`: Returns raw PDF bytes directly **Credits:** 1 credit deducted per successful generation.
132
+
133
+ :param create_pdf_request: (required)
134
+ :type create_pdf_request: CreatePdfRequest
135
+ :param _request_timeout: timeout setting for this request. If one
136
+ number provided, it will be total request
137
+ timeout. It can also be a pair (tuple) of
138
+ (connection, read) timeouts.
139
+ :type _request_timeout: int, tuple(int, int), optional
140
+ :param _request_auth: set to override the auth_settings for an a single
141
+ request; this effectively ignores the
142
+ authentication in the spec for a single request.
143
+ :type _request_auth: dict, optional
144
+ :param _content_type: force content-type for the request.
145
+ :type _content_type: str, Optional
146
+ :param _headers: set to override the headers for a single
147
+ request; this effectively ignores the headers
148
+ in the spec for a single request.
149
+ :type _headers: dict, optional
150
+ :param _host_index: set to override the host_index for a single
151
+ request; this effectively ignores the host_index
152
+ in the spec for a single request.
153
+ :type _host_index: int, optional
154
+ :return: Returns the result object.
155
+ """ # noqa: E501
156
+
157
+ _param = self._create_pdf_serialize(
158
+ create_pdf_request=create_pdf_request,
159
+ _request_auth=_request_auth,
160
+ _content_type=_content_type,
161
+ _headers=_headers,
162
+ _host_index=_host_index
163
+ )
164
+
165
+ _response_types_map: Dict[str, Optional[str]] = {
166
+ '200': "CreatePdfResponse",
167
+ '402': None,
168
+ '403': None,
169
+ '404': None,
170
+ '422': "HTTPValidationError",
171
+ }
172
+ response_data = self.api_client.call_api(
173
+ *_param,
174
+ _request_timeout=_request_timeout
175
+ )
176
+ response_data.read()
177
+ return self.api_client.response_deserialize(
178
+ response_data=response_data,
179
+ response_types_map=_response_types_map,
180
+ )
181
+
182
+
183
+ @validate_call
184
+ def create_pdf_without_preload_content(
185
+ self,
186
+ create_pdf_request: CreatePdfRequest,
187
+ _request_timeout: Union[
188
+ None,
189
+ Annotated[StrictFloat, Field(gt=0)],
190
+ Tuple[
191
+ Annotated[StrictFloat, Field(gt=0)],
192
+ Annotated[StrictFloat, Field(gt=0)]
193
+ ]
194
+ ] = None,
195
+ _request_auth: Optional[Dict[StrictStr, Any]] = None,
196
+ _content_type: Optional[StrictStr] = None,
197
+ _headers: Optional[Dict[StrictStr, Any]] = None,
198
+ _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
199
+ ) -> RESTResponseType:
200
+ """Generate PDF from template
201
+
202
+ Generate a PDF from a saved template with dynamic data. **Authentication:** API Key required (`x-api-key` header) ## Request Body | Field | Type | Required | Description | |-------|------|----------|-------------| | `template_id` | string | ✅ Yes | Template short ID (12 characters) | | `data` | object | ✅ Yes | Key-value data to render in template | | `export_type` | string | No | `url` (default) or `binary` | | `expiration` | integer | No | URL expiration in seconds (60-604800, default: 86400) | ## Export Types - `url` (default): PDF is uploaded to CDN, returns JSON with URL - `binary`: Returns raw PDF bytes directly **Credits:** 1 credit deducted per successful generation.
203
+
204
+ :param create_pdf_request: (required)
205
+ :type create_pdf_request: CreatePdfRequest
206
+ :param _request_timeout: timeout setting for this request. If one
207
+ number provided, it will be total request
208
+ timeout. It can also be a pair (tuple) of
209
+ (connection, read) timeouts.
210
+ :type _request_timeout: int, tuple(int, int), optional
211
+ :param _request_auth: set to override the auth_settings for an a single
212
+ request; this effectively ignores the
213
+ authentication in the spec for a single request.
214
+ :type _request_auth: dict, optional
215
+ :param _content_type: force content-type for the request.
216
+ :type _content_type: str, Optional
217
+ :param _headers: set to override the headers for a single
218
+ request; this effectively ignores the headers
219
+ in the spec for a single request.
220
+ :type _headers: dict, optional
221
+ :param _host_index: set to override the host_index for a single
222
+ request; this effectively ignores the host_index
223
+ in the spec for a single request.
224
+ :type _host_index: int, optional
225
+ :return: Returns the result object.
226
+ """ # noqa: E501
227
+
228
+ _param = self._create_pdf_serialize(
229
+ create_pdf_request=create_pdf_request,
230
+ _request_auth=_request_auth,
231
+ _content_type=_content_type,
232
+ _headers=_headers,
233
+ _host_index=_host_index
234
+ )
235
+
236
+ _response_types_map: Dict[str, Optional[str]] = {
237
+ '200': "CreatePdfResponse",
238
+ '402': None,
239
+ '403': None,
240
+ '404': None,
241
+ '422': "HTTPValidationError",
242
+ }
243
+ response_data = self.api_client.call_api(
244
+ *_param,
245
+ _request_timeout=_request_timeout
246
+ )
247
+ return response_data.response
248
+
249
+
250
+ def _create_pdf_serialize(
251
+ self,
252
+ create_pdf_request,
253
+ _request_auth,
254
+ _content_type,
255
+ _headers,
256
+ _host_index,
257
+ ) -> RequestSerialized:
258
+
259
+ _host = None
260
+
261
+ _collection_formats: Dict[str, str] = {
262
+ }
263
+
264
+ _path_params: Dict[str, str] = {}
265
+ _query_params: List[Tuple[str, str]] = []
266
+ _header_params: Dict[str, Optional[str]] = _headers or {}
267
+ _form_params: List[Tuple[str, str]] = []
268
+ _files: Dict[
269
+ str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]]
270
+ ] = {}
271
+ _body_params: Optional[bytes] = None
272
+
273
+ # process the path parameters
274
+ # process the query parameters
275
+ # process the header parameters
276
+ # process the form parameters
277
+ # process the body parameter
278
+ if create_pdf_request is not None:
279
+ _body_params = create_pdf_request
280
+
281
+
282
+ # set the HTTP header `Accept`
283
+ if 'Accept' not in _header_params:
284
+ _header_params['Accept'] = self.api_client.select_header_accept(
285
+ [
286
+ 'application/json',
287
+ 'application/pdf'
288
+ ]
289
+ )
290
+
291
+ # set the HTTP header `Content-Type`
292
+ if _content_type:
293
+ _header_params['Content-Type'] = _content_type
294
+ else:
295
+ _default_content_type = (
296
+ self.api_client.select_header_content_type(
297
+ [
298
+ 'application/json'
299
+ ]
300
+ )
301
+ )
302
+ if _default_content_type is not None:
303
+ _header_params['Content-Type'] = _default_content_type
304
+
305
+ # authentication setting
306
+ _auth_settings: List[str] = [
307
+ 'ApiKeyAuth'
308
+ ]
309
+
310
+ return self.api_client.param_serialize(
311
+ method='POST',
312
+ resource_path='/v1/pdf/create',
313
+ path_params=_path_params,
314
+ query_params=_query_params,
315
+ header_params=_header_params,
316
+ body=_body_params,
317
+ post_params=_form_params,
318
+ files=_files,
319
+ auth_settings=_auth_settings,
320
+ collection_formats=_collection_formats,
321
+ _host=_host,
322
+ _request_auth=_request_auth
323
+ )
324
+
325
+