pulse-python-sdk 0.0.52__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.
- pulse/__init__.py +42 -0
- pulse/client.py +666 -0
- pulse/core/__init__.py +34 -0
- pulse/core/api_error.py +23 -0
- pulse/core/client_wrapper.py +89 -0
- pulse/core/datetime_utils.py +28 -0
- pulse/core/file.py +67 -0
- pulse/core/force_multipart.py +18 -0
- pulse/core/http_client.py +663 -0
- pulse/core/http_response.py +55 -0
- pulse/core/http_sse/__init__.py +42 -0
- pulse/core/http_sse/_api.py +112 -0
- pulse/core/http_sse/_decoders.py +61 -0
- pulse/core/http_sse/_exceptions.py +7 -0
- pulse/core/http_sse/_models.py +17 -0
- pulse/core/jsonable_encoder.py +100 -0
- pulse/core/pydantic_utilities.py +260 -0
- pulse/core/query_encoder.py +58 -0
- pulse/core/remove_none_from_dict.py +11 -0
- pulse/core/request_options.py +35 -0
- pulse/core/serialization.py +276 -0
- pulse/core/unchecked_base_model.py +396 -0
- pulse/environment.py +7 -0
- pulse/errors/__init__.py +4 -0
- pulse/errors/bad_request_error.py +10 -0
- pulse/errors/forbidden_error.py +10 -0
- pulse/errors/internal_server_error.py +10 -0
- pulse/errors/not_found_error.py +10 -0
- pulse/errors/too_many_requests_error.py +10 -0
- pulse/errors/unauthorized_error.py +10 -0
- pulse/jobs/__init__.py +4 -0
- pulse/jobs/client.py +191 -0
- pulse/jobs/raw_client.py +408 -0
- pulse/py.typed +0 -0
- pulse/raw_client.py +661 -0
- pulse/types/__init__.py +4 -0
- pulse/types/extract_async_input.py +5 -0
- pulse/types/extract_async_response.py +43 -0
- pulse/types/extract_async_submission_response_status.py +7 -0
- pulse/types/extract_input.py +5 -0
- pulse/types/extract_json_input.py +116 -0
- pulse/types/extract_json_input_experimental_schema.py +5 -0
- pulse/types/extract_json_input_schema.py +5 -0
- pulse/types/extract_json_input_storage.py +36 -0
- pulse/types/extract_json_input_structured_output.py +38 -0
- pulse/types/extract_multipart_input.py +111 -0
- pulse/types/extract_multipart_input_experimental_schema.py +5 -0
- pulse/types/extract_multipart_input_schema.py +5 -0
- pulse/types/extract_multipart_input_storage.py +36 -0
- pulse/types/extract_multipart_input_structured_output.py +38 -0
- pulse/types/extract_options.py +111 -0
- pulse/types/extract_options_experimental_schema.py +5 -0
- pulse/types/extract_options_schema.py +5 -0
- pulse/types/extract_options_storage.py +36 -0
- pulse/types/extract_options_structured_output.py +38 -0
- pulse/types/extract_response.py +47 -0
- pulse/types/extract_source_multipart_one.py +27 -0
- pulse/types/extract_source_multipart_zero.py +27 -0
- pulse/types/job_cancellation_response.py +32 -0
- pulse/types/job_status.py +5 -0
- pulse/types/job_status_response.py +50 -0
- pulse/types/json_source.py +29 -0
- pulse/types/multipart_source.py +8 -0
- pulse/version.py +3 -0
- pulse/webhooks/__init__.py +4 -0
- pulse/webhooks/client.py +104 -0
- pulse/webhooks/raw_client.py +139 -0
- pulse/webhooks/types/__init__.py +4 -0
- pulse/webhooks/types/create_webhook_link_response.py +23 -0
- pulse_python_sdk-0.0.52.dist-info/METADATA +197 -0
- pulse_python_sdk-0.0.52.dist-info/RECORD +72 -0
- pulse_python_sdk-0.0.52.dist-info/WHEEL +4 -0
pulse/client.py
ADDED
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
9
|
+
from .core.request_options import RequestOptions
|
|
10
|
+
from .environment import PulseEnvironment
|
|
11
|
+
from .raw_client import AsyncRawPulse, RawPulse
|
|
12
|
+
from .types.extract_async_response import ExtractAsyncResponse
|
|
13
|
+
from .types.extract_json_input_experimental_schema import ExtractJsonInputExperimentalSchema
|
|
14
|
+
from .types.extract_json_input_schema import ExtractJsonInputSchema
|
|
15
|
+
from .types.extract_json_input_storage import ExtractJsonInputStorage
|
|
16
|
+
from .types.extract_json_input_structured_output import ExtractJsonInputStructuredOutput
|
|
17
|
+
from .types.extract_response import ExtractResponse
|
|
18
|
+
|
|
19
|
+
if typing.TYPE_CHECKING:
|
|
20
|
+
from .jobs.client import AsyncJobsClient, JobsClient
|
|
21
|
+
from .webhooks.client import AsyncWebhooksClient, WebhooksClient
|
|
22
|
+
# this is used as the default value for optional parameters
|
|
23
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Pulse:
|
|
27
|
+
"""
|
|
28
|
+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
base_url : typing.Optional[str]
|
|
33
|
+
The base url to use for requests from the client.
|
|
34
|
+
|
|
35
|
+
environment : PulseEnvironment
|
|
36
|
+
The environment to use for requests from the client. from .environment import PulseEnvironment
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Defaults to PulseEnvironment.DEFAULT
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
api_key : str
|
|
45
|
+
headers : typing.Optional[typing.Dict[str, str]]
|
|
46
|
+
Additional headers to send with every request.
|
|
47
|
+
|
|
48
|
+
timeout : typing.Optional[float]
|
|
49
|
+
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
50
|
+
|
|
51
|
+
follow_redirects : typing.Optional[bool]
|
|
52
|
+
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
|
|
53
|
+
|
|
54
|
+
httpx_client : typing.Optional[httpx.Client]
|
|
55
|
+
The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
|
|
56
|
+
|
|
57
|
+
Examples
|
|
58
|
+
--------
|
|
59
|
+
from pulse import Pulse
|
|
60
|
+
|
|
61
|
+
client = Pulse(
|
|
62
|
+
api_key="YOUR_API_KEY",
|
|
63
|
+
)
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
def __init__(
|
|
67
|
+
self,
|
|
68
|
+
*,
|
|
69
|
+
base_url: typing.Optional[str] = None,
|
|
70
|
+
environment: PulseEnvironment = PulseEnvironment.DEFAULT,
|
|
71
|
+
api_key: str,
|
|
72
|
+
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
73
|
+
timeout: typing.Optional[float] = None,
|
|
74
|
+
follow_redirects: typing.Optional[bool] = True,
|
|
75
|
+
httpx_client: typing.Optional[httpx.Client] = None,
|
|
76
|
+
):
|
|
77
|
+
_defaulted_timeout = (
|
|
78
|
+
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
|
|
79
|
+
)
|
|
80
|
+
self._client_wrapper = SyncClientWrapper(
|
|
81
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
82
|
+
api_key=api_key,
|
|
83
|
+
headers=headers,
|
|
84
|
+
httpx_client=httpx_client
|
|
85
|
+
if httpx_client is not None
|
|
86
|
+
else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
|
|
87
|
+
if follow_redirects is not None
|
|
88
|
+
else httpx.Client(timeout=_defaulted_timeout),
|
|
89
|
+
timeout=_defaulted_timeout,
|
|
90
|
+
)
|
|
91
|
+
self._raw_client = RawPulse(client_wrapper=self._client_wrapper)
|
|
92
|
+
self._jobs: typing.Optional[JobsClient] = None
|
|
93
|
+
self._webhooks: typing.Optional[WebhooksClient] = None
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def with_raw_response(self) -> RawPulse:
|
|
97
|
+
"""
|
|
98
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
RawPulse
|
|
103
|
+
"""
|
|
104
|
+
return self._raw_client
|
|
105
|
+
|
|
106
|
+
def extract(
|
|
107
|
+
self,
|
|
108
|
+
*,
|
|
109
|
+
file_url: str,
|
|
110
|
+
structured_output: typing.Optional[ExtractJsonInputStructuredOutput] = OMIT,
|
|
111
|
+
schema: typing.Optional[ExtractJsonInputSchema] = OMIT,
|
|
112
|
+
experimental_schema: typing.Optional[ExtractJsonInputExperimentalSchema] = OMIT,
|
|
113
|
+
schema_prompt: typing.Optional[str] = OMIT,
|
|
114
|
+
custom_prompt: typing.Optional[str] = OMIT,
|
|
115
|
+
chunking: typing.Optional[str] = OMIT,
|
|
116
|
+
chunk_size: typing.Optional[int] = OMIT,
|
|
117
|
+
pages: typing.Optional[str] = OMIT,
|
|
118
|
+
extract_figure: typing.Optional[bool] = OMIT,
|
|
119
|
+
figure_description: typing.Optional[bool] = OMIT,
|
|
120
|
+
return_html: typing.Optional[bool] = OMIT,
|
|
121
|
+
thinking: typing.Optional[bool] = OMIT,
|
|
122
|
+
storage: typing.Optional[ExtractJsonInputStorage] = OMIT,
|
|
123
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
124
|
+
) -> ExtractResponse:
|
|
125
|
+
"""
|
|
126
|
+
The primary endpoint for the Pulse API. Parses uploaded documents or remote
|
|
127
|
+
file URLs and returns rich markdown content with optional structured data
|
|
128
|
+
extraction based on user-provided schemas and extraction options.
|
|
129
|
+
|
|
130
|
+
Parameters
|
|
131
|
+
----------
|
|
132
|
+
file_url : str
|
|
133
|
+
Public or pre-signed URL that Pulse will download and extract.
|
|
134
|
+
|
|
135
|
+
structured_output : typing.Optional[ExtractJsonInputStructuredOutput]
|
|
136
|
+
Recommended method for schema-guided extraction. Contains the schema and optional prompt in a single object.
|
|
137
|
+
|
|
138
|
+
schema : typing.Optional[ExtractJsonInputSchema]
|
|
139
|
+
(Deprecated) JSON schema describing structured data to extract. Use structuredOutput instead. Accepts either a JSON object or a stringified JSON representation.
|
|
140
|
+
|
|
141
|
+
experimental_schema : typing.Optional[ExtractJsonInputExperimentalSchema]
|
|
142
|
+
(Deprecated) Experimental schema definition used for feature flagged behaviour. Accepts either a JSON object or a stringified JSON representation.
|
|
143
|
+
|
|
144
|
+
schema_prompt : typing.Optional[str]
|
|
145
|
+
(Deprecated) Natural language prompt for schema-guided extraction. Use structuredOutput.schemaPrompt instead.
|
|
146
|
+
|
|
147
|
+
custom_prompt : typing.Optional[str]
|
|
148
|
+
(Deprecated) Custom instructions that augment the default extraction behaviour.
|
|
149
|
+
|
|
150
|
+
chunking : typing.Optional[str]
|
|
151
|
+
Comma-separated list of chunking strategies to apply (for example `semantic,header,page,recursive`).
|
|
152
|
+
|
|
153
|
+
chunk_size : typing.Optional[int]
|
|
154
|
+
Override for maximum characters per chunk when chunking is enabled.
|
|
155
|
+
|
|
156
|
+
pages : typing.Optional[str]
|
|
157
|
+
Page range filter supporting segments such as `1-2` or mixed ranges like `1-2,5`.
|
|
158
|
+
|
|
159
|
+
extract_figure : typing.Optional[bool]
|
|
160
|
+
Toggle to enable figure extraction in results.
|
|
161
|
+
|
|
162
|
+
figure_description : typing.Optional[bool]
|
|
163
|
+
Toggle to generate descriptive captions for extracted figures.
|
|
164
|
+
|
|
165
|
+
return_html : typing.Optional[bool]
|
|
166
|
+
Whether to include HTML representation alongside markdown in the response.
|
|
167
|
+
|
|
168
|
+
thinking : typing.Optional[bool]
|
|
169
|
+
(Deprecated) Enables expanded rationale output for debugging.
|
|
170
|
+
|
|
171
|
+
storage : typing.Optional[ExtractJsonInputStorage]
|
|
172
|
+
Options for persisting extraction artifacts. When enabled (default), artifacts are saved to storage and a database record is created.
|
|
173
|
+
|
|
174
|
+
request_options : typing.Optional[RequestOptions]
|
|
175
|
+
Request-specific configuration.
|
|
176
|
+
|
|
177
|
+
Returns
|
|
178
|
+
-------
|
|
179
|
+
ExtractResponse
|
|
180
|
+
Synchronous extraction result
|
|
181
|
+
|
|
182
|
+
Examples
|
|
183
|
+
--------
|
|
184
|
+
from pulse import Pulse
|
|
185
|
+
|
|
186
|
+
client = Pulse(
|
|
187
|
+
api_key="YOUR_API_KEY",
|
|
188
|
+
)
|
|
189
|
+
client.extract(
|
|
190
|
+
file_url="fileUrl",
|
|
191
|
+
)
|
|
192
|
+
"""
|
|
193
|
+
_response = self._raw_client.extract(
|
|
194
|
+
file_url=file_url,
|
|
195
|
+
structured_output=structured_output,
|
|
196
|
+
schema=schema,
|
|
197
|
+
experimental_schema=experimental_schema,
|
|
198
|
+
schema_prompt=schema_prompt,
|
|
199
|
+
custom_prompt=custom_prompt,
|
|
200
|
+
chunking=chunking,
|
|
201
|
+
chunk_size=chunk_size,
|
|
202
|
+
pages=pages,
|
|
203
|
+
extract_figure=extract_figure,
|
|
204
|
+
figure_description=figure_description,
|
|
205
|
+
return_html=return_html,
|
|
206
|
+
thinking=thinking,
|
|
207
|
+
storage=storage,
|
|
208
|
+
request_options=request_options,
|
|
209
|
+
)
|
|
210
|
+
return _response.data
|
|
211
|
+
|
|
212
|
+
def extract_async(
|
|
213
|
+
self,
|
|
214
|
+
*,
|
|
215
|
+
file_url: str,
|
|
216
|
+
structured_output: typing.Optional[ExtractJsonInputStructuredOutput] = OMIT,
|
|
217
|
+
schema: typing.Optional[ExtractJsonInputSchema] = OMIT,
|
|
218
|
+
experimental_schema: typing.Optional[ExtractJsonInputExperimentalSchema] = OMIT,
|
|
219
|
+
schema_prompt: typing.Optional[str] = OMIT,
|
|
220
|
+
custom_prompt: typing.Optional[str] = OMIT,
|
|
221
|
+
chunking: typing.Optional[str] = OMIT,
|
|
222
|
+
chunk_size: typing.Optional[int] = OMIT,
|
|
223
|
+
pages: typing.Optional[str] = OMIT,
|
|
224
|
+
extract_figure: typing.Optional[bool] = OMIT,
|
|
225
|
+
figure_description: typing.Optional[bool] = OMIT,
|
|
226
|
+
return_html: typing.Optional[bool] = OMIT,
|
|
227
|
+
thinking: typing.Optional[bool] = OMIT,
|
|
228
|
+
storage: typing.Optional[ExtractJsonInputStorage] = OMIT,
|
|
229
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
230
|
+
) -> ExtractAsyncResponse:
|
|
231
|
+
"""
|
|
232
|
+
Starts an asynchronous extraction job. The request mirrors the
|
|
233
|
+
synchronous options but returns immediately with a job identifier that
|
|
234
|
+
clients can poll for completion status.
|
|
235
|
+
|
|
236
|
+
Parameters
|
|
237
|
+
----------
|
|
238
|
+
file_url : str
|
|
239
|
+
Public or pre-signed URL that Pulse will download and extract.
|
|
240
|
+
|
|
241
|
+
structured_output : typing.Optional[ExtractJsonInputStructuredOutput]
|
|
242
|
+
Recommended method for schema-guided extraction. Contains the schema and optional prompt in a single object.
|
|
243
|
+
|
|
244
|
+
schema : typing.Optional[ExtractJsonInputSchema]
|
|
245
|
+
(Deprecated) JSON schema describing structured data to extract. Use structuredOutput instead. Accepts either a JSON object or a stringified JSON representation.
|
|
246
|
+
|
|
247
|
+
experimental_schema : typing.Optional[ExtractJsonInputExperimentalSchema]
|
|
248
|
+
(Deprecated) Experimental schema definition used for feature flagged behaviour. Accepts either a JSON object or a stringified JSON representation.
|
|
249
|
+
|
|
250
|
+
schema_prompt : typing.Optional[str]
|
|
251
|
+
(Deprecated) Natural language prompt for schema-guided extraction. Use structuredOutput.schemaPrompt instead.
|
|
252
|
+
|
|
253
|
+
custom_prompt : typing.Optional[str]
|
|
254
|
+
(Deprecated) Custom instructions that augment the default extraction behaviour.
|
|
255
|
+
|
|
256
|
+
chunking : typing.Optional[str]
|
|
257
|
+
Comma-separated list of chunking strategies to apply (for example `semantic,header,page,recursive`).
|
|
258
|
+
|
|
259
|
+
chunk_size : typing.Optional[int]
|
|
260
|
+
Override for maximum characters per chunk when chunking is enabled.
|
|
261
|
+
|
|
262
|
+
pages : typing.Optional[str]
|
|
263
|
+
Page range filter supporting segments such as `1-2` or mixed ranges like `1-2,5`.
|
|
264
|
+
|
|
265
|
+
extract_figure : typing.Optional[bool]
|
|
266
|
+
Toggle to enable figure extraction in results.
|
|
267
|
+
|
|
268
|
+
figure_description : typing.Optional[bool]
|
|
269
|
+
Toggle to generate descriptive captions for extracted figures.
|
|
270
|
+
|
|
271
|
+
return_html : typing.Optional[bool]
|
|
272
|
+
Whether to include HTML representation alongside markdown in the response.
|
|
273
|
+
|
|
274
|
+
thinking : typing.Optional[bool]
|
|
275
|
+
(Deprecated) Enables expanded rationale output for debugging.
|
|
276
|
+
|
|
277
|
+
storage : typing.Optional[ExtractJsonInputStorage]
|
|
278
|
+
Options for persisting extraction artifacts. When enabled (default), artifacts are saved to storage and a database record is created.
|
|
279
|
+
|
|
280
|
+
request_options : typing.Optional[RequestOptions]
|
|
281
|
+
Request-specific configuration.
|
|
282
|
+
|
|
283
|
+
Returns
|
|
284
|
+
-------
|
|
285
|
+
ExtractAsyncResponse
|
|
286
|
+
Asynchronous extraction job accepted
|
|
287
|
+
|
|
288
|
+
Examples
|
|
289
|
+
--------
|
|
290
|
+
from pulse import Pulse
|
|
291
|
+
|
|
292
|
+
client = Pulse(
|
|
293
|
+
api_key="YOUR_API_KEY",
|
|
294
|
+
)
|
|
295
|
+
client.extract_async(
|
|
296
|
+
file_url="fileUrl",
|
|
297
|
+
)
|
|
298
|
+
"""
|
|
299
|
+
_response = self._raw_client.extract_async(
|
|
300
|
+
file_url=file_url,
|
|
301
|
+
structured_output=structured_output,
|
|
302
|
+
schema=schema,
|
|
303
|
+
experimental_schema=experimental_schema,
|
|
304
|
+
schema_prompt=schema_prompt,
|
|
305
|
+
custom_prompt=custom_prompt,
|
|
306
|
+
chunking=chunking,
|
|
307
|
+
chunk_size=chunk_size,
|
|
308
|
+
pages=pages,
|
|
309
|
+
extract_figure=extract_figure,
|
|
310
|
+
figure_description=figure_description,
|
|
311
|
+
return_html=return_html,
|
|
312
|
+
thinking=thinking,
|
|
313
|
+
storage=storage,
|
|
314
|
+
request_options=request_options,
|
|
315
|
+
)
|
|
316
|
+
return _response.data
|
|
317
|
+
|
|
318
|
+
@property
|
|
319
|
+
def jobs(self):
|
|
320
|
+
if self._jobs is None:
|
|
321
|
+
from .jobs.client import JobsClient # noqa: E402
|
|
322
|
+
|
|
323
|
+
self._jobs = JobsClient(client_wrapper=self._client_wrapper)
|
|
324
|
+
return self._jobs
|
|
325
|
+
|
|
326
|
+
@property
|
|
327
|
+
def webhooks(self):
|
|
328
|
+
if self._webhooks is None:
|
|
329
|
+
from .webhooks.client import WebhooksClient # noqa: E402
|
|
330
|
+
|
|
331
|
+
self._webhooks = WebhooksClient(client_wrapper=self._client_wrapper)
|
|
332
|
+
return self._webhooks
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class AsyncPulse:
|
|
336
|
+
"""
|
|
337
|
+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
|
|
338
|
+
|
|
339
|
+
Parameters
|
|
340
|
+
----------
|
|
341
|
+
base_url : typing.Optional[str]
|
|
342
|
+
The base url to use for requests from the client.
|
|
343
|
+
|
|
344
|
+
environment : PulseEnvironment
|
|
345
|
+
The environment to use for requests from the client. from .environment import PulseEnvironment
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
Defaults to PulseEnvironment.DEFAULT
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
api_key : str
|
|
354
|
+
headers : typing.Optional[typing.Dict[str, str]]
|
|
355
|
+
Additional headers to send with every request.
|
|
356
|
+
|
|
357
|
+
timeout : typing.Optional[float]
|
|
358
|
+
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
359
|
+
|
|
360
|
+
follow_redirects : typing.Optional[bool]
|
|
361
|
+
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
|
|
362
|
+
|
|
363
|
+
httpx_client : typing.Optional[httpx.AsyncClient]
|
|
364
|
+
The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
|
|
365
|
+
|
|
366
|
+
Examples
|
|
367
|
+
--------
|
|
368
|
+
from pulse import AsyncPulse
|
|
369
|
+
|
|
370
|
+
client = AsyncPulse(
|
|
371
|
+
api_key="YOUR_API_KEY",
|
|
372
|
+
)
|
|
373
|
+
"""
|
|
374
|
+
|
|
375
|
+
def __init__(
|
|
376
|
+
self,
|
|
377
|
+
*,
|
|
378
|
+
base_url: typing.Optional[str] = None,
|
|
379
|
+
environment: PulseEnvironment = PulseEnvironment.DEFAULT,
|
|
380
|
+
api_key: str,
|
|
381
|
+
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
382
|
+
timeout: typing.Optional[float] = None,
|
|
383
|
+
follow_redirects: typing.Optional[bool] = True,
|
|
384
|
+
httpx_client: typing.Optional[httpx.AsyncClient] = None,
|
|
385
|
+
):
|
|
386
|
+
_defaulted_timeout = (
|
|
387
|
+
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
|
|
388
|
+
)
|
|
389
|
+
self._client_wrapper = AsyncClientWrapper(
|
|
390
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
391
|
+
api_key=api_key,
|
|
392
|
+
headers=headers,
|
|
393
|
+
httpx_client=httpx_client
|
|
394
|
+
if httpx_client is not None
|
|
395
|
+
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
|
|
396
|
+
if follow_redirects is not None
|
|
397
|
+
else httpx.AsyncClient(timeout=_defaulted_timeout),
|
|
398
|
+
timeout=_defaulted_timeout,
|
|
399
|
+
)
|
|
400
|
+
self._raw_client = AsyncRawPulse(client_wrapper=self._client_wrapper)
|
|
401
|
+
self._jobs: typing.Optional[AsyncJobsClient] = None
|
|
402
|
+
self._webhooks: typing.Optional[AsyncWebhooksClient] = None
|
|
403
|
+
|
|
404
|
+
@property
|
|
405
|
+
def with_raw_response(self) -> AsyncRawPulse:
|
|
406
|
+
"""
|
|
407
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
408
|
+
|
|
409
|
+
Returns
|
|
410
|
+
-------
|
|
411
|
+
AsyncRawPulse
|
|
412
|
+
"""
|
|
413
|
+
return self._raw_client
|
|
414
|
+
|
|
415
|
+
async def extract(
|
|
416
|
+
self,
|
|
417
|
+
*,
|
|
418
|
+
file_url: str,
|
|
419
|
+
structured_output: typing.Optional[ExtractJsonInputStructuredOutput] = OMIT,
|
|
420
|
+
schema: typing.Optional[ExtractJsonInputSchema] = OMIT,
|
|
421
|
+
experimental_schema: typing.Optional[ExtractJsonInputExperimentalSchema] = OMIT,
|
|
422
|
+
schema_prompt: typing.Optional[str] = OMIT,
|
|
423
|
+
custom_prompt: typing.Optional[str] = OMIT,
|
|
424
|
+
chunking: typing.Optional[str] = OMIT,
|
|
425
|
+
chunk_size: typing.Optional[int] = OMIT,
|
|
426
|
+
pages: typing.Optional[str] = OMIT,
|
|
427
|
+
extract_figure: typing.Optional[bool] = OMIT,
|
|
428
|
+
figure_description: typing.Optional[bool] = OMIT,
|
|
429
|
+
return_html: typing.Optional[bool] = OMIT,
|
|
430
|
+
thinking: typing.Optional[bool] = OMIT,
|
|
431
|
+
storage: typing.Optional[ExtractJsonInputStorage] = OMIT,
|
|
432
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
433
|
+
) -> ExtractResponse:
|
|
434
|
+
"""
|
|
435
|
+
The primary endpoint for the Pulse API. Parses uploaded documents or remote
|
|
436
|
+
file URLs and returns rich markdown content with optional structured data
|
|
437
|
+
extraction based on user-provided schemas and extraction options.
|
|
438
|
+
|
|
439
|
+
Parameters
|
|
440
|
+
----------
|
|
441
|
+
file_url : str
|
|
442
|
+
Public or pre-signed URL that Pulse will download and extract.
|
|
443
|
+
|
|
444
|
+
structured_output : typing.Optional[ExtractJsonInputStructuredOutput]
|
|
445
|
+
Recommended method for schema-guided extraction. Contains the schema and optional prompt in a single object.
|
|
446
|
+
|
|
447
|
+
schema : typing.Optional[ExtractJsonInputSchema]
|
|
448
|
+
(Deprecated) JSON schema describing structured data to extract. Use structuredOutput instead. Accepts either a JSON object or a stringified JSON representation.
|
|
449
|
+
|
|
450
|
+
experimental_schema : typing.Optional[ExtractJsonInputExperimentalSchema]
|
|
451
|
+
(Deprecated) Experimental schema definition used for feature flagged behaviour. Accepts either a JSON object or a stringified JSON representation.
|
|
452
|
+
|
|
453
|
+
schema_prompt : typing.Optional[str]
|
|
454
|
+
(Deprecated) Natural language prompt for schema-guided extraction. Use structuredOutput.schemaPrompt instead.
|
|
455
|
+
|
|
456
|
+
custom_prompt : typing.Optional[str]
|
|
457
|
+
(Deprecated) Custom instructions that augment the default extraction behaviour.
|
|
458
|
+
|
|
459
|
+
chunking : typing.Optional[str]
|
|
460
|
+
Comma-separated list of chunking strategies to apply (for example `semantic,header,page,recursive`).
|
|
461
|
+
|
|
462
|
+
chunk_size : typing.Optional[int]
|
|
463
|
+
Override for maximum characters per chunk when chunking is enabled.
|
|
464
|
+
|
|
465
|
+
pages : typing.Optional[str]
|
|
466
|
+
Page range filter supporting segments such as `1-2` or mixed ranges like `1-2,5`.
|
|
467
|
+
|
|
468
|
+
extract_figure : typing.Optional[bool]
|
|
469
|
+
Toggle to enable figure extraction in results.
|
|
470
|
+
|
|
471
|
+
figure_description : typing.Optional[bool]
|
|
472
|
+
Toggle to generate descriptive captions for extracted figures.
|
|
473
|
+
|
|
474
|
+
return_html : typing.Optional[bool]
|
|
475
|
+
Whether to include HTML representation alongside markdown in the response.
|
|
476
|
+
|
|
477
|
+
thinking : typing.Optional[bool]
|
|
478
|
+
(Deprecated) Enables expanded rationale output for debugging.
|
|
479
|
+
|
|
480
|
+
storage : typing.Optional[ExtractJsonInputStorage]
|
|
481
|
+
Options for persisting extraction artifacts. When enabled (default), artifacts are saved to storage and a database record is created.
|
|
482
|
+
|
|
483
|
+
request_options : typing.Optional[RequestOptions]
|
|
484
|
+
Request-specific configuration.
|
|
485
|
+
|
|
486
|
+
Returns
|
|
487
|
+
-------
|
|
488
|
+
ExtractResponse
|
|
489
|
+
Synchronous extraction result
|
|
490
|
+
|
|
491
|
+
Examples
|
|
492
|
+
--------
|
|
493
|
+
import asyncio
|
|
494
|
+
|
|
495
|
+
from pulse import AsyncPulse
|
|
496
|
+
|
|
497
|
+
client = AsyncPulse(
|
|
498
|
+
api_key="YOUR_API_KEY",
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
async def main() -> None:
|
|
503
|
+
await client.extract(
|
|
504
|
+
file_url="fileUrl",
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
asyncio.run(main())
|
|
509
|
+
"""
|
|
510
|
+
_response = await self._raw_client.extract(
|
|
511
|
+
file_url=file_url,
|
|
512
|
+
structured_output=structured_output,
|
|
513
|
+
schema=schema,
|
|
514
|
+
experimental_schema=experimental_schema,
|
|
515
|
+
schema_prompt=schema_prompt,
|
|
516
|
+
custom_prompt=custom_prompt,
|
|
517
|
+
chunking=chunking,
|
|
518
|
+
chunk_size=chunk_size,
|
|
519
|
+
pages=pages,
|
|
520
|
+
extract_figure=extract_figure,
|
|
521
|
+
figure_description=figure_description,
|
|
522
|
+
return_html=return_html,
|
|
523
|
+
thinking=thinking,
|
|
524
|
+
storage=storage,
|
|
525
|
+
request_options=request_options,
|
|
526
|
+
)
|
|
527
|
+
return _response.data
|
|
528
|
+
|
|
529
|
+
async def extract_async(
|
|
530
|
+
self,
|
|
531
|
+
*,
|
|
532
|
+
file_url: str,
|
|
533
|
+
structured_output: typing.Optional[ExtractJsonInputStructuredOutput] = OMIT,
|
|
534
|
+
schema: typing.Optional[ExtractJsonInputSchema] = OMIT,
|
|
535
|
+
experimental_schema: typing.Optional[ExtractJsonInputExperimentalSchema] = OMIT,
|
|
536
|
+
schema_prompt: typing.Optional[str] = OMIT,
|
|
537
|
+
custom_prompt: typing.Optional[str] = OMIT,
|
|
538
|
+
chunking: typing.Optional[str] = OMIT,
|
|
539
|
+
chunk_size: typing.Optional[int] = OMIT,
|
|
540
|
+
pages: typing.Optional[str] = OMIT,
|
|
541
|
+
extract_figure: typing.Optional[bool] = OMIT,
|
|
542
|
+
figure_description: typing.Optional[bool] = OMIT,
|
|
543
|
+
return_html: typing.Optional[bool] = OMIT,
|
|
544
|
+
thinking: typing.Optional[bool] = OMIT,
|
|
545
|
+
storage: typing.Optional[ExtractJsonInputStorage] = OMIT,
|
|
546
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
547
|
+
) -> ExtractAsyncResponse:
|
|
548
|
+
"""
|
|
549
|
+
Starts an asynchronous extraction job. The request mirrors the
|
|
550
|
+
synchronous options but returns immediately with a job identifier that
|
|
551
|
+
clients can poll for completion status.
|
|
552
|
+
|
|
553
|
+
Parameters
|
|
554
|
+
----------
|
|
555
|
+
file_url : str
|
|
556
|
+
Public or pre-signed URL that Pulse will download and extract.
|
|
557
|
+
|
|
558
|
+
structured_output : typing.Optional[ExtractJsonInputStructuredOutput]
|
|
559
|
+
Recommended method for schema-guided extraction. Contains the schema and optional prompt in a single object.
|
|
560
|
+
|
|
561
|
+
schema : typing.Optional[ExtractJsonInputSchema]
|
|
562
|
+
(Deprecated) JSON schema describing structured data to extract. Use structuredOutput instead. Accepts either a JSON object or a stringified JSON representation.
|
|
563
|
+
|
|
564
|
+
experimental_schema : typing.Optional[ExtractJsonInputExperimentalSchema]
|
|
565
|
+
(Deprecated) Experimental schema definition used for feature flagged behaviour. Accepts either a JSON object or a stringified JSON representation.
|
|
566
|
+
|
|
567
|
+
schema_prompt : typing.Optional[str]
|
|
568
|
+
(Deprecated) Natural language prompt for schema-guided extraction. Use structuredOutput.schemaPrompt instead.
|
|
569
|
+
|
|
570
|
+
custom_prompt : typing.Optional[str]
|
|
571
|
+
(Deprecated) Custom instructions that augment the default extraction behaviour.
|
|
572
|
+
|
|
573
|
+
chunking : typing.Optional[str]
|
|
574
|
+
Comma-separated list of chunking strategies to apply (for example `semantic,header,page,recursive`).
|
|
575
|
+
|
|
576
|
+
chunk_size : typing.Optional[int]
|
|
577
|
+
Override for maximum characters per chunk when chunking is enabled.
|
|
578
|
+
|
|
579
|
+
pages : typing.Optional[str]
|
|
580
|
+
Page range filter supporting segments such as `1-2` or mixed ranges like `1-2,5`.
|
|
581
|
+
|
|
582
|
+
extract_figure : typing.Optional[bool]
|
|
583
|
+
Toggle to enable figure extraction in results.
|
|
584
|
+
|
|
585
|
+
figure_description : typing.Optional[bool]
|
|
586
|
+
Toggle to generate descriptive captions for extracted figures.
|
|
587
|
+
|
|
588
|
+
return_html : typing.Optional[bool]
|
|
589
|
+
Whether to include HTML representation alongside markdown in the response.
|
|
590
|
+
|
|
591
|
+
thinking : typing.Optional[bool]
|
|
592
|
+
(Deprecated) Enables expanded rationale output for debugging.
|
|
593
|
+
|
|
594
|
+
storage : typing.Optional[ExtractJsonInputStorage]
|
|
595
|
+
Options for persisting extraction artifacts. When enabled (default), artifacts are saved to storage and a database record is created.
|
|
596
|
+
|
|
597
|
+
request_options : typing.Optional[RequestOptions]
|
|
598
|
+
Request-specific configuration.
|
|
599
|
+
|
|
600
|
+
Returns
|
|
601
|
+
-------
|
|
602
|
+
ExtractAsyncResponse
|
|
603
|
+
Asynchronous extraction job accepted
|
|
604
|
+
|
|
605
|
+
Examples
|
|
606
|
+
--------
|
|
607
|
+
import asyncio
|
|
608
|
+
|
|
609
|
+
from pulse import AsyncPulse
|
|
610
|
+
|
|
611
|
+
client = AsyncPulse(
|
|
612
|
+
api_key="YOUR_API_KEY",
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
async def main() -> None:
|
|
617
|
+
await client.extract_async(
|
|
618
|
+
file_url="fileUrl",
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
asyncio.run(main())
|
|
623
|
+
"""
|
|
624
|
+
_response = await self._raw_client.extract_async(
|
|
625
|
+
file_url=file_url,
|
|
626
|
+
structured_output=structured_output,
|
|
627
|
+
schema=schema,
|
|
628
|
+
experimental_schema=experimental_schema,
|
|
629
|
+
schema_prompt=schema_prompt,
|
|
630
|
+
custom_prompt=custom_prompt,
|
|
631
|
+
chunking=chunking,
|
|
632
|
+
chunk_size=chunk_size,
|
|
633
|
+
pages=pages,
|
|
634
|
+
extract_figure=extract_figure,
|
|
635
|
+
figure_description=figure_description,
|
|
636
|
+
return_html=return_html,
|
|
637
|
+
thinking=thinking,
|
|
638
|
+
storage=storage,
|
|
639
|
+
request_options=request_options,
|
|
640
|
+
)
|
|
641
|
+
return _response.data
|
|
642
|
+
|
|
643
|
+
@property
|
|
644
|
+
def jobs(self):
|
|
645
|
+
if self._jobs is None:
|
|
646
|
+
from .jobs.client import AsyncJobsClient # noqa: E402
|
|
647
|
+
|
|
648
|
+
self._jobs = AsyncJobsClient(client_wrapper=self._client_wrapper)
|
|
649
|
+
return self._jobs
|
|
650
|
+
|
|
651
|
+
@property
|
|
652
|
+
def webhooks(self):
|
|
653
|
+
if self._webhooks is None:
|
|
654
|
+
from .webhooks.client import AsyncWebhooksClient # noqa: E402
|
|
655
|
+
|
|
656
|
+
self._webhooks = AsyncWebhooksClient(client_wrapper=self._client_wrapper)
|
|
657
|
+
return self._webhooks
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: PulseEnvironment) -> str:
|
|
661
|
+
if base_url is not None:
|
|
662
|
+
return base_url
|
|
663
|
+
elif environment is not None:
|
|
664
|
+
return environment.value
|
|
665
|
+
else:
|
|
666
|
+
raise Exception("Please pass in either base_url or environment to construct the client")
|
pulse/core/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
# isort: skip_file
|
|
4
|
+
|
|
5
|
+
import typing
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from .file import File, with_content_type
|
|
10
|
+
_dynamic_imports: typing.Dict[str, str] = {"File": ".file", "with_content_type": ".file"}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def __getattr__(attr_name: str) -> typing.Any:
|
|
14
|
+
module_name = _dynamic_imports.get(attr_name)
|
|
15
|
+
if module_name is None:
|
|
16
|
+
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
|
|
17
|
+
try:
|
|
18
|
+
module = import_module(module_name, __package__)
|
|
19
|
+
if module_name == f".{attr_name}":
|
|
20
|
+
return module
|
|
21
|
+
else:
|
|
22
|
+
return getattr(module, attr_name)
|
|
23
|
+
except ImportError as e:
|
|
24
|
+
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
|
|
25
|
+
except AttributeError as e:
|
|
26
|
+
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def __dir__():
|
|
30
|
+
lazy_attrs = list(_dynamic_imports.keys())
|
|
31
|
+
return sorted(lazy_attrs)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
__all__ = ["File", "with_content_type"]
|