scrapely-client-python 3.1.3__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.

Files changed (65) hide show
  1. scrapely_client/__init__.py +30 -0
  2. scrapely_client/_charging.py +186 -0
  3. scrapely_client/_client_registry.py +136 -0
  4. scrapely_client/_consts.py +96 -0
  5. scrapely_client/_docs.py +37 -0
  6. scrapely_client/_literals.py +539 -0
  7. scrapely_client/_logging.py +180 -0
  8. scrapely_client/_models.py +4172 -0
  9. scrapely_client/_pagination.py +220 -0
  10. scrapely_client/_resource_clients/__init__.py +84 -0
  11. scrapely_client/_resource_clients/_resource_client.py +567 -0
  12. scrapely_client/_resource_clients/actor.py +1042 -0
  13. scrapely_client/_resource_clients/actor_collection.py +377 -0
  14. scrapely_client/_resource_clients/actor_env_var.py +154 -0
  15. scrapely_client/_resource_clients/actor_env_var_collection.py +165 -0
  16. scrapely_client/_resource_clients/actor_version.py +254 -0
  17. scrapely_client/_resource_clients/actor_version_collection.py +232 -0
  18. scrapely_client/_resource_clients/build.py +244 -0
  19. scrapely_client/_resource_clients/build_collection.py +164 -0
  20. scrapely_client/_resource_clients/dataset.py +1151 -0
  21. scrapely_client/_resource_clients/dataset_collection.py +244 -0
  22. scrapely_client/_resource_clients/key_value_store.py +906 -0
  23. scrapely_client/_resource_clients/key_value_store_collection.py +243 -0
  24. scrapely_client/_resource_clients/log.py +225 -0
  25. scrapely_client/_resource_clients/request_queue.py +1167 -0
  26. scrapely_client/_resource_clients/request_queue_collection.py +240 -0
  27. scrapely_client/_resource_clients/run.py +875 -0
  28. scrapely_client/_resource_clients/run_collection.py +226 -0
  29. scrapely_client/_resource_clients/schedule.py +243 -0
  30. scrapely_client/_resource_clients/schedule_collection.py +260 -0
  31. scrapely_client/_resource_clients/store_collection.py +242 -0
  32. scrapely_client/_resource_clients/task.py +793 -0
  33. scrapely_client/_resource_clients/task_collection.py +322 -0
  34. scrapely_client/_resource_clients/user.py +262 -0
  35. scrapely_client/_resource_clients/webhook.py +292 -0
  36. scrapely_client/_resource_clients/webhook_collection.py +281 -0
  37. scrapely_client/_resource_clients/webhook_dispatch.py +84 -0
  38. scrapely_client/_resource_clients/webhook_dispatch_collection.py +158 -0
  39. scrapely_client/_scrapely_client.py +837 -0
  40. scrapely_client/_statistics.py +29 -0
  41. scrapely_client/_status_message_watcher.py +197 -0
  42. scrapely_client/_streamed_log.py +250 -0
  43. scrapely_client/_typeddicts.py +408 -0
  44. scrapely_client/_utils/__init__.py +0 -0
  45. scrapely_client/_utils/crypto.py +87 -0
  46. scrapely_client/_utils/encoding.py +133 -0
  47. scrapely_client/_utils/errors.py +33 -0
  48. scrapely_client/_utils/http.py +137 -0
  49. scrapely_client/_utils/time.py +32 -0
  50. scrapely_client/_utils/try_import.py +61 -0
  51. scrapely_client/errors.py +190 -0
  52. scrapely_client/http_clients/__init__.py +10 -0
  53. scrapely_client/http_clients/_base.py +430 -0
  54. scrapely_client/http_clients/_impit.py +598 -0
  55. scrapely_client/http_compressors/__init__.py +18 -0
  56. scrapely_client/http_compressors/_base.py +25 -0
  57. scrapely_client/http_compressors/_brotli.py +38 -0
  58. scrapely_client/http_compressors/_gzip.py +38 -0
  59. scrapely_client/http_compressors/_resolve.py +38 -0
  60. scrapely_client/py.typed +0 -0
  61. scrapely_client/types.py +52 -0
  62. scrapely_client_python-3.1.3.dist-info/METADATA +269 -0
  63. scrapely_client_python-3.1.3.dist-info/RECORD +65 -0
  64. scrapely_client_python-3.1.3.dist-info/WHEEL +4 -0
  65. scrapely_client_python-3.1.3.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,226 @@
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 ListOfRuns, ListOfRunsResponse
7
+ from scrapely_client._pagination import get_items_iterator, get_items_iterator_async
8
+ from scrapely_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
9
+
10
+ if TYPE_CHECKING:
11
+ from collections.abc import AsyncIterator, Iterator
12
+ from datetime import datetime
13
+
14
+ from scrapely_client._literals import ActorJobStatus
15
+ from scrapely_client._models import RunShort
16
+ from scrapely_client.types import Timeout
17
+
18
+
19
+ @docs_group('Resource clients')
20
+ class RunCollectionClient(ResourceClient):
21
+ """Sub-client for the Actor run collection.
22
+
23
+ Provides methods to manage Actor runs, e.g. list them. Obtain an instance via an appropriate method on the
24
+ `ApifyClient` class.
25
+ """
26
+
27
+ def __init__(
28
+ self,
29
+ *,
30
+ resource_path: str = 'actor-runs',
31
+ **kwargs: Any,
32
+ ) -> None:
33
+ super().__init__(
34
+ resource_path=resource_path,
35
+ **kwargs,
36
+ )
37
+
38
+ def list(
39
+ self,
40
+ *,
41
+ limit: int | None = None,
42
+ offset: int | None = None,
43
+ desc: bool | None = None,
44
+ status: ActorJobStatus | list[ActorJobStatus] | None = None, # ty: ignore[invalid-type-form]
45
+ started_before: str | datetime | None = None,
46
+ started_after: str | datetime | None = None,
47
+ timeout: Timeout = 'medium',
48
+ ) -> ListOfRuns:
49
+ """List all Actor runs.
50
+
51
+ List all Actor runs, either of a single Actor, or all user's Actors, depending on where this client
52
+ was initialized from.
53
+
54
+
55
+ Args:
56
+ limit: How many runs to retrieve.
57
+ offset: What run to include as first when retrieving the list.
58
+ desc: Whether to sort the runs in descending order based on their start date.
59
+ status: Retrieve only runs with the provided statuses.
60
+ started_before: Only return runs started before this date (inclusive).
61
+ started_after: Only return runs started after this date (inclusive).
62
+ timeout: Timeout for the API HTTP request.
63
+
64
+ Returns:
65
+ The retrieved Actor runs.
66
+ """
67
+ status_param = list(status) if isinstance(status, list) else status
68
+
69
+ result = self._list(
70
+ timeout=timeout,
71
+ limit=limit,
72
+ offset=offset,
73
+ desc=desc,
74
+ status=status_param,
75
+ startedBefore=started_before,
76
+ startedAfter=started_after,
77
+ )
78
+ return ListOfRunsResponse.model_validate(result).data
79
+
80
+ def iterate(
81
+ self,
82
+ *,
83
+ limit: int | None = None,
84
+ offset: int | None = None,
85
+ desc: bool | None = None,
86
+ status: ActorJobStatus | list[ActorJobStatus] | None = None, # ty: ignore[invalid-type-form]
87
+ started_before: str | datetime | None = None,
88
+ started_after: str | datetime | None = None,
89
+ timeout: Timeout = 'medium',
90
+ ) -> Iterator[RunShort]:
91
+ """Iterate over all Actor runs.
92
+
93
+ Simple `list` does only one API call, possibly not listing all items matching the criteria. This method
94
+ returns an iterator that is capable of making multiple API calls to retrieve all items matching the criteria.
95
+
96
+
97
+ Args:
98
+ limit: How many runs to retrieve.
99
+ offset: What run to include as first when retrieving the list.
100
+ desc: Whether to sort the runs in descending order based on their start date.
101
+ status: Retrieve only runs with the provided statuses.
102
+ started_before: Only return runs started before this date (inclusive).
103
+ started_after: Only return runs started after this date (inclusive).
104
+ timeout: Timeout for the API HTTP request.
105
+
106
+ Yields:
107
+ The Actor runs matching the specified filters.
108
+ """
109
+
110
+ def _callback(*, limit: int | None = None, offset: int | None = None) -> ListOfRuns:
111
+ return self.list(
112
+ limit=limit,
113
+ offset=offset,
114
+ desc=desc,
115
+ status=status,
116
+ started_before=started_before,
117
+ started_after=started_after,
118
+ timeout=timeout,
119
+ )
120
+
121
+ return get_items_iterator(_callback, limit=limit, offset=offset)
122
+
123
+
124
+ @docs_group('Resource clients')
125
+ class RunCollectionClientAsync(ResourceClientAsync):
126
+ """Sub-client for the Actor run collection.
127
+
128
+ Provides methods to manage Actor runs, e.g. list them. Obtain an instance via an appropriate method on the
129
+ `ApifyClientAsync` class.
130
+ """
131
+
132
+ def __init__(
133
+ self,
134
+ *,
135
+ resource_path: str = 'actor-runs',
136
+ **kwargs: Any,
137
+ ) -> None:
138
+ super().__init__(
139
+ resource_path=resource_path,
140
+ **kwargs,
141
+ )
142
+
143
+ async def list(
144
+ self,
145
+ *,
146
+ limit: int | None = None,
147
+ offset: int | None = None,
148
+ desc: bool | None = None,
149
+ status: ActorJobStatus | list[ActorJobStatus] | None = None, # ty: ignore[invalid-type-form]
150
+ started_before: str | datetime | None = None,
151
+ started_after: str | datetime | None = None,
152
+ timeout: Timeout = 'medium',
153
+ ) -> ListOfRuns:
154
+ """List all Actor runs.
155
+
156
+ List all Actor runs, either of a single Actor, or all user's Actors, depending on where this client
157
+ was initialized from.
158
+
159
+
160
+ Args:
161
+ limit: How many runs to retrieve.
162
+ offset: What run to include as first when retrieving the list.
163
+ desc: Whether to sort the runs in descending order based on their start date.
164
+ status: Retrieve only runs with the provided statuses.
165
+ started_before: Only return runs started before this date (inclusive).
166
+ started_after: Only return runs started after this date (inclusive).
167
+ timeout: Timeout for the API HTTP request.
168
+
169
+ Returns:
170
+ The retrieved Actor runs.
171
+ """
172
+ status_param = list(status) if isinstance(status, list) else status
173
+
174
+ result = await self._list(
175
+ timeout=timeout,
176
+ limit=limit,
177
+ offset=offset,
178
+ desc=desc,
179
+ status=status_param,
180
+ startedBefore=started_before,
181
+ startedAfter=started_after,
182
+ )
183
+ return ListOfRunsResponse.model_validate(result).data
184
+
185
+ def iterate(
186
+ self,
187
+ *,
188
+ limit: int | None = None,
189
+ offset: int | None = None,
190
+ desc: bool | None = None,
191
+ status: ActorJobStatus | list[ActorJobStatus] | None = None, # ty: ignore[invalid-type-form]
192
+ started_before: str | datetime | None = None,
193
+ started_after: str | datetime | None = None,
194
+ timeout: Timeout = 'medium',
195
+ ) -> AsyncIterator[RunShort]:
196
+ """Iterate over all Actor runs.
197
+
198
+ Simple `list` does only one API call, possibly not listing all items matching the criteria. This method
199
+ returns an iterator that is capable of making multiple API calls to retrieve all items matching the criteria.
200
+
201
+
202
+ Args:
203
+ limit: How many runs to retrieve.
204
+ offset: What run to include as first when retrieving the list.
205
+ desc: Whether to sort the runs in descending order based on their start date.
206
+ status: Retrieve only runs with the provided statuses.
207
+ started_before: Only return runs started before this date (inclusive).
208
+ started_after: Only return runs started after this date (inclusive).
209
+ timeout: Timeout for the API HTTP request.
210
+
211
+ Yields:
212
+ The Actor runs matching the specified filters.
213
+ """
214
+
215
+ async def _callback(*, limit: int | None = None, offset: int | None = None) -> ListOfRuns:
216
+ return await self.list(
217
+ limit=limit,
218
+ offset=offset,
219
+ desc=desc,
220
+ status=status,
221
+ started_before=started_before,
222
+ started_after=started_after,
223
+ timeout=timeout,
224
+ )
225
+
226
+ return get_items_iterator_async(_callback, limit=limit, offset=offset)
@@ -0,0 +1,243 @@
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 (
7
+ Schedule,
8
+ ScheduleCreate,
9
+ ScheduleInvoked,
10
+ ScheduleLogResponse,
11
+ ScheduleResponse,
12
+ )
13
+ from scrapely_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
14
+ from scrapely_client._utils.http import response_to_dict
15
+
16
+ if TYPE_CHECKING:
17
+ from scrapely_client.types import Timeout
18
+
19
+
20
+ @docs_group('Resource clients')
21
+ class ScheduleClient(ResourceClient):
22
+ """Sub-client for managing a specific schedule.
23
+
24
+ Provides methods to manage a specific schedule, e.g. get, update, or delete it. Obtain an instance via an
25
+ appropriate method on the `ApifyClient` class.
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ *,
31
+ resource_id: str,
32
+ resource_path: str = 'schedules',
33
+ **kwargs: Any,
34
+ ) -> None:
35
+ super().__init__(
36
+ resource_id=resource_id,
37
+ resource_path=resource_path,
38
+ **kwargs,
39
+ )
40
+
41
+ def get(self, *, timeout: Timeout = 'short') -> Schedule | None:
42
+ """Return information about the schedule.
43
+
44
+
45
+ Args:
46
+ timeout: Timeout for the API HTTP request.
47
+
48
+ Returns:
49
+ The retrieved schedule.
50
+ """
51
+ result = self._get(timeout=timeout)
52
+ if result is None:
53
+ return None
54
+ return ScheduleResponse.model_validate(result).data
55
+
56
+ def update(
57
+ self,
58
+ *,
59
+ cron_expression: str | None = None,
60
+ is_enabled: bool | None = None,
61
+ is_exclusive: bool | None = None,
62
+ name: str | None = None,
63
+ actions: list[dict[str, Any]] | None = None,
64
+ description: str | None = None,
65
+ timezone: str | None = None,
66
+ title: str | None = None,
67
+ timeout: Timeout = 'short',
68
+ ) -> Schedule:
69
+ """Update the schedule with specified fields.
70
+
71
+
72
+ Args:
73
+ cron_expression: The cron expression used by this schedule.
74
+ is_enabled: True if the schedule should be enabled.
75
+ is_exclusive: When set to true, don't start Actor or Actor task if it's still running from the previous
76
+ schedule.
77
+ name: The name of the schedule to create.
78
+ actions: Actors or tasks that should be run on this schedule. See the API documentation for exact structure.
79
+ description: Description of this schedule.
80
+ timezone: Timezone in which your cron expression runs (TZ database name from
81
+ https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
82
+ title: A human-friendly equivalent of the name.
83
+ timeout: Timeout for the API HTTP request.
84
+
85
+ Returns:
86
+ The updated schedule.
87
+ """
88
+ schedule_fields = ScheduleCreate(
89
+ cron_expression=cron_expression,
90
+ is_enabled=is_enabled,
91
+ is_exclusive=is_exclusive,
92
+ name=name,
93
+ actions=actions or None,
94
+ description=description,
95
+ timezone=timezone,
96
+ title=title,
97
+ )
98
+ result = self._update(timeout=timeout, **schedule_fields.model_dump(by_alias=True, exclude_none=True))
99
+ return ScheduleResponse.model_validate(result).data
100
+
101
+ def delete(self, *, timeout: Timeout = 'short') -> None:
102
+ """Delete the schedule.
103
+
104
+
105
+ Args:
106
+ timeout: Timeout for the API HTTP request.
107
+ """
108
+ self._delete(timeout=timeout)
109
+
110
+ def get_log(self, *, timeout: Timeout = 'medium') -> list[ScheduleInvoked]:
111
+ """Return log for the given schedule.
112
+
113
+
114
+ Args:
115
+ timeout: Timeout for the API HTTP request.
116
+
117
+ Returns:
118
+ Retrieved log of the given schedule.
119
+
120
+ Raises:
121
+ NotFoundError: If the schedule does not exist.
122
+ """
123
+ response = self._http_client.call(
124
+ url=self._build_url('log'),
125
+ method='GET',
126
+ params=self._build_params(),
127
+ timeout=timeout,
128
+ )
129
+ result = response_to_dict(response)
130
+ return ScheduleLogResponse.model_validate(result).data
131
+
132
+
133
+ @docs_group('Resource clients')
134
+ class ScheduleClientAsync(ResourceClientAsync):
135
+ """Sub-client for managing a specific schedule.
136
+
137
+ Provides methods to manage a specific schedule, e.g. get, update, or delete it. Obtain an instance via an
138
+ appropriate method on the `ApifyClientAsync` class.
139
+ """
140
+
141
+ def __init__(
142
+ self,
143
+ *,
144
+ resource_id: str,
145
+ resource_path: str = 'schedules',
146
+ **kwargs: Any,
147
+ ) -> None:
148
+ super().__init__(
149
+ resource_id=resource_id,
150
+ resource_path=resource_path,
151
+ **kwargs,
152
+ )
153
+
154
+ async def get(self, *, timeout: Timeout = 'short') -> Schedule | None:
155
+ """Return information about the schedule.
156
+
157
+
158
+ Args:
159
+ timeout: Timeout for the API HTTP request.
160
+
161
+ Returns:
162
+ The retrieved schedule.
163
+ """
164
+ result = await self._get(timeout=timeout)
165
+ if result is None:
166
+ return None
167
+ return ScheduleResponse.model_validate(result).data
168
+
169
+ async def update(
170
+ self,
171
+ *,
172
+ cron_expression: str | None = None,
173
+ is_enabled: bool | None = None,
174
+ is_exclusive: bool | None = None,
175
+ name: str | None = None,
176
+ actions: list[dict[str, Any]] | None = None,
177
+ description: str | None = None,
178
+ timezone: str | None = None,
179
+ title: str | None = None,
180
+ timeout: Timeout = 'short',
181
+ ) -> Schedule:
182
+ """Update the schedule with specified fields.
183
+
184
+
185
+ Args:
186
+ cron_expression: The cron expression used by this schedule.
187
+ is_enabled: True if the schedule should be enabled.
188
+ is_exclusive: When set to true, don't start Actor or Actor task if it's still running from the previous
189
+ schedule.
190
+ name: The name of the schedule to create.
191
+ actions: Actors or tasks that should be run on this schedule. See the API documentation for exact structure.
192
+ description: Description of this schedule.
193
+ timezone: Timezone in which your cron expression runs (TZ database name from
194
+ https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
195
+ title: A human-friendly equivalent of the name.
196
+ timeout: Timeout for the API HTTP request.
197
+
198
+ Returns:
199
+ The updated schedule.
200
+ """
201
+ schedule_fields = ScheduleCreate(
202
+ cron_expression=cron_expression,
203
+ is_enabled=is_enabled,
204
+ is_exclusive=is_exclusive,
205
+ name=name,
206
+ actions=actions or None,
207
+ description=description,
208
+ timezone=timezone,
209
+ title=title,
210
+ )
211
+ result = await self._update(timeout=timeout, **schedule_fields.model_dump(by_alias=True, exclude_none=True))
212
+ return ScheduleResponse.model_validate(result).data
213
+
214
+ async def delete(self, *, timeout: Timeout = 'short') -> None:
215
+ """Delete the schedule.
216
+
217
+
218
+ Args:
219
+ timeout: Timeout for the API HTTP request.
220
+ """
221
+ await self._delete(timeout=timeout)
222
+
223
+ async def get_log(self, *, timeout: Timeout = 'medium') -> list[ScheduleInvoked]:
224
+ """Return log for the given schedule.
225
+
226
+
227
+ Args:
228
+ timeout: Timeout for the API HTTP request.
229
+
230
+ Returns:
231
+ Retrieved log of the given schedule.
232
+
233
+ Raises:
234
+ NotFoundError: If the schedule does not exist.
235
+ """
236
+ response = await self._http_client.call(
237
+ url=self._build_url('log'),
238
+ method='GET',
239
+ params=self._build_params(),
240
+ timeout=timeout,
241
+ )
242
+ result = response_to_dict(response)
243
+ return ScheduleLogResponse.model_validate(result).data