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
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import datetime as dt
|
|
4
|
+
import inspect
|
|
5
|
+
import typing
|
|
6
|
+
import uuid
|
|
7
|
+
|
|
8
|
+
import pydantic
|
|
9
|
+
import typing_extensions
|
|
10
|
+
from .pydantic_utilities import (
|
|
11
|
+
IS_PYDANTIC_V2,
|
|
12
|
+
ModelField,
|
|
13
|
+
UniversalBaseModel,
|
|
14
|
+
get_args,
|
|
15
|
+
get_origin,
|
|
16
|
+
is_literal_type,
|
|
17
|
+
is_union,
|
|
18
|
+
parse_date,
|
|
19
|
+
parse_datetime,
|
|
20
|
+
parse_obj_as,
|
|
21
|
+
)
|
|
22
|
+
from .serialization import convert_and_respect_annotation_metadata, get_field_to_alias_mapping
|
|
23
|
+
from pydantic_core import PydanticUndefined
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class UnionMetadata:
|
|
27
|
+
discriminant: str
|
|
28
|
+
|
|
29
|
+
def __init__(self, *, discriminant: str) -> None:
|
|
30
|
+
self.discriminant = discriminant
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Model = typing.TypeVar("Model", bound=pydantic.BaseModel)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class UncheckedBaseModel(UniversalBaseModel):
|
|
37
|
+
if IS_PYDANTIC_V2:
|
|
38
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow") # type: ignore # Pydantic v2
|
|
39
|
+
else:
|
|
40
|
+
|
|
41
|
+
class Config:
|
|
42
|
+
extra = pydantic.Extra.allow
|
|
43
|
+
|
|
44
|
+
if IS_PYDANTIC_V2:
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def model_validate(
|
|
48
|
+
cls: typing.Type["Model"],
|
|
49
|
+
obj: typing.Any,
|
|
50
|
+
*args: typing.Any,
|
|
51
|
+
**kwargs: typing.Any,
|
|
52
|
+
) -> "Model":
|
|
53
|
+
"""
|
|
54
|
+
Ensure that when using Pydantic v2's `model_validate` entrypoint we still
|
|
55
|
+
respect our FieldMetadata-based aliasing.
|
|
56
|
+
"""
|
|
57
|
+
dealiased_obj = convert_and_respect_annotation_metadata(
|
|
58
|
+
object_=obj,
|
|
59
|
+
annotation=cls,
|
|
60
|
+
direction="read",
|
|
61
|
+
)
|
|
62
|
+
return super().model_validate(dealiased_obj, *args, **kwargs) # type: ignore[misc]
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def model_construct(
|
|
66
|
+
cls: typing.Type["Model"],
|
|
67
|
+
_fields_set: typing.Optional[typing.Set[str]] = None,
|
|
68
|
+
**values: typing.Any,
|
|
69
|
+
) -> "Model":
|
|
70
|
+
# Fallback construct function to the specified override below.
|
|
71
|
+
return cls.construct(_fields_set=_fields_set, **values)
|
|
72
|
+
|
|
73
|
+
# Allow construct to not validate model
|
|
74
|
+
# Implementation taken from: https://github.com/pydantic/pydantic/issues/1168#issuecomment-817742836
|
|
75
|
+
@classmethod
|
|
76
|
+
def construct(
|
|
77
|
+
cls: typing.Type["Model"],
|
|
78
|
+
_fields_set: typing.Optional[typing.Set[str]] = None,
|
|
79
|
+
**values: typing.Any,
|
|
80
|
+
) -> "Model":
|
|
81
|
+
m = cls.__new__(cls)
|
|
82
|
+
fields_values = {}
|
|
83
|
+
|
|
84
|
+
if _fields_set is None:
|
|
85
|
+
_fields_set = set(values.keys())
|
|
86
|
+
|
|
87
|
+
fields = _get_model_fields(cls)
|
|
88
|
+
populate_by_name = _get_is_populate_by_name(cls)
|
|
89
|
+
field_aliases = get_field_to_alias_mapping(cls)
|
|
90
|
+
|
|
91
|
+
for name, field in fields.items():
|
|
92
|
+
# Key here is only used to pull data from the values dict
|
|
93
|
+
# you should always use the NAME of the field to for field_values, etc.
|
|
94
|
+
# because that's how the object is constructed from a pydantic perspective
|
|
95
|
+
key = field.alias
|
|
96
|
+
if (key is None or field.alias == name) and name in field_aliases:
|
|
97
|
+
key = field_aliases[name]
|
|
98
|
+
|
|
99
|
+
if key is None or (key not in values and populate_by_name): # Added this to allow population by field name
|
|
100
|
+
key = name
|
|
101
|
+
|
|
102
|
+
if key in values:
|
|
103
|
+
if IS_PYDANTIC_V2:
|
|
104
|
+
type_ = field.annotation # type: ignore # Pydantic v2
|
|
105
|
+
else:
|
|
106
|
+
type_ = typing.cast(typing.Type, field.outer_type_) # type: ignore # Pydantic < v1.10.15
|
|
107
|
+
|
|
108
|
+
fields_values[name] = (
|
|
109
|
+
construct_type(object_=values[key], type_=type_) if type_ is not None else values[key]
|
|
110
|
+
)
|
|
111
|
+
_fields_set.add(name)
|
|
112
|
+
else:
|
|
113
|
+
default = _get_field_default(field)
|
|
114
|
+
fields_values[name] = default
|
|
115
|
+
|
|
116
|
+
# If the default values are non-null act like they've been set
|
|
117
|
+
# This effectively allows exclude_unset to work like exclude_none where
|
|
118
|
+
# the latter passes through intentionally set none values.
|
|
119
|
+
if default != None and default != PydanticUndefined:
|
|
120
|
+
_fields_set.add(name)
|
|
121
|
+
|
|
122
|
+
# Add extras back in
|
|
123
|
+
extras = {}
|
|
124
|
+
pydantic_alias_fields = [field.alias for field in fields.values()]
|
|
125
|
+
internal_alias_fields = list(field_aliases.values())
|
|
126
|
+
for key, value in values.items():
|
|
127
|
+
# If the key is not a field by name, nor an alias to a field, then it's extra
|
|
128
|
+
if (key not in pydantic_alias_fields and key not in internal_alias_fields) and key not in fields:
|
|
129
|
+
if IS_PYDANTIC_V2:
|
|
130
|
+
extras[key] = value
|
|
131
|
+
else:
|
|
132
|
+
_fields_set.add(key)
|
|
133
|
+
fields_values[key] = value
|
|
134
|
+
|
|
135
|
+
object.__setattr__(m, "__dict__", fields_values)
|
|
136
|
+
|
|
137
|
+
if IS_PYDANTIC_V2:
|
|
138
|
+
object.__setattr__(m, "__pydantic_private__", None)
|
|
139
|
+
object.__setattr__(m, "__pydantic_extra__", extras)
|
|
140
|
+
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
|
|
141
|
+
else:
|
|
142
|
+
object.__setattr__(m, "__fields_set__", _fields_set)
|
|
143
|
+
m._init_private_attributes() # type: ignore # Pydantic v1
|
|
144
|
+
return m
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _validate_collection_items_compatible(collection: typing.Any, target_type: typing.Type[typing.Any]) -> bool:
|
|
148
|
+
"""
|
|
149
|
+
Validate that all items in a collection are compatible with the target type.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
collection: The collection to validate (list, set, or dict values)
|
|
153
|
+
target_type: The target type to validate against
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
True if all items are compatible, False otherwise
|
|
157
|
+
"""
|
|
158
|
+
if inspect.isclass(target_type) and issubclass(target_type, pydantic.BaseModel):
|
|
159
|
+
for item in collection:
|
|
160
|
+
try:
|
|
161
|
+
# Try to validate the item against the target type
|
|
162
|
+
if isinstance(item, dict):
|
|
163
|
+
parse_obj_as(target_type, item)
|
|
164
|
+
else:
|
|
165
|
+
# If it's not a dict, it might already be the right type
|
|
166
|
+
if not isinstance(item, target_type):
|
|
167
|
+
return False
|
|
168
|
+
except Exception:
|
|
169
|
+
return False
|
|
170
|
+
return True
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _convert_undiscriminated_union_type(union_type: typing.Type[typing.Any], object_: typing.Any) -> typing.Any:
|
|
174
|
+
inner_types = get_args(union_type)
|
|
175
|
+
if typing.Any in inner_types:
|
|
176
|
+
return object_
|
|
177
|
+
|
|
178
|
+
for inner_type in inner_types:
|
|
179
|
+
# Handle lists of objects that need parsing
|
|
180
|
+
if get_origin(inner_type) is list and isinstance(object_, list):
|
|
181
|
+
list_inner_type = get_args(inner_type)[0]
|
|
182
|
+
try:
|
|
183
|
+
if inspect.isclass(list_inner_type) and issubclass(list_inner_type, pydantic.BaseModel):
|
|
184
|
+
# Validate that all items in the list are compatible with the target type
|
|
185
|
+
if _validate_collection_items_compatible(object_, list_inner_type):
|
|
186
|
+
parsed_list = [parse_obj_as(object_=item, type_=list_inner_type) for item in object_]
|
|
187
|
+
return parsed_list
|
|
188
|
+
except Exception:
|
|
189
|
+
pass
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
if inspect.isclass(inner_type) and issubclass(inner_type, pydantic.BaseModel):
|
|
193
|
+
# Attempt a validated parse until one works
|
|
194
|
+
return parse_obj_as(inner_type, object_)
|
|
195
|
+
except Exception:
|
|
196
|
+
continue
|
|
197
|
+
|
|
198
|
+
# If none of the types work, try matching literal fields first, then fall back
|
|
199
|
+
# First pass: try types where all literal fields match the object's values
|
|
200
|
+
for inner_type in inner_types:
|
|
201
|
+
if inspect.isclass(inner_type) and issubclass(inner_type, pydantic.BaseModel):
|
|
202
|
+
fields = _get_model_fields(inner_type)
|
|
203
|
+
literal_fields_match = True
|
|
204
|
+
|
|
205
|
+
for field_name, field in fields.items():
|
|
206
|
+
# Check if this field has a Literal type
|
|
207
|
+
if IS_PYDANTIC_V2:
|
|
208
|
+
field_type = field.annotation # type: ignore # Pydantic v2
|
|
209
|
+
else:
|
|
210
|
+
field_type = field.outer_type_ # type: ignore # Pydantic v1
|
|
211
|
+
|
|
212
|
+
if is_literal_type(field_type): # type: ignore[arg-type]
|
|
213
|
+
field_default = _get_field_default(field)
|
|
214
|
+
name_or_alias = get_field_to_alias_mapping(inner_type).get(field_name, field_name)
|
|
215
|
+
# Get the value from the object
|
|
216
|
+
if isinstance(object_, dict):
|
|
217
|
+
object_value = object_.get(name_or_alias)
|
|
218
|
+
else:
|
|
219
|
+
object_value = getattr(object_, name_or_alias, None)
|
|
220
|
+
|
|
221
|
+
# If the literal field value doesn't match, this type is not a match
|
|
222
|
+
if object_value is not None and field_default != object_value:
|
|
223
|
+
literal_fields_match = False
|
|
224
|
+
break
|
|
225
|
+
|
|
226
|
+
# If all literal fields match, try to construct this type
|
|
227
|
+
if literal_fields_match:
|
|
228
|
+
try:
|
|
229
|
+
return construct_type(object_=object_, type_=inner_type)
|
|
230
|
+
except Exception:
|
|
231
|
+
continue
|
|
232
|
+
|
|
233
|
+
# Second pass: if no literal matches, just return the first successful cast
|
|
234
|
+
for inner_type in inner_types:
|
|
235
|
+
try:
|
|
236
|
+
return construct_type(object_=object_, type_=inner_type)
|
|
237
|
+
except Exception:
|
|
238
|
+
continue
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _convert_union_type(type_: typing.Type[typing.Any], object_: typing.Any) -> typing.Any:
|
|
242
|
+
base_type = get_origin(type_) or type_
|
|
243
|
+
union_type = type_
|
|
244
|
+
if base_type == typing_extensions.Annotated: # type: ignore[comparison-overlap]
|
|
245
|
+
union_type = get_args(type_)[0]
|
|
246
|
+
annotated_metadata = get_args(type_)[1:]
|
|
247
|
+
for metadata in annotated_metadata:
|
|
248
|
+
if isinstance(metadata, UnionMetadata):
|
|
249
|
+
try:
|
|
250
|
+
# Cast to the correct type, based on the discriminant
|
|
251
|
+
for inner_type in get_args(union_type):
|
|
252
|
+
try:
|
|
253
|
+
objects_discriminant = getattr(object_, metadata.discriminant)
|
|
254
|
+
except:
|
|
255
|
+
objects_discriminant = object_[metadata.discriminant]
|
|
256
|
+
if inner_type.__fields__[metadata.discriminant].default == objects_discriminant:
|
|
257
|
+
return construct_type(object_=object_, type_=inner_type)
|
|
258
|
+
except Exception:
|
|
259
|
+
# Allow to fall through to our regular union handling
|
|
260
|
+
pass
|
|
261
|
+
return _convert_undiscriminated_union_type(union_type, object_)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def construct_type(*, type_: typing.Type[typing.Any], object_: typing.Any) -> typing.Any:
|
|
265
|
+
"""
|
|
266
|
+
Here we are essentially creating the same `construct` method in spirit as the above, but for all types, not just
|
|
267
|
+
Pydantic models.
|
|
268
|
+
The idea is to essentially attempt to coerce object_ to type_ (recursively)
|
|
269
|
+
"""
|
|
270
|
+
# Short circuit when dealing with optionals, don't try to coerces None to a type
|
|
271
|
+
if object_ is None:
|
|
272
|
+
return None
|
|
273
|
+
|
|
274
|
+
base_type = get_origin(type_) or type_
|
|
275
|
+
is_annotated = base_type == typing_extensions.Annotated # type: ignore[comparison-overlap]
|
|
276
|
+
maybe_annotation_members = get_args(type_)
|
|
277
|
+
is_annotated_union = is_annotated and is_union(get_origin(maybe_annotation_members[0]))
|
|
278
|
+
|
|
279
|
+
if base_type == typing.Any: # type: ignore[comparison-overlap]
|
|
280
|
+
return object_
|
|
281
|
+
|
|
282
|
+
if base_type == dict:
|
|
283
|
+
if not isinstance(object_, typing.Mapping):
|
|
284
|
+
return object_
|
|
285
|
+
|
|
286
|
+
key_type, items_type = get_args(type_)
|
|
287
|
+
d = {
|
|
288
|
+
construct_type(object_=key, type_=key_type): construct_type(object_=item, type_=items_type)
|
|
289
|
+
for key, item in object_.items()
|
|
290
|
+
}
|
|
291
|
+
return d
|
|
292
|
+
|
|
293
|
+
if base_type == list:
|
|
294
|
+
if not isinstance(object_, list):
|
|
295
|
+
return object_
|
|
296
|
+
|
|
297
|
+
inner_type = get_args(type_)[0]
|
|
298
|
+
return [construct_type(object_=entry, type_=inner_type) for entry in object_]
|
|
299
|
+
|
|
300
|
+
if base_type == set:
|
|
301
|
+
if not isinstance(object_, set) and not isinstance(object_, list):
|
|
302
|
+
return object_
|
|
303
|
+
|
|
304
|
+
inner_type = get_args(type_)[0]
|
|
305
|
+
return {construct_type(object_=entry, type_=inner_type) for entry in object_}
|
|
306
|
+
|
|
307
|
+
if is_union(base_type) or is_annotated_union:
|
|
308
|
+
return _convert_union_type(type_, object_)
|
|
309
|
+
|
|
310
|
+
# Cannot do an `issubclass` with a literal type, let's also just confirm we have a class before this call
|
|
311
|
+
if (
|
|
312
|
+
object_ is not None
|
|
313
|
+
and not is_literal_type(type_)
|
|
314
|
+
and (
|
|
315
|
+
(inspect.isclass(base_type) and issubclass(base_type, pydantic.BaseModel))
|
|
316
|
+
or (
|
|
317
|
+
is_annotated
|
|
318
|
+
and inspect.isclass(maybe_annotation_members[0])
|
|
319
|
+
and issubclass(maybe_annotation_members[0], pydantic.BaseModel)
|
|
320
|
+
)
|
|
321
|
+
)
|
|
322
|
+
):
|
|
323
|
+
if IS_PYDANTIC_V2:
|
|
324
|
+
return type_.model_construct(**object_)
|
|
325
|
+
else:
|
|
326
|
+
return type_.construct(**object_)
|
|
327
|
+
|
|
328
|
+
if base_type == dt.datetime:
|
|
329
|
+
try:
|
|
330
|
+
return parse_datetime(object_)
|
|
331
|
+
except Exception:
|
|
332
|
+
return object_
|
|
333
|
+
|
|
334
|
+
if base_type == dt.date:
|
|
335
|
+
try:
|
|
336
|
+
return parse_date(object_)
|
|
337
|
+
except Exception:
|
|
338
|
+
return object_
|
|
339
|
+
|
|
340
|
+
if base_type == uuid.UUID:
|
|
341
|
+
try:
|
|
342
|
+
return uuid.UUID(object_)
|
|
343
|
+
except Exception:
|
|
344
|
+
return object_
|
|
345
|
+
|
|
346
|
+
if base_type == int:
|
|
347
|
+
try:
|
|
348
|
+
return int(object_)
|
|
349
|
+
except Exception:
|
|
350
|
+
return object_
|
|
351
|
+
|
|
352
|
+
if base_type == bool:
|
|
353
|
+
try:
|
|
354
|
+
if isinstance(object_, str):
|
|
355
|
+
stringified_object = object_.lower()
|
|
356
|
+
return stringified_object == "true" or stringified_object == "1"
|
|
357
|
+
|
|
358
|
+
return bool(object_)
|
|
359
|
+
except Exception:
|
|
360
|
+
return object_
|
|
361
|
+
|
|
362
|
+
return object_
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _get_is_populate_by_name(model: typing.Type["Model"]) -> bool:
|
|
366
|
+
if IS_PYDANTIC_V2:
|
|
367
|
+
return model.model_config.get("populate_by_name", False) # type: ignore # Pydantic v2
|
|
368
|
+
return model.__config__.allow_population_by_field_name # type: ignore # Pydantic v1
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
PydanticField = typing.Union[ModelField, pydantic.fields.FieldInfo]
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
# Pydantic V1 swapped the typing of __fields__'s values from ModelField to FieldInfo
|
|
375
|
+
# And so we try to handle both V1 cases, as well as V2 (FieldInfo from model.model_fields)
|
|
376
|
+
def _get_model_fields(
|
|
377
|
+
model: typing.Type["Model"],
|
|
378
|
+
) -> typing.Mapping[str, PydanticField]:
|
|
379
|
+
if IS_PYDANTIC_V2:
|
|
380
|
+
return model.model_fields # type: ignore # Pydantic v2
|
|
381
|
+
else:
|
|
382
|
+
return model.__fields__ # type: ignore # Pydantic v1
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _get_field_default(field: PydanticField) -> typing.Any:
|
|
386
|
+
try:
|
|
387
|
+
value = field.get_default() # type: ignore # Pydantic < v1.10.15
|
|
388
|
+
except:
|
|
389
|
+
value = field.default
|
|
390
|
+
if IS_PYDANTIC_V2:
|
|
391
|
+
from pydantic_core import PydanticUndefined
|
|
392
|
+
|
|
393
|
+
if value == PydanticUndefined:
|
|
394
|
+
return None
|
|
395
|
+
return value
|
|
396
|
+
return value
|
pulse/environment.py
ADDED
pulse/errors/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BadRequestError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Any, headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=400, headers=headers, body=body)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ForbiddenError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Any, headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=403, headers=headers, body=body)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class InternalServerError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Any, headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=500, headers=headers, body=body)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class NotFoundError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Any, headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=404, headers=headers, body=body)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TooManyRequestsError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Any, headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=429, headers=headers, body=body)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.api_error import ApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class UnauthorizedError(ApiError):
|
|
9
|
+
def __init__(self, body: typing.Any, headers: typing.Optional[typing.Dict[str, str]] = None):
|
|
10
|
+
super().__init__(status_code=401, headers=headers, body=body)
|
pulse/jobs/__init__.py
ADDED
pulse/jobs/client.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
6
|
+
from ..core.request_options import RequestOptions
|
|
7
|
+
from ..types.job_cancellation_response import JobCancellationResponse
|
|
8
|
+
from ..types.job_status_response import JobStatusResponse
|
|
9
|
+
from .raw_client import AsyncRawJobsClient, RawJobsClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class JobsClient:
|
|
13
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
14
|
+
self._raw_client = RawJobsClient(client_wrapper=client_wrapper)
|
|
15
|
+
|
|
16
|
+
@property
|
|
17
|
+
def with_raw_response(self) -> RawJobsClient:
|
|
18
|
+
"""
|
|
19
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
RawJobsClient
|
|
24
|
+
"""
|
|
25
|
+
return self._raw_client
|
|
26
|
+
|
|
27
|
+
def get_job(self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> JobStatusResponse:
|
|
28
|
+
"""
|
|
29
|
+
Check the status and retrieve results of an asynchronous job
|
|
30
|
+
(e.g., submitted via `/extract_async`).
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
job_id : str
|
|
35
|
+
Identifier returned from an async job submission (e.g., `/extract_async`).
|
|
36
|
+
|
|
37
|
+
request_options : typing.Optional[RequestOptions]
|
|
38
|
+
Request-specific configuration.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
JobStatusResponse
|
|
43
|
+
Current job status payload
|
|
44
|
+
|
|
45
|
+
Examples
|
|
46
|
+
--------
|
|
47
|
+
from pulse import Pulse
|
|
48
|
+
|
|
49
|
+
client = Pulse(
|
|
50
|
+
api_key="YOUR_API_KEY",
|
|
51
|
+
)
|
|
52
|
+
client.jobs.get_job(
|
|
53
|
+
job_id="jobId",
|
|
54
|
+
)
|
|
55
|
+
"""
|
|
56
|
+
_response = self._raw_client.get_job(job_id, request_options=request_options)
|
|
57
|
+
return _response.data
|
|
58
|
+
|
|
59
|
+
def cancel_job(
|
|
60
|
+
self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
61
|
+
) -> JobCancellationResponse:
|
|
62
|
+
"""
|
|
63
|
+
Attempts to cancel an asynchronous job that is currently pending
|
|
64
|
+
or processing. Jobs that have already completed will remain unchanged.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
job_id : str
|
|
69
|
+
Identifier returned from an async job submission (e.g., `/extract_async`).
|
|
70
|
+
|
|
71
|
+
request_options : typing.Optional[RequestOptions]
|
|
72
|
+
Request-specific configuration.
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
JobCancellationResponse
|
|
77
|
+
Job cancellation accepted
|
|
78
|
+
|
|
79
|
+
Examples
|
|
80
|
+
--------
|
|
81
|
+
from pulse import Pulse
|
|
82
|
+
|
|
83
|
+
client = Pulse(
|
|
84
|
+
api_key="YOUR_API_KEY",
|
|
85
|
+
)
|
|
86
|
+
client.jobs.cancel_job(
|
|
87
|
+
job_id="jobId",
|
|
88
|
+
)
|
|
89
|
+
"""
|
|
90
|
+
_response = self._raw_client.cancel_job(job_id, request_options=request_options)
|
|
91
|
+
return _response.data
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class AsyncJobsClient:
|
|
95
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
96
|
+
self._raw_client = AsyncRawJobsClient(client_wrapper=client_wrapper)
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def with_raw_response(self) -> AsyncRawJobsClient:
|
|
100
|
+
"""
|
|
101
|
+
Retrieves a raw implementation of this client that returns raw responses.
|
|
102
|
+
|
|
103
|
+
Returns
|
|
104
|
+
-------
|
|
105
|
+
AsyncRawJobsClient
|
|
106
|
+
"""
|
|
107
|
+
return self._raw_client
|
|
108
|
+
|
|
109
|
+
async def get_job(
|
|
110
|
+
self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
111
|
+
) -> JobStatusResponse:
|
|
112
|
+
"""
|
|
113
|
+
Check the status and retrieve results of an asynchronous job
|
|
114
|
+
(e.g., submitted via `/extract_async`).
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
job_id : str
|
|
119
|
+
Identifier returned from an async job submission (e.g., `/extract_async`).
|
|
120
|
+
|
|
121
|
+
request_options : typing.Optional[RequestOptions]
|
|
122
|
+
Request-specific configuration.
|
|
123
|
+
|
|
124
|
+
Returns
|
|
125
|
+
-------
|
|
126
|
+
JobStatusResponse
|
|
127
|
+
Current job status payload
|
|
128
|
+
|
|
129
|
+
Examples
|
|
130
|
+
--------
|
|
131
|
+
import asyncio
|
|
132
|
+
|
|
133
|
+
from pulse import AsyncPulse
|
|
134
|
+
|
|
135
|
+
client = AsyncPulse(
|
|
136
|
+
api_key="YOUR_API_KEY",
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
async def main() -> None:
|
|
141
|
+
await client.jobs.get_job(
|
|
142
|
+
job_id="jobId",
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
asyncio.run(main())
|
|
147
|
+
"""
|
|
148
|
+
_response = await self._raw_client.get_job(job_id, request_options=request_options)
|
|
149
|
+
return _response.data
|
|
150
|
+
|
|
151
|
+
async def cancel_job(
|
|
152
|
+
self, job_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
153
|
+
) -> JobCancellationResponse:
|
|
154
|
+
"""
|
|
155
|
+
Attempts to cancel an asynchronous job that is currently pending
|
|
156
|
+
or processing. Jobs that have already completed will remain unchanged.
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
job_id : str
|
|
161
|
+
Identifier returned from an async job submission (e.g., `/extract_async`).
|
|
162
|
+
|
|
163
|
+
request_options : typing.Optional[RequestOptions]
|
|
164
|
+
Request-specific configuration.
|
|
165
|
+
|
|
166
|
+
Returns
|
|
167
|
+
-------
|
|
168
|
+
JobCancellationResponse
|
|
169
|
+
Job cancellation accepted
|
|
170
|
+
|
|
171
|
+
Examples
|
|
172
|
+
--------
|
|
173
|
+
import asyncio
|
|
174
|
+
|
|
175
|
+
from pulse import AsyncPulse
|
|
176
|
+
|
|
177
|
+
client = AsyncPulse(
|
|
178
|
+
api_key="YOUR_API_KEY",
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
async def main() -> None:
|
|
183
|
+
await client.jobs.cancel_job(
|
|
184
|
+
job_id="jobId",
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
asyncio.run(main())
|
|
189
|
+
"""
|
|
190
|
+
_response = await self._raw_client.cancel_job(job_id, request_options=request_options)
|
|
191
|
+
return _response.data
|