scrapely-client-python 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.
Potentially problematic release.
This version of scrapely-client-python might be problematic. Click here for more details.
- scrapely_client/__init__.py +30 -0
- scrapely_client/_charging.py +186 -0
- scrapely_client/_client_registry.py +136 -0
- scrapely_client/_consts.py +96 -0
- scrapely_client/_docs.py +37 -0
- scrapely_client/_literals.py +539 -0
- scrapely_client/_logging.py +180 -0
- scrapely_client/_models.py +4172 -0
- scrapely_client/_pagination.py +220 -0
- scrapely_client/_resource_clients/__init__.py +84 -0
- scrapely_client/_resource_clients/_resource_client.py +567 -0
- scrapely_client/_resource_clients/actor.py +1042 -0
- scrapely_client/_resource_clients/actor_collection.py +377 -0
- scrapely_client/_resource_clients/actor_env_var.py +154 -0
- scrapely_client/_resource_clients/actor_env_var_collection.py +165 -0
- scrapely_client/_resource_clients/actor_version.py +254 -0
- scrapely_client/_resource_clients/actor_version_collection.py +232 -0
- scrapely_client/_resource_clients/build.py +244 -0
- scrapely_client/_resource_clients/build_collection.py +164 -0
- scrapely_client/_resource_clients/dataset.py +1151 -0
- scrapely_client/_resource_clients/dataset_collection.py +244 -0
- scrapely_client/_resource_clients/key_value_store.py +906 -0
- scrapely_client/_resource_clients/key_value_store_collection.py +243 -0
- scrapely_client/_resource_clients/log.py +225 -0
- scrapely_client/_resource_clients/request_queue.py +1167 -0
- scrapely_client/_resource_clients/request_queue_collection.py +240 -0
- scrapely_client/_resource_clients/run.py +875 -0
- scrapely_client/_resource_clients/run_collection.py +226 -0
- scrapely_client/_resource_clients/schedule.py +243 -0
- scrapely_client/_resource_clients/schedule_collection.py +260 -0
- scrapely_client/_resource_clients/store_collection.py +242 -0
- scrapely_client/_resource_clients/task.py +793 -0
- scrapely_client/_resource_clients/task_collection.py +322 -0
- scrapely_client/_resource_clients/user.py +262 -0
- scrapely_client/_resource_clients/webhook.py +292 -0
- scrapely_client/_resource_clients/webhook_collection.py +281 -0
- scrapely_client/_resource_clients/webhook_dispatch.py +84 -0
- scrapely_client/_resource_clients/webhook_dispatch_collection.py +158 -0
- scrapely_client/_scrapely_client.py +837 -0
- scrapely_client/_statistics.py +29 -0
- scrapely_client/_status_message_watcher.py +197 -0
- scrapely_client/_streamed_log.py +250 -0
- scrapely_client/_typeddicts.py +408 -0
- scrapely_client/_utils/__init__.py +0 -0
- scrapely_client/_utils/crypto.py +87 -0
- scrapely_client/_utils/encoding.py +133 -0
- scrapely_client/_utils/errors.py +33 -0
- scrapely_client/_utils/http.py +137 -0
- scrapely_client/_utils/time.py +32 -0
- scrapely_client/_utils/try_import.py +61 -0
- scrapely_client/errors.py +190 -0
- scrapely_client/http_clients/__init__.py +10 -0
- scrapely_client/http_clients/_base.py +430 -0
- scrapely_client/http_clients/_impit.py +598 -0
- scrapely_client/http_compressors/__init__.py +18 -0
- scrapely_client/http_compressors/_base.py +25 -0
- scrapely_client/http_compressors/_brotli.py +38 -0
- scrapely_client/http_compressors/_gzip.py +38 -0
- scrapely_client/http_compressors/_resolve.py +38 -0
- scrapely_client/py.typed +0 -0
- scrapely_client/types.py +52 -0
- scrapely_client_python-1.0.0.dist-info/METADATA +244 -0
- scrapely_client_python-1.0.0.dist-info/RECORD +65 -0
- scrapely_client_python-1.0.0.dist-info/WHEEL +4 -0
- scrapely_client_python-1.0.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Literal
|
|
4
|
+
|
|
5
|
+
from scrapely_client._docs import docs_group
|
|
6
|
+
from scrapely_client._models import (
|
|
7
|
+
Actor,
|
|
8
|
+
ActorResponse,
|
|
9
|
+
ActorStandby,
|
|
10
|
+
CreateActorRequest,
|
|
11
|
+
DefaultRunOptions,
|
|
12
|
+
ExampleRunInput,
|
|
13
|
+
ListOfActors,
|
|
14
|
+
ListOfActorsResponse,
|
|
15
|
+
)
|
|
16
|
+
from scrapely_client._pagination import get_items_iterator, get_items_iterator_async
|
|
17
|
+
from scrapely_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
|
|
18
|
+
from scrapely_client._utils.time import to_seconds
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from collections.abc import AsyncIterator, Iterator
|
|
22
|
+
from datetime import timedelta
|
|
23
|
+
|
|
24
|
+
from scrapely_client._models import ActorShort
|
|
25
|
+
from scrapely_client.types import Timeout
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@docs_group('Resource clients')
|
|
29
|
+
class ActorCollectionClient(ResourceClient):
|
|
30
|
+
"""Sub-client for the Actor collection.
|
|
31
|
+
|
|
32
|
+
Provides methods to manage the Actor collection, e.g. list or create Actors. Obtain an instance via an appropriate
|
|
33
|
+
method on the `ApifyClient` class.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
*,
|
|
39
|
+
resource_path: str = 'actors',
|
|
40
|
+
**kwargs: Any,
|
|
41
|
+
) -> None:
|
|
42
|
+
super().__init__(
|
|
43
|
+
resource_path=resource_path,
|
|
44
|
+
**kwargs,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def list(
|
|
48
|
+
self,
|
|
49
|
+
*,
|
|
50
|
+
my: bool | None = None,
|
|
51
|
+
limit: int | None = None,
|
|
52
|
+
offset: int | None = None,
|
|
53
|
+
desc: bool | None = None,
|
|
54
|
+
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
|
|
55
|
+
timeout: Timeout = 'medium',
|
|
56
|
+
) -> ListOfActors:
|
|
57
|
+
"""List the Actors the user has created or used.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
my: If True, will return only Actors which the user has created themselves.
|
|
62
|
+
limit: How many Actors to list.
|
|
63
|
+
offset: What Actor to include as first when retrieving the list.
|
|
64
|
+
desc: Whether to sort the Actors in descending order based on their creation date.
|
|
65
|
+
sort_by: Field to sort the results by.
|
|
66
|
+
timeout: Timeout for the API HTTP request.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
The list of available Actors matching the specified filters.
|
|
70
|
+
"""
|
|
71
|
+
result = self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=sort_by)
|
|
72
|
+
return ListOfActorsResponse.model_validate(result).data
|
|
73
|
+
|
|
74
|
+
def iterate(
|
|
75
|
+
self,
|
|
76
|
+
*,
|
|
77
|
+
my: bool | None = None,
|
|
78
|
+
limit: int | None = None,
|
|
79
|
+
offset: int | None = None,
|
|
80
|
+
desc: bool | None = None,
|
|
81
|
+
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
|
|
82
|
+
timeout: Timeout = 'medium',
|
|
83
|
+
) -> Iterator[ActorShort]:
|
|
84
|
+
"""Iterate over the Actors the user has created or used.
|
|
85
|
+
|
|
86
|
+
Simple `list` does only one API call, possibly not listing all items matching the criteria. This method
|
|
87
|
+
returns an iterator that is capable of making multiple API calls to retrieve all items matching the criteria.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
my: If True, will return only Actors which the user has created themselves.
|
|
92
|
+
limit: How many Actors to list.
|
|
93
|
+
offset: What Actor to include as first when retrieving the list.
|
|
94
|
+
desc: Whether to sort the Actors in descending order based on their creation date.
|
|
95
|
+
sort_by: Field to sort the results by.
|
|
96
|
+
timeout: Timeout for the API HTTP request.
|
|
97
|
+
|
|
98
|
+
Yields:
|
|
99
|
+
The Actors available to the user matching the specified filters.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def _callback(*, limit: int | None = None, offset: int | None = None) -> ListOfActors:
|
|
103
|
+
return self.list(my=my, limit=limit, offset=offset, desc=desc, sort_by=sort_by, timeout=timeout)
|
|
104
|
+
|
|
105
|
+
return get_items_iterator(_callback, limit=limit, offset=offset)
|
|
106
|
+
|
|
107
|
+
def create(
|
|
108
|
+
self,
|
|
109
|
+
*,
|
|
110
|
+
name: str,
|
|
111
|
+
title: str | None = None,
|
|
112
|
+
description: str | None = None,
|
|
113
|
+
seo_title: str | None = None,
|
|
114
|
+
seo_description: str | None = None,
|
|
115
|
+
versions: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form]
|
|
116
|
+
restart_on_error: bool | None = None,
|
|
117
|
+
is_public: bool | None = None,
|
|
118
|
+
is_deprecated: bool | None = None,
|
|
119
|
+
categories: list[str] | None = None, # ty: ignore[invalid-type-form]
|
|
120
|
+
default_run_build: str | None = None,
|
|
121
|
+
default_run_max_items: int | None = None,
|
|
122
|
+
default_run_memory_mbytes: int | None = None,
|
|
123
|
+
default_run_timeout: timedelta | None = None,
|
|
124
|
+
example_run_input_body: Any = None,
|
|
125
|
+
example_run_input_content_type: str | None = None,
|
|
126
|
+
actor_standby_is_enabled: bool | None = None,
|
|
127
|
+
actor_standby_desired_requests_per_actor_run: int | None = None,
|
|
128
|
+
actor_standby_max_requests_per_actor_run: int | None = None,
|
|
129
|
+
actor_standby_idle_timeout: timedelta | None = None,
|
|
130
|
+
actor_standby_build: str | None = None,
|
|
131
|
+
actor_standby_memory_mbytes: int | None = None,
|
|
132
|
+
timeout: Timeout = 'medium',
|
|
133
|
+
) -> Actor:
|
|
134
|
+
"""Create a new Actor.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
name: The name of the Actor.
|
|
139
|
+
title: The title of the Actor (human-readable).
|
|
140
|
+
description: The description for the Actor.
|
|
141
|
+
seo_title: The title of the Actor optimized for search engines.
|
|
142
|
+
seo_description: The description of the Actor optimized for search engines.
|
|
143
|
+
versions: The list of Actor versions.
|
|
144
|
+
restart_on_error: If true, the Actor run process will be restarted whenever it exits with
|
|
145
|
+
a non-zero status code.
|
|
146
|
+
is_public: Whether the Actor is public.
|
|
147
|
+
is_deprecated: Whether the Actor is deprecated.
|
|
148
|
+
categories: The categories to which the Actor belongs to.
|
|
149
|
+
default_run_build: Tag or number of the build that you want to run by default.
|
|
150
|
+
default_run_max_items: Default limit of the number of results that will be returned by runs
|
|
151
|
+
of this Actor, if the Actor is charged per result.
|
|
152
|
+
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
|
|
153
|
+
default_run_timeout: Default timeout for the runs of this Actor.
|
|
154
|
+
example_run_input_body: Input to be prefilled as default input to new users of this Actor.
|
|
155
|
+
example_run_input_content_type: The content type of the example run input.
|
|
156
|
+
actor_standby_is_enabled: Whether the Actor Standby is enabled.
|
|
157
|
+
actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for
|
|
158
|
+
a single Actor Standby run.
|
|
159
|
+
actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for
|
|
160
|
+
a single Actor Standby run.
|
|
161
|
+
actor_standby_idle_timeout: If the Actor run does not receive any requests for this time,
|
|
162
|
+
it will be shut down.
|
|
163
|
+
actor_standby_build: The build tag or number to run when the Actor is in Standby mode.
|
|
164
|
+
actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode.
|
|
165
|
+
timeout: Timeout for the API HTTP request.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
The created Actor.
|
|
169
|
+
"""
|
|
170
|
+
actor_fields = CreateActorRequest(
|
|
171
|
+
name=name,
|
|
172
|
+
title=title,
|
|
173
|
+
description=description,
|
|
174
|
+
seo_title=seo_title,
|
|
175
|
+
seo_description=seo_description,
|
|
176
|
+
versions=versions,
|
|
177
|
+
is_public=is_public,
|
|
178
|
+
is_deprecated=is_deprecated,
|
|
179
|
+
categories=categories,
|
|
180
|
+
default_run_options=DefaultRunOptions(
|
|
181
|
+
build=default_run_build,
|
|
182
|
+
max_items=default_run_max_items,
|
|
183
|
+
memory_mbytes=default_run_memory_mbytes,
|
|
184
|
+
timeout_secs=to_seconds(default_run_timeout, as_int=True),
|
|
185
|
+
restart_on_error=restart_on_error,
|
|
186
|
+
),
|
|
187
|
+
actor_standby=ActorStandby(
|
|
188
|
+
is_enabled=actor_standby_is_enabled,
|
|
189
|
+
desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run,
|
|
190
|
+
max_requests_per_actor_run=actor_standby_max_requests_per_actor_run,
|
|
191
|
+
idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True),
|
|
192
|
+
build=actor_standby_build,
|
|
193
|
+
memory_mbytes=actor_standby_memory_mbytes,
|
|
194
|
+
),
|
|
195
|
+
example_run_input=ExampleRunInput(
|
|
196
|
+
body=example_run_input_body,
|
|
197
|
+
content_type=example_run_input_content_type,
|
|
198
|
+
),
|
|
199
|
+
)
|
|
200
|
+
result = self._create(timeout=timeout, **actor_fields.model_dump(by_alias=True, exclude_none=True))
|
|
201
|
+
return ActorResponse.model_validate(result).data
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@docs_group('Resource clients')
|
|
205
|
+
class ActorCollectionClientAsync(ResourceClientAsync):
|
|
206
|
+
"""Sub-client for the Actor collection.
|
|
207
|
+
|
|
208
|
+
Provides methods to manage the Actor collection, e.g. list or create Actors. Obtain an instance via an appropriate
|
|
209
|
+
method on the `ApifyClientAsync` class.
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
def __init__(
|
|
213
|
+
self,
|
|
214
|
+
*,
|
|
215
|
+
resource_path: str = 'actors',
|
|
216
|
+
**kwargs: Any,
|
|
217
|
+
) -> None:
|
|
218
|
+
super().__init__(
|
|
219
|
+
resource_path=resource_path,
|
|
220
|
+
**kwargs,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
async def list(
|
|
224
|
+
self,
|
|
225
|
+
*,
|
|
226
|
+
my: bool | None = None,
|
|
227
|
+
limit: int | None = None,
|
|
228
|
+
offset: int | None = None,
|
|
229
|
+
desc: bool | None = None,
|
|
230
|
+
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
|
|
231
|
+
timeout: Timeout = 'medium',
|
|
232
|
+
) -> ListOfActors:
|
|
233
|
+
"""List the Actors the user has created or used.
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
Args:
|
|
237
|
+
my: If True, will return only Actors which the user has created themselves.
|
|
238
|
+
limit: How many Actors to list.
|
|
239
|
+
offset: What Actor to include as first when retrieving the list.
|
|
240
|
+
desc: Whether to sort the Actors in descending order based on their creation date.
|
|
241
|
+
sort_by: Field to sort the results by.
|
|
242
|
+
timeout: Timeout for the API HTTP request.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
The list of available Actors matching the specified filters.
|
|
246
|
+
"""
|
|
247
|
+
result = await self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=sort_by)
|
|
248
|
+
return ListOfActorsResponse.model_validate(result).data
|
|
249
|
+
|
|
250
|
+
def iterate(
|
|
251
|
+
self,
|
|
252
|
+
*,
|
|
253
|
+
my: bool | None = None,
|
|
254
|
+
limit: int | None = None,
|
|
255
|
+
offset: int | None = None,
|
|
256
|
+
desc: bool | None = None,
|
|
257
|
+
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
|
|
258
|
+
timeout: Timeout = 'medium',
|
|
259
|
+
) -> AsyncIterator[ActorShort]:
|
|
260
|
+
"""Iterate over the Actors the user has created or used.
|
|
261
|
+
|
|
262
|
+
Simple `list` does only one API call, possibly not listing all items matching the criteria. This method
|
|
263
|
+
returns an iterator that is capable of making multiple API calls to retrieve all items matching the criteria.
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
Args:
|
|
267
|
+
my: If True, will return only Actors which the user has created themselves.
|
|
268
|
+
limit: How many Actors to list.
|
|
269
|
+
offset: What Actor to include as first when retrieving the list.
|
|
270
|
+
desc: Whether to sort the Actors in descending order based on their creation date.
|
|
271
|
+
sort_by: Field to sort the results by.
|
|
272
|
+
timeout: Timeout for the API HTTP request.
|
|
273
|
+
|
|
274
|
+
Yields:
|
|
275
|
+
The Actors available to the user matching the specified filters.
|
|
276
|
+
"""
|
|
277
|
+
|
|
278
|
+
async def _callback(*, limit: int | None = None, offset: int | None = None) -> ListOfActors:
|
|
279
|
+
return await self.list(my=my, limit=limit, offset=offset, desc=desc, sort_by=sort_by, timeout=timeout)
|
|
280
|
+
|
|
281
|
+
return get_items_iterator_async(_callback, limit=limit, offset=offset)
|
|
282
|
+
|
|
283
|
+
async def create(
|
|
284
|
+
self,
|
|
285
|
+
*,
|
|
286
|
+
name: str,
|
|
287
|
+
title: str | None = None,
|
|
288
|
+
description: str | None = None,
|
|
289
|
+
seo_title: str | None = None,
|
|
290
|
+
seo_description: str | None = None,
|
|
291
|
+
versions: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form]
|
|
292
|
+
restart_on_error: bool | None = None,
|
|
293
|
+
is_public: bool | None = None,
|
|
294
|
+
is_deprecated: bool | None = None,
|
|
295
|
+
categories: list[str] | None = None, # ty: ignore[invalid-type-form]
|
|
296
|
+
default_run_build: str | None = None,
|
|
297
|
+
default_run_max_items: int | None = None,
|
|
298
|
+
default_run_memory_mbytes: int | None = None,
|
|
299
|
+
default_run_timeout: timedelta | None = None,
|
|
300
|
+
example_run_input_body: Any = None,
|
|
301
|
+
example_run_input_content_type: str | None = None,
|
|
302
|
+
actor_standby_is_enabled: bool | None = None,
|
|
303
|
+
actor_standby_desired_requests_per_actor_run: int | None = None,
|
|
304
|
+
actor_standby_max_requests_per_actor_run: int | None = None,
|
|
305
|
+
actor_standby_idle_timeout: timedelta | None = None,
|
|
306
|
+
actor_standby_build: str | None = None,
|
|
307
|
+
actor_standby_memory_mbytes: int | None = None,
|
|
308
|
+
timeout: Timeout = 'medium',
|
|
309
|
+
) -> Actor:
|
|
310
|
+
"""Create a new Actor.
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
Args:
|
|
314
|
+
name: The name of the Actor.
|
|
315
|
+
title: The title of the Actor (human-readable).
|
|
316
|
+
description: The description for the Actor.
|
|
317
|
+
seo_title: The title of the Actor optimized for search engines.
|
|
318
|
+
seo_description: The description of the Actor optimized for search engines.
|
|
319
|
+
versions: The list of Actor versions.
|
|
320
|
+
restart_on_error: If true, the Actor run process will be restarted whenever it exits with
|
|
321
|
+
a non-zero status code.
|
|
322
|
+
is_public: Whether the Actor is public.
|
|
323
|
+
is_deprecated: Whether the Actor is deprecated.
|
|
324
|
+
categories: The categories to which the Actor belongs to.
|
|
325
|
+
default_run_build: Tag or number of the build that you want to run by default.
|
|
326
|
+
default_run_max_items: Default limit of the number of results that will be returned by runs
|
|
327
|
+
of this Actor, if the Actor is charged per result.
|
|
328
|
+
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
|
|
329
|
+
default_run_timeout: Default timeout for the runs of this Actor.
|
|
330
|
+
example_run_input_body: Input to be prefilled as default input to new users of this Actor.
|
|
331
|
+
example_run_input_content_type: The content type of the example run input.
|
|
332
|
+
actor_standby_is_enabled: Whether the Actor Standby is enabled.
|
|
333
|
+
actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for
|
|
334
|
+
a single Actor Standby run.
|
|
335
|
+
actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for
|
|
336
|
+
a single Actor Standby run.
|
|
337
|
+
actor_standby_idle_timeout: If the Actor run does not receive any requests for this time,
|
|
338
|
+
it will be shut down.
|
|
339
|
+
actor_standby_build: The build tag or number to run when the Actor is in Standby mode.
|
|
340
|
+
actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode.
|
|
341
|
+
timeout: Timeout for the API HTTP request.
|
|
342
|
+
|
|
343
|
+
Returns:
|
|
344
|
+
The created Actor.
|
|
345
|
+
"""
|
|
346
|
+
actor_fields = CreateActorRequest(
|
|
347
|
+
name=name,
|
|
348
|
+
title=title,
|
|
349
|
+
description=description,
|
|
350
|
+
seo_title=seo_title,
|
|
351
|
+
seo_description=seo_description,
|
|
352
|
+
versions=versions,
|
|
353
|
+
is_public=is_public,
|
|
354
|
+
is_deprecated=is_deprecated,
|
|
355
|
+
categories=categories,
|
|
356
|
+
default_run_options=DefaultRunOptions(
|
|
357
|
+
build=default_run_build,
|
|
358
|
+
max_items=default_run_max_items,
|
|
359
|
+
memory_mbytes=default_run_memory_mbytes,
|
|
360
|
+
timeout_secs=to_seconds(default_run_timeout, as_int=True),
|
|
361
|
+
restart_on_error=restart_on_error,
|
|
362
|
+
),
|
|
363
|
+
actor_standby=ActorStandby(
|
|
364
|
+
is_enabled=actor_standby_is_enabled,
|
|
365
|
+
desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run,
|
|
366
|
+
max_requests_per_actor_run=actor_standby_max_requests_per_actor_run,
|
|
367
|
+
idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True),
|
|
368
|
+
build=actor_standby_build,
|
|
369
|
+
memory_mbytes=actor_standby_memory_mbytes,
|
|
370
|
+
),
|
|
371
|
+
example_run_input=ExampleRunInput(
|
|
372
|
+
body=example_run_input_body,
|
|
373
|
+
content_type=example_run_input_content_type,
|
|
374
|
+
),
|
|
375
|
+
)
|
|
376
|
+
result = await self._create(timeout=timeout, **actor_fields.model_dump(by_alias=True, exclude_none=True))
|
|
377
|
+
return ActorResponse.model_validate(result).data
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
|
|
5
|
+
from scrapely_client._docs import docs_group
|
|
6
|
+
from scrapely_client._models import EnvVar, EnvVarResponse
|
|
7
|
+
from scrapely_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from scrapely_client.types import Timeout
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@docs_group('Resource clients')
|
|
14
|
+
class ActorEnvVarClient(ResourceClient):
|
|
15
|
+
"""Sub-client for managing a specific Actor environment variable.
|
|
16
|
+
|
|
17
|
+
Provides methods to manage a specific Actor environment variable, e.g. get, update, or delete it. Obtain an instance
|
|
18
|
+
via an appropriate method on the `ActorVersionClient` class.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
*,
|
|
24
|
+
resource_id: str,
|
|
25
|
+
resource_path: str = 'env-vars',
|
|
26
|
+
**kwargs: Any,
|
|
27
|
+
) -> None:
|
|
28
|
+
super().__init__(
|
|
29
|
+
resource_id=resource_id,
|
|
30
|
+
resource_path=resource_path,
|
|
31
|
+
**kwargs,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def get(self, *, timeout: Timeout = 'short') -> EnvVar | None:
|
|
35
|
+
"""Return information about the Actor environment variable.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
timeout: Timeout for the API HTTP request.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
The retrieved Actor environment variable data.
|
|
43
|
+
"""
|
|
44
|
+
result = self._get(timeout=timeout)
|
|
45
|
+
if result is None:
|
|
46
|
+
return None
|
|
47
|
+
return EnvVarResponse.model_validate(result).data
|
|
48
|
+
|
|
49
|
+
def update(
|
|
50
|
+
self,
|
|
51
|
+
*,
|
|
52
|
+
is_secret: bool | None = None,
|
|
53
|
+
name: str,
|
|
54
|
+
value: str,
|
|
55
|
+
timeout: Timeout = 'short',
|
|
56
|
+
) -> EnvVar:
|
|
57
|
+
"""Update the Actor environment variable with specified fields.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
is_secret: Whether the environment variable is secret or not.
|
|
62
|
+
name: The name of the environment variable.
|
|
63
|
+
value: The value of the environment variable.
|
|
64
|
+
timeout: Timeout for the API HTTP request.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
The updated Actor environment variable.
|
|
68
|
+
"""
|
|
69
|
+
result = self._update(
|
|
70
|
+
timeout=timeout,
|
|
71
|
+
**EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True),
|
|
72
|
+
)
|
|
73
|
+
return EnvVarResponse.model_validate(result).data
|
|
74
|
+
|
|
75
|
+
def delete(self, *, timeout: Timeout = 'short') -> None:
|
|
76
|
+
"""Delete the Actor environment variable.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
timeout: Timeout for the API HTTP request.
|
|
81
|
+
"""
|
|
82
|
+
self._delete(timeout=timeout)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@docs_group('Resource clients')
|
|
86
|
+
class ActorEnvVarClientAsync(ResourceClientAsync):
|
|
87
|
+
"""Sub-client for managing a specific Actor environment variable.
|
|
88
|
+
|
|
89
|
+
Provides methods to manage a specific Actor environment variable, e.g. get, update, or delete it. Obtain an instance
|
|
90
|
+
via an appropriate method on the `ActorVersionClientAsync` class.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
def __init__(
|
|
94
|
+
self,
|
|
95
|
+
*,
|
|
96
|
+
resource_id: str,
|
|
97
|
+
resource_path: str = 'env-vars',
|
|
98
|
+
**kwargs: Any,
|
|
99
|
+
) -> None:
|
|
100
|
+
super().__init__(
|
|
101
|
+
resource_id=resource_id,
|
|
102
|
+
resource_path=resource_path,
|
|
103
|
+
**kwargs,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
async def get(self, *, timeout: Timeout = 'short') -> EnvVar | None:
|
|
107
|
+
"""Return information about the Actor environment variable.
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
timeout: Timeout for the API HTTP request.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
The retrieved Actor environment variable data.
|
|
115
|
+
"""
|
|
116
|
+
result = await self._get(timeout=timeout)
|
|
117
|
+
if result is None:
|
|
118
|
+
return None
|
|
119
|
+
return EnvVarResponse.model_validate(result).data
|
|
120
|
+
|
|
121
|
+
async def update(
|
|
122
|
+
self,
|
|
123
|
+
*,
|
|
124
|
+
is_secret: bool | None = None,
|
|
125
|
+
name: str,
|
|
126
|
+
value: str,
|
|
127
|
+
timeout: Timeout = 'short',
|
|
128
|
+
) -> EnvVar:
|
|
129
|
+
"""Update the Actor environment variable with specified fields.
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
is_secret: Whether the environment variable is secret or not.
|
|
134
|
+
name: The name of the environment variable.
|
|
135
|
+
value: The value of the environment variable.
|
|
136
|
+
timeout: Timeout for the API HTTP request.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
The updated Actor environment variable.
|
|
140
|
+
"""
|
|
141
|
+
result = await self._update(
|
|
142
|
+
timeout=timeout,
|
|
143
|
+
**EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True),
|
|
144
|
+
)
|
|
145
|
+
return EnvVarResponse.model_validate(result).data
|
|
146
|
+
|
|
147
|
+
async def delete(self, *, timeout: Timeout = 'short') -> None:
|
|
148
|
+
"""Delete the Actor environment variable.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
timeout: Timeout for the API HTTP request.
|
|
153
|
+
"""
|
|
154
|
+
await self._delete(timeout=timeout)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
|
|
5
|
+
from scrapely_client._docs import docs_group
|
|
6
|
+
from scrapely_client._models import EnvVar, EnvVarResponse, ListOfEnvVars, ListOfEnvVarsResponse
|
|
7
|
+
from scrapely_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from collections.abc import AsyncIterator, Iterator
|
|
11
|
+
|
|
12
|
+
from scrapely_client.types import Timeout
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@docs_group('Resource clients')
|
|
16
|
+
class ActorEnvVarCollectionClient(ResourceClient):
|
|
17
|
+
"""Sub-client for the Actor environment variable collection.
|
|
18
|
+
|
|
19
|
+
Provides methods to manage Actor environment variables, e.g. list or create them. Obtain an instance via an
|
|
20
|
+
appropriate method on the `ActorVersionClient` class.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
*,
|
|
26
|
+
resource_path: str = 'env-vars',
|
|
27
|
+
**kwargs: Any,
|
|
28
|
+
) -> None:
|
|
29
|
+
super().__init__(
|
|
30
|
+
resource_path=resource_path,
|
|
31
|
+
**kwargs,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def list(self, *, timeout: Timeout = 'short') -> ListOfEnvVars:
|
|
35
|
+
"""List the available Actor environment variables.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
timeout: Timeout for the API HTTP request.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
The list of available Actor environment variables.
|
|
43
|
+
"""
|
|
44
|
+
result = self._list(timeout=timeout)
|
|
45
|
+
return ListOfEnvVarsResponse.model_validate(result).data
|
|
46
|
+
|
|
47
|
+
def iterate(self, *, timeout: Timeout = 'short') -> Iterator[EnvVar]:
|
|
48
|
+
"""Iterate over the available Actor environment variables.
|
|
49
|
+
|
|
50
|
+
The underlying API endpoint does not support pagination, so this method performs a single API call and yields
|
|
51
|
+
the items from its response. If the endpoint returns more items than fit in one response (the API caps the page
|
|
52
|
+
size), the rest are not returned. In practice this is rarely a concern — Actors are not expected to define more
|
|
53
|
+
environment variables than the cap.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
timeout: Timeout for the API HTTP request.
|
|
58
|
+
|
|
59
|
+
Yields:
|
|
60
|
+
An Actor environment variable.
|
|
61
|
+
"""
|
|
62
|
+
return iter(self.list(timeout=timeout).items)
|
|
63
|
+
|
|
64
|
+
def create(
|
|
65
|
+
self,
|
|
66
|
+
*,
|
|
67
|
+
is_secret: bool | None = None,
|
|
68
|
+
name: str,
|
|
69
|
+
value: str,
|
|
70
|
+
timeout: Timeout = 'short',
|
|
71
|
+
) -> EnvVar:
|
|
72
|
+
"""Create a new Actor environment variable.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
is_secret: Whether the environment variable is secret or not.
|
|
77
|
+
name: The name of the environment variable.
|
|
78
|
+
value: The value of the environment variable.
|
|
79
|
+
timeout: Timeout for the API HTTP request.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
The created Actor environment variable.
|
|
83
|
+
"""
|
|
84
|
+
result = self._create(
|
|
85
|
+
timeout=timeout,
|
|
86
|
+
**EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True),
|
|
87
|
+
)
|
|
88
|
+
return EnvVarResponse.model_validate(result).data
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@docs_group('Resource clients')
|
|
92
|
+
class ActorEnvVarCollectionClientAsync(ResourceClientAsync):
|
|
93
|
+
"""Sub-client for the Actor environment variable collection.
|
|
94
|
+
|
|
95
|
+
Provides methods to manage Actor environment variables, e.g. list or create them. Obtain an instance via an
|
|
96
|
+
appropriate method on the `ActorVersionClientAsync` class.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
def __init__(
|
|
100
|
+
self,
|
|
101
|
+
*,
|
|
102
|
+
resource_path: str = 'env-vars',
|
|
103
|
+
**kwargs: Any,
|
|
104
|
+
) -> None:
|
|
105
|
+
super().__init__(
|
|
106
|
+
resource_path=resource_path,
|
|
107
|
+
**kwargs,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
async def list(self, *, timeout: Timeout = 'short') -> ListOfEnvVars:
|
|
111
|
+
"""List the available Actor environment variables.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
timeout: Timeout for the API HTTP request.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
The list of available Actor environment variables.
|
|
119
|
+
"""
|
|
120
|
+
result = await self._list(timeout=timeout)
|
|
121
|
+
return ListOfEnvVarsResponse.model_validate(result).data
|
|
122
|
+
|
|
123
|
+
async def iterate(self, *, timeout: Timeout = 'short') -> AsyncIterator[EnvVar]:
|
|
124
|
+
"""Iterate over the available Actor environment variables.
|
|
125
|
+
|
|
126
|
+
The underlying API endpoint does not support pagination, so this method performs a single API call and yields
|
|
127
|
+
the items from its response. If the endpoint returns more items than fit in one response (the API caps the page
|
|
128
|
+
size), the rest are not returned. In practice this is rarely a concern — Actors are not expected to define more
|
|
129
|
+
environment variables than the cap.
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
timeout: Timeout for the API HTTP request.
|
|
134
|
+
|
|
135
|
+
Yields:
|
|
136
|
+
An Actor environment variable.
|
|
137
|
+
"""
|
|
138
|
+
for item in (await self.list(timeout=timeout)).items:
|
|
139
|
+
yield item
|
|
140
|
+
|
|
141
|
+
async def create(
|
|
142
|
+
self,
|
|
143
|
+
*,
|
|
144
|
+
is_secret: bool | None = None,
|
|
145
|
+
name: str,
|
|
146
|
+
value: str,
|
|
147
|
+
timeout: Timeout = 'short',
|
|
148
|
+
) -> EnvVar:
|
|
149
|
+
"""Create a new Actor environment variable.
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
is_secret: Whether the environment variable is secret or not.
|
|
154
|
+
name: The name of the environment variable.
|
|
155
|
+
value: The value of the environment variable.
|
|
156
|
+
timeout: Timeout for the API HTTP request.
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
The created Actor environment variable.
|
|
160
|
+
"""
|
|
161
|
+
result = await self._create(
|
|
162
|
+
timeout=timeout,
|
|
163
|
+
**EnvVar(name=name, value=value, is_secret=is_secret).model_dump(by_alias=True, exclude_none=True),
|
|
164
|
+
)
|
|
165
|
+
return EnvVarResponse.model_validate(result).data
|