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,254 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+ from pydantic import TypeAdapter
6
+
7
+ from scrapely_client._docs import docs_group
8
+ from scrapely_client._models import (
9
+ CreateOrUpdateVersionRequest,
10
+ EnvVarRequest,
11
+ SourceCodeFile,
12
+ SourceCodeFolder,
13
+ Version,
14
+ VersionResponse,
15
+ )
16
+ from scrapely_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
17
+
18
+ if TYPE_CHECKING:
19
+ from scrapely_client._literals import VersionSourceType
20
+ from scrapely_client._resource_clients import (
21
+ ActorEnvVarClient,
22
+ ActorEnvVarClientAsync,
23
+ ActorEnvVarCollectionClient,
24
+ ActorEnvVarCollectionClientAsync,
25
+ )
26
+ from scrapely_client.types import Timeout
27
+
28
+ _source_file_list_adapter = TypeAdapter(list[SourceCodeFile | SourceCodeFolder])
29
+
30
+
31
+ @docs_group('Resource clients')
32
+ class ActorVersionClient(ResourceClient):
33
+ """Sub-client for managing a specific Actor version.
34
+
35
+ Provides methods to manage a specific Actor version, e.g. get, update, or delete it. Obtain an instance via an
36
+ appropriate method on the `ActorClient` class.
37
+ """
38
+
39
+ def __init__(
40
+ self,
41
+ *,
42
+ resource_id: str,
43
+ resource_path: str = 'versions',
44
+ **kwargs: Any,
45
+ ) -> None:
46
+ super().__init__(
47
+ resource_id=resource_id,
48
+ resource_path=resource_path,
49
+ **kwargs,
50
+ )
51
+
52
+ def get(self, *, timeout: Timeout = 'short') -> Version | None:
53
+ """Return information about the Actor version.
54
+
55
+
56
+ Args:
57
+ timeout: Timeout for the API HTTP request.
58
+
59
+ Returns:
60
+ The retrieved Actor version data.
61
+ """
62
+ result = self._get(timeout=timeout)
63
+ if result is None:
64
+ return None
65
+ return VersionResponse.model_validate(result).data
66
+
67
+ def update(
68
+ self,
69
+ *,
70
+ build_tag: str | None = None,
71
+ env_vars: list[dict[str, Any]] | None = None,
72
+ apply_env_vars_to_build: bool | None = None,
73
+ source_type: VersionSourceType | None = None,
74
+ source_files: list[dict[str, Any]] | None = None,
75
+ git_repo_url: str | None = None,
76
+ tarball_url: str | None = None,
77
+ github_gist_url: str | None = None,
78
+ timeout: Timeout = 'short',
79
+ ) -> Version:
80
+ """Update the Actor version with specified fields.
81
+
82
+
83
+ Args:
84
+ build_tag: Tag that is automatically set to the latest successful build of the current version.
85
+ env_vars: Environment variables that will be available to the Actor run process, and optionally
86
+ also to the build process. See the API docs for their exact structure.
87
+ apply_env_vars_to_build: Whether the environment variables specified for the Actor run will also
88
+ be set to the Actor build process.
89
+ source_type: What source type is the Actor version using.
90
+ source_files: Source code comprised of multiple files, each an item of the array. Required when
91
+ `source_type` is `'SOURCE_FILES'`. See the API docs for the exact structure.
92
+ git_repo_url: The URL of a Git repository from which the source code will be cloned.
93
+ Required when `source_type` is `'GIT_REPO'`.
94
+ tarball_url: The URL of a tarball or a zip archive from which the source code will be downloaded.
95
+ Required when `source_type` is `'TARBALL'`.
96
+ github_gist_url: The URL of a GitHub Gist from which the source will be downloaded.
97
+ Required when `source_type` is `'GITHUB_GIST'`.
98
+ timeout: Timeout for the API HTTP request.
99
+
100
+ Returns:
101
+ The updated Actor version.
102
+ """
103
+ version_fields = CreateOrUpdateVersionRequest(
104
+ build_tag=build_tag,
105
+ env_vars=[EnvVarRequest.model_validate(v) for v in env_vars] if env_vars else None,
106
+ apply_env_vars_to_build=apply_env_vars_to_build,
107
+ source_type=source_type,
108
+ source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None,
109
+ git_repo_url=git_repo_url,
110
+ tarball_url=tarball_url,
111
+ github_gist_url=github_gist_url,
112
+ )
113
+ result = self._update(timeout=timeout, **version_fields.model_dump(by_alias=True, exclude_none=True))
114
+ return VersionResponse.model_validate(result).data
115
+
116
+ def delete(self, *, timeout: Timeout = 'short') -> None:
117
+ """Delete the Actor version.
118
+
119
+
120
+ Args:
121
+ timeout: Timeout for the API HTTP request.
122
+ """
123
+ self._delete(timeout=timeout)
124
+
125
+ def env_vars(self) -> ActorEnvVarCollectionClient:
126
+ """Retrieve a client for the environment variables of this Actor version."""
127
+ return self._client_registry.actor_env_var_collection_client(**self._base_client_kwargs)
128
+
129
+ def env_var(self, env_var_name: str) -> ActorEnvVarClient:
130
+ """Retrieve the client for the specified environment variable of this Actor version.
131
+
132
+ Args:
133
+ env_var_name: The name of the environment variable for which to retrieve the resource client.
134
+
135
+ Returns:
136
+ The resource client for the specified Actor environment variable.
137
+ """
138
+ return self._client_registry.actor_env_var_client(
139
+ resource_id=env_var_name,
140
+ **self._base_client_kwargs,
141
+ )
142
+
143
+
144
+ @docs_group('Resource clients')
145
+ class ActorVersionClientAsync(ResourceClientAsync):
146
+ """Sub-client for managing a specific Actor version.
147
+
148
+ Provides methods to manage a specific Actor version, e.g. get, update, or delete it. Obtain an instance via an
149
+ appropriate method on the `ActorClientAsync` class.
150
+ """
151
+
152
+ def __init__(
153
+ self,
154
+ *,
155
+ resource_id: str,
156
+ resource_path: str = 'versions',
157
+ **kwargs: Any,
158
+ ) -> None:
159
+ super().__init__(
160
+ resource_id=resource_id,
161
+ resource_path=resource_path,
162
+ **kwargs,
163
+ )
164
+
165
+ async def get(self, *, timeout: Timeout = 'short') -> Version | None:
166
+ """Return information about the Actor version.
167
+
168
+
169
+ Args:
170
+ timeout: Timeout for the API HTTP request.
171
+
172
+ Returns:
173
+ The retrieved Actor version data.
174
+ """
175
+ result = await self._get(timeout=timeout)
176
+ if result is None:
177
+ return None
178
+ return VersionResponse.model_validate(result).data
179
+
180
+ async def update(
181
+ self,
182
+ *,
183
+ build_tag: str | None = None,
184
+ env_vars: list[dict[str, Any]] | None = None,
185
+ apply_env_vars_to_build: bool | None = None,
186
+ source_type: VersionSourceType | None = None,
187
+ source_files: list[dict[str, Any]] | None = None,
188
+ git_repo_url: str | None = None,
189
+ tarball_url: str | None = None,
190
+ github_gist_url: str | None = None,
191
+ timeout: Timeout = 'short',
192
+ ) -> Version:
193
+ """Update the Actor version with specified fields.
194
+
195
+
196
+ Args:
197
+ build_tag: Tag that is automatically set to the latest successful build of the current version.
198
+ env_vars: Environment variables that will be available to the Actor run process, and optionally
199
+ also to the build process. See the API docs for their exact structure.
200
+ apply_env_vars_to_build: Whether the environment variables specified for the Actor run will also
201
+ be set to the Actor build process.
202
+ source_type: What source type is the Actor version using.
203
+ source_files: Source code comprised of multiple files, each an item of the array. Required when
204
+ `source_type` is `'SOURCE_FILES'`. See the API docs for the exact structure.
205
+ git_repo_url: The URL of a Git repository from which the source code will be cloned.
206
+ Required when `source_type` is `'GIT_REPO'`.
207
+ tarball_url: The URL of a tarball or a zip archive from which the source code will be downloaded.
208
+ Required when `source_type` is `'TARBALL'`.
209
+ github_gist_url: The URL of a GitHub Gist from which the source will be downloaded.
210
+ Required when `source_type` is `'GITHUB_GIST'`.
211
+ timeout: Timeout for the API HTTP request.
212
+
213
+ Returns:
214
+ The updated Actor version.
215
+ """
216
+ version_fields = CreateOrUpdateVersionRequest(
217
+ build_tag=build_tag,
218
+ env_vars=[EnvVarRequest.model_validate(v) for v in env_vars] if env_vars else None,
219
+ apply_env_vars_to_build=apply_env_vars_to_build,
220
+ source_type=source_type,
221
+ source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None,
222
+ git_repo_url=git_repo_url,
223
+ tarball_url=tarball_url,
224
+ github_gist_url=github_gist_url,
225
+ )
226
+ result = await self._update(timeout=timeout, **version_fields.model_dump(by_alias=True, exclude_none=True))
227
+ return VersionResponse.model_validate(result).data
228
+
229
+ async def delete(self, *, timeout: Timeout = 'short') -> None:
230
+ """Delete the Actor version.
231
+
232
+
233
+ Args:
234
+ timeout: Timeout for the API HTTP request.
235
+ """
236
+ await self._delete(timeout=timeout)
237
+
238
+ def env_vars(self) -> ActorEnvVarCollectionClientAsync:
239
+ """Retrieve a client for the environment variables of this Actor version."""
240
+ return self._client_registry.actor_env_var_collection_client(**self._base_client_kwargs)
241
+
242
+ def env_var(self, env_var_name: str) -> ActorEnvVarClientAsync:
243
+ """Retrieve the client for the specified environment variable of this Actor version.
244
+
245
+ Args:
246
+ env_var_name: The name of the environment variable for which to retrieve the resource client.
247
+
248
+ Returns:
249
+ The resource client for the specified Actor environment variable.
250
+ """
251
+ return self._client_registry.actor_env_var_client(
252
+ resource_id=env_var_name,
253
+ **self._base_client_kwargs,
254
+ )
@@ -0,0 +1,232 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+ from pydantic import TypeAdapter
6
+
7
+ from scrapely_client._docs import docs_group
8
+ from scrapely_client._models import (
9
+ CreateOrUpdateVersionRequest,
10
+ EnvVarRequest,
11
+ ListOfVersions,
12
+ ListOfVersionsResponse,
13
+ SourceCodeFile,
14
+ SourceCodeFolder,
15
+ Version,
16
+ VersionResponse,
17
+ )
18
+ from scrapely_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
19
+
20
+ if TYPE_CHECKING:
21
+ from collections.abc import AsyncIterator, Iterator
22
+
23
+ from scrapely_client._literals import VersionSourceType
24
+ from scrapely_client.types import Timeout
25
+
26
+
27
+ _source_file_list_adapter = TypeAdapter(list[SourceCodeFile | SourceCodeFolder])
28
+
29
+
30
+ @docs_group('Resource clients')
31
+ class ActorVersionCollectionClient(ResourceClient):
32
+ """Sub-client for the Actor version collection.
33
+
34
+ Provides methods to manage Actor versions, e.g. list or create them. Obtain an instance via an appropriate method
35
+ on the `ActorClient` class.
36
+ """
37
+
38
+ def __init__(
39
+ self,
40
+ *,
41
+ resource_path: str = 'versions',
42
+ **kwargs: Any,
43
+ ) -> None:
44
+ super().__init__(
45
+ resource_path=resource_path,
46
+ **kwargs,
47
+ )
48
+
49
+ def list(self, *, timeout: Timeout = 'short') -> ListOfVersions:
50
+ """List the available Actor versions.
51
+
52
+
53
+ Args:
54
+ timeout: Timeout for the API HTTP request.
55
+
56
+ Returns:
57
+ The list of available Actor versions.
58
+ """
59
+ result = self._list(timeout=timeout)
60
+ return ListOfVersionsResponse.model_validate(result).data
61
+
62
+ def iterate(self, *, timeout: Timeout = 'short') -> Iterator[Version]:
63
+ """Iterate over the available Actor versions.
64
+
65
+ The underlying API endpoint does not support pagination, so this method performs a single API call and yields
66
+ the items from its response. If the endpoint returns more items than fit in one response (the API caps the page
67
+ size), the rest are not returned. In practice this is rarely a concern — Actors are not expected to have more
68
+ versions than the cap.
69
+
70
+
71
+ Args:
72
+ timeout: Timeout for the API HTTP request.
73
+
74
+ Yields:
75
+ An Actor version.
76
+ """
77
+ return iter(self.list(timeout=timeout).items)
78
+
79
+ def create(
80
+ self,
81
+ *,
82
+ version_number: str,
83
+ build_tag: str | None = None,
84
+ env_vars: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form]
85
+ apply_env_vars_to_build: bool | None = None,
86
+ source_type: VersionSourceType,
87
+ source_files: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form]
88
+ git_repo_url: str | None = None,
89
+ tarball_url: str | None = None,
90
+ github_gist_url: str | None = None,
91
+ timeout: Timeout = 'short',
92
+ ) -> Version:
93
+ """Create a new Actor version.
94
+
95
+
96
+ Args:
97
+ version_number: Major and minor version of the Actor (e.g. `1.0`).
98
+ build_tag: Tag that is automatically set to the latest successful build of the current version.
99
+ env_vars: Environment variables that will be available to the Actor run process, and optionally
100
+ also to the build process. See the API docs for their exact structure.
101
+ apply_env_vars_to_build: Whether the environment variables specified for the Actor run will also
102
+ be set to the Actor build process.
103
+ source_type: What source type is the Actor version using.
104
+ source_files: Source code comprised of multiple files, each an item of the array. Required
105
+ when `source_type` is `'SOURCE_FILES'`. See the API docs for the exact structure.
106
+ git_repo_url: The URL of a Git repository from which the source code will be cloned.
107
+ Required when `source_type` is `'GIT_REPO'`.
108
+ tarball_url: The URL of a tarball or a zip archive from which the source code will be downloaded.
109
+ Required when `source_type` is `'TARBALL'`.
110
+ github_gist_url: The URL of a GitHub Gist from which the source will be downloaded.
111
+ Required when `source_type` is `'GITHUB_GIST'`.
112
+ timeout: Timeout for the API HTTP request.
113
+
114
+ Returns:
115
+ The created Actor version.
116
+ """
117
+ version_fields = CreateOrUpdateVersionRequest(
118
+ version_number=version_number,
119
+ build_tag=build_tag,
120
+ env_vars=[EnvVarRequest.model_validate(v) for v in env_vars] if env_vars else None,
121
+ apply_env_vars_to_build=apply_env_vars_to_build,
122
+ source_type=source_type,
123
+ source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None,
124
+ git_repo_url=git_repo_url,
125
+ tarball_url=tarball_url,
126
+ github_gist_url=github_gist_url,
127
+ )
128
+ result = self._create(timeout=timeout, **version_fields.model_dump(by_alias=True, exclude_none=True))
129
+ return VersionResponse.model_validate(result).data
130
+
131
+
132
+ @docs_group('Resource clients')
133
+ class ActorVersionCollectionClientAsync(ResourceClientAsync):
134
+ """Sub-client for the Actor version collection.
135
+
136
+ Provides methods to manage Actor versions, e.g. list or create them. Obtain an instance via an appropriate method
137
+ on the `ActorClientAsync` class.
138
+ """
139
+
140
+ def __init__(
141
+ self,
142
+ *,
143
+ resource_path: str = 'versions',
144
+ **kwargs: Any,
145
+ ) -> None:
146
+ super().__init__(
147
+ resource_path=resource_path,
148
+ **kwargs,
149
+ )
150
+
151
+ async def list(self, *, timeout: Timeout = 'short') -> ListOfVersions:
152
+ """List the available Actor versions.
153
+
154
+
155
+ Args:
156
+ timeout: Timeout for the API HTTP request.
157
+
158
+ Returns:
159
+ The list of available Actor versions.
160
+ """
161
+ result = await self._list(timeout=timeout)
162
+ return ListOfVersionsResponse.model_validate(result).data
163
+
164
+ async def iterate(self, *, timeout: Timeout = 'short') -> AsyncIterator[Version]:
165
+ """Iterate over the available Actor versions.
166
+
167
+ The underlying API endpoint does not support pagination, so this method performs a single API call and yields
168
+ the items from its response. If the endpoint returns more items than fit in one response (the API caps the page
169
+ size), the rest are not returned. In practice this is rarely a concern — Actors are not expected to have more
170
+ versions than the cap.
171
+
172
+
173
+ Args:
174
+ timeout: Timeout for the API HTTP request.
175
+
176
+ Yields:
177
+ An Actor version.
178
+ """
179
+ for item in (await self.list(timeout=timeout)).items:
180
+ yield item
181
+
182
+ async def create(
183
+ self,
184
+ *,
185
+ version_number: str,
186
+ build_tag: str | None = None,
187
+ env_vars: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form]
188
+ apply_env_vars_to_build: bool | None = None,
189
+ source_type: VersionSourceType,
190
+ source_files: list[dict[str, Any]] | None = None, # ty: ignore[invalid-type-form]
191
+ git_repo_url: str | None = None,
192
+ tarball_url: str | None = None,
193
+ github_gist_url: str | None = None,
194
+ timeout: Timeout = 'short',
195
+ ) -> Version:
196
+ """Create a new Actor version.
197
+
198
+
199
+ Args:
200
+ version_number: Major and minor version of the Actor (e.g. `1.0`).
201
+ build_tag: Tag that is automatically set to the latest successful build of the current version.
202
+ env_vars: Environment variables that will be available to the Actor run process, and optionally
203
+ also to the build process. See the API docs for their exact structure.
204
+ apply_env_vars_to_build: Whether the environment variables specified for the Actor run will also
205
+ be set to the Actor build process.
206
+ source_type: What source type is the Actor version using.
207
+ source_files: Source code comprised of multiple files, each an item of the array. Required
208
+ when `source_type` is `'SOURCE_FILES'`. See the API docs for the exact structure.
209
+ git_repo_url: The URL of a Git repository from which the source code will be cloned.
210
+ Required when `source_type` is `'GIT_REPO'`.
211
+ tarball_url: The URL of a tarball or a zip archive from which the source code will be downloaded.
212
+ Required when `source_type` is `'TARBALL'`.
213
+ github_gist_url: The URL of a GitHub Gist from which the source will be downloaded.
214
+ Required when `source_type` is `'GITHUB_GIST'`.
215
+ timeout: Timeout for the API HTTP request.
216
+
217
+ Returns:
218
+ The created Actor version.
219
+ """
220
+ version_fields = CreateOrUpdateVersionRequest(
221
+ version_number=version_number,
222
+ build_tag=build_tag,
223
+ env_vars=[EnvVarRequest.model_validate(v) for v in env_vars] if env_vars else None,
224
+ apply_env_vars_to_build=apply_env_vars_to_build,
225
+ source_type=source_type,
226
+ source_files=_source_file_list_adapter.validate_python(source_files) if source_files else None,
227
+ git_repo_url=git_repo_url,
228
+ tarball_url=tarball_url,
229
+ github_gist_url=github_gist_url,
230
+ )
231
+ result = await self._create(timeout=timeout, **version_fields.model_dump(by_alias=True, exclude_none=True))
232
+ return VersionResponse.model_validate(result).data