scrapely-python 0.1.47__tar.gz → 0.1.48__tar.gz

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.
Files changed (85) hide show
  1. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/CHANGELOG.md +4 -0
  2. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/PKG-INFO +1 -1
  3. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/pyproject.toml +1 -1
  4. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/__init__.py +1 -1
  5. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/actor.py +15 -0
  6. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/charging.py +14 -4
  7. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/resume_dedupe.py +48 -3
  8. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely_python.egg-info/PKG-INFO +1 -1
  9. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/LICENSE +0 -0
  10. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/LICENSE-APACHE +0 -0
  11. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/MANIFEST.in +0 -0
  12. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/NOTICE +0 -0
  13. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/README.md +0 -0
  14. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/setup.cfg +0 -0
  15. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/_browser_locations.py +0 -0
  16. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/browser_configuration.py +0 -0
  17. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/cdp_retry.py +0 -0
  18. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/charging_client.py +0 -0
  19. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/configuration.py +0 -0
  20. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/crypto/__init__.py +0 -0
  21. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/crypto/_secrets.py +0 -0
  22. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/errors.py +0 -0
  23. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/events/__init__.py +0 -0
  24. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/events/_types.py +0 -0
  25. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/events/event_manager.py +0 -0
  26. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/__init__.py +0 -0
  27. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_capture.py +0 -0
  28. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_client.py +0 -0
  29. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_compat.py +0 -0
  30. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_detect.py +0 -0
  31. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_headers.py +0 -0
  32. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_options.py +0 -0
  33. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_policy.py +0 -0
  34. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_profiles.py +0 -0
  35. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_response.py +0 -0
  36. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_stats.py +0 -0
  37. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/_transport.py +0 -0
  38. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/http/profiles.json +0 -0
  39. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/log.py +0 -0
  40. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/patch_browser_pool.py +0 -0
  41. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/pricing_types.py +0 -0
  42. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/proxy_configuration.py +0 -0
  43. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/py.typed +0 -0
  44. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/request_loaders/__init__.py +0 -0
  45. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/request_loaders/_scrapely_request_list.py +0 -0
  46. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/__init__.py +0 -0
  47. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/_actor_runner.py +0 -0
  48. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/_async_thread.py +0 -0
  49. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/_logging_config.py +0 -0
  50. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/_serialization.py +0 -0
  51. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/_warnings.py +0 -0
  52. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/extensions/__init__.py +0 -0
  53. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/extensions/_graceful_stop.py +0 -0
  54. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/extensions/_httpcache.py +0 -0
  55. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/middlewares/__init__.py +0 -0
  56. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/middlewares/apify_proxy.py +0 -0
  57. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/pipelines/__init__.py +0 -0
  58. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/pipelines/actor_dataset_push.py +0 -0
  59. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/requests.py +0 -0
  60. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/scheduler.py +0 -0
  61. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/scrapy/utils.py +0 -0
  62. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/solver.py +0 -0
  63. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/__init__.py +0 -0
  64. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/_file_system/__init__.py +0 -0
  65. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/_file_system/_key_value_store_client.py +0 -0
  66. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/_file_system/_storage_client.py +0 -0
  67. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/_metadata.py +0 -0
  68. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/api_client.py +0 -0
  69. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/client.py +0 -0
  70. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/patch_storage.py +0 -0
  71. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/scrapely_dataset_client.py +0 -0
  72. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/scrapely_kvs_client.py +0 -0
  73. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/scrapely_rq_client.py +0 -0
  74. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/scrapely_storage_client.py +0 -0
  75. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/smart_scrapely_storage_client.py +0 -0
  76. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/types.py +0 -0
  77. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage/utils.py +0 -0
  78. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storage_clients/__init__.py +0 -0
  79. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/storages/__init__.py +0 -0
  80. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/types.py +0 -0
  81. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely/webhook.py +0 -0
  82. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely_python.egg-info/SOURCES.txt +0 -0
  83. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely_python.egg-info/dependency_links.txt +0 -0
  84. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely_python.egg-info/requires.txt +0 -0
  85. {scrapely_python-0.1.47 → scrapely_python-0.1.48}/src/scrapely_python.egg-info/top_level.txt +0 -0
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.1.48] - 2026-11-10
8
+
9
+ - **A resurrected or rebooted run stops at the Actor's own result limit.** A resumed run starts the Actor's code again, and with it the Actor's own result count, so an Actor whose source returns results in a different order each run (search pages, feeds) could end with more results than its limit: with `maxResults` 60, 24 rows saved before the abort plus the resumed run's own 60 (some of them saved before and skipped) gave 67. `Actor.set_result_limit(n)` declares the Actor's run-level result limit, e.g. its `maxItems` input. In a resumed run the rows saved before count towards it: once they and the new rows reach `n`, further charged rows are refused like at the spending limit (not saved, not charged, the push reports the limit), so the run ends with `n` results. Declare only a limit that counts all results of the run, not one per search. Nothing changes in a first run or for Actors that do not declare a limit.
10
+
7
11
  ## [0.1.47] - 2026-11-10
8
12
 
9
13
  - **A resurrected or rebooted run no longer charges again for results it had already saved.** Such a run keeps its default dataset, but the Actor's code starts from the beginning, and an Actor without its own progress state collects the results it saved before once more. On the first charged push to the default dataset of such a run, the SDK reads the result key of the rows already saved (one read of the dataset's `id` values; `id` by default). A charged row whose key is one of them is not saved and not charged again: the dataset already holds it and it was paid for when it was first saved. It counts as accepted in the push result (`charged_count`) and in `get_charged_event_count()`, so Actors that compare pushed and charged counts do not stop. The run's spending limit is not used by these rows.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scrapely-python
3
- Version: 0.1.47
3
+ Version: 0.1.48
4
4
  Summary: Scrapely Python SDK - A toolkit for building Actors on the Scrapely platform
5
5
  Author-email: Scrapely <hello@scrape.ly>
6
6
  License-Expression: MIT AND Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "scrapely-python"
7
- version = "0.1.47"
7
+ version = "0.1.48"
8
8
  description = "Scrapely Python SDK - A toolkit for building Actors on the Scrapely platform"
9
9
  readme = "README.md"
10
10
  license = "MIT AND Apache-2.0"
@@ -325,7 +325,7 @@ if TYPE_CHECKING: # Static analysers and IDEs see the lazy names as plain impor
325
325
  )
326
326
  from .webhook import Webhook, WebhookEventType
327
327
 
328
- __version__ = '0.1.47'
328
+ __version__ = '0.1.48'
329
329
  __all__ = [
330
330
  # Core
331
331
  'Actor',
@@ -1010,6 +1010,21 @@ class Actor(metaclass=_ActorMeta):
1010
1010
  target.push_data,
1011
1011
  )
1012
1012
 
1013
+ @classmethod
1014
+ def set_result_limit(cls, limit: Optional[int]) -> None:
1015
+ """Declare the Actor's run-level result limit (e.g. its ``maxItems`` input).
1016
+
1017
+ A resurrected or rebooted run starts the Actor's code again, and with it the
1018
+ Actor's own result count. With a declared limit, the rows the run saved before
1019
+ count towards it: once they and the new rows of the resumed run reach ``limit``,
1020
+ further charged rows are refused like at the spending limit (not saved, not
1021
+ charged, the push reports the limit). Only declare a limit that counts all
1022
+ results of the run, not one per search. ``None`` removes it.
1023
+ """
1024
+ from .resume_dedupe import get_resume_dedupe
1025
+
1026
+ get_resume_dedupe().set_result_limit(limit)
1027
+
1013
1028
  @classmethod
1014
1029
  def set_result_key(cls, key: Union[str, List[str], None]) -> None:
1015
1030
  """Name the field(s) that identify one result row (default ``'id'``).
@@ -1945,9 +1945,17 @@ async def _skip_saved_rows(
1945
1945
  return await push(rows)
1946
1946
  async with dedupe.lock:
1947
1947
  kept, skipped, pushed = dedupe.plan(rows)
1948
- if not skipped:
1948
+ # The Actor's declared run-level limit counts the rows saved before.
1949
+ room = dedupe.remaining()
1950
+ capped = room is not None and len(kept) > room
1951
+ if capped:
1952
+ kept, pushed = kept[:room], pushed[:room]
1953
+ dedupe.note_capped()
1954
+ if not skipped and not capped:
1949
1955
  result = await push(kept)
1950
- dedupe.commit([], pushed[: max(0, result.charged_count)])
1956
+ stored = max(0, result.charged_count)
1957
+ dedupe.commit([], pushed[:stored])
1958
+ dedupe.note_new_rows(stored)
1951
1959
  return result
1952
1960
  if kept:
1953
1961
  result = await push(kept)
@@ -1957,12 +1965,14 @@ async def _skip_saved_rows(
1957
1965
  charged_count=0,
1958
1966
  event_charge_limit_reached=charging_manager.is_charge_limit_reached(),
1959
1967
  )
1960
- n = dedupe.commit(skipped, pushed[: max(0, result.charged_count)])
1968
+ stored = max(0, result.charged_count)
1969
+ n = dedupe.commit(skipped, pushed[:stored])
1970
+ dedupe.note_new_rows(stored)
1961
1971
  charging_manager._note_covered_earlier(event_names, n)
1962
1972
  return ChargeResult(
1963
1973
  chargeable_within_limit=result.chargeable_within_limit,
1964
1974
  charged_count=result.charged_count + n,
1965
- event_charge_limit_reached=result.event_charge_limit_reached,
1975
+ event_charge_limit_reached=result.event_charge_limit_reached or capped,
1966
1976
  covered_counts=result.covered_counts,
1967
1977
  )
1968
1978
 
@@ -17,6 +17,13 @@ The key must identify a row. When the saved rows repeat a key, or this run
17
17
  pushes one key twice, it does not, and the run goes on as before: every row is
18
18
  stored and charged. Nothing is skipped in a first run, in a run that saved
19
19
  nothing yet, after a metamorph, or for pushes that are not charged per row.
20
+
21
+ A resumed generation also starts the Actor's own result count from zero. An
22
+ Actor that declares its run-level result limit (``Actor.set_result_limit(n)``,
23
+ e.g. its ``maxItems`` input) gets it applied across generations: once the rows
24
+ saved before plus the new rows of this generation reach ``n``, further charged
25
+ rows are refused like at the spending limit (not stored, not charged, and the
26
+ push reports the limit), so the run ends with ``n`` results, not more.
20
27
  """
21
28
 
22
29
  from __future__ import annotations
@@ -88,6 +95,13 @@ class ResumeDedupe:
88
95
  self._skipped = 0
89
96
  self._announced = False
90
97
  self._lock = asyncio.Lock()
98
+ # Run-level result limit the Actor declared (None: not declared).
99
+ self._limit: Optional[int] = None
100
+ # Rows the default dataset held when this resumed generation started (None: not a resumed run).
101
+ self._resumed_rows: Optional[int] = None
102
+ # New rows this generation stored through charged pushes.
103
+ self._new_rows = 0
104
+ self._limit_announced = False
91
105
 
92
106
  # Actor API
93
107
  def set_result_key(self, key: Union[str, Sequence[str], None]) -> None:
@@ -100,6 +114,33 @@ class ResumeDedupe:
100
114
  self._saved = set()
101
115
  self._seen = set()
102
116
 
117
+ def set_result_limit(self, limit: Optional[int]) -> None:
118
+ if limit is None:
119
+ self._limit = None
120
+ return
121
+ if isinstance(limit, bool) or not isinstance(limit, int) or limit < 1:
122
+ raise ValueError('result limit must be a positive integer or None')
123
+ self._limit = limit
124
+
125
+ def remaining(self) -> Optional[int]:
126
+ """New rows this resumed generation may still store under the declared limit (None: no cap)."""
127
+ if self._limit is None or self._resumed_rows is None:
128
+ return None
129
+ return max(0, self._limit - self._resumed_rows - self._new_rows)
130
+
131
+ def note_new_rows(self, count: int) -> None:
132
+ if count > 0:
133
+ self._new_rows += count
134
+
135
+ def note_capped(self) -> None:
136
+ if not self._limit_announced:
137
+ self._limit_announced = True
138
+ logger.info(
139
+ 'This run was resumed with %s results saved before; it stops at its limit of %s results',
140
+ self._resumed_rows,
141
+ self._limit,
142
+ )
143
+
103
144
  @property
104
145
  def skipped(self) -> int:
105
146
  return self._skipped
@@ -122,10 +163,10 @@ class ResumeDedupe:
122
163
  if self._state != 'unknown':
123
164
  return
124
165
  self._state = 'off'
125
- if self._fields is None:
126
- return
127
166
  if (os.environ.get('SCRAPELY_RESUME_DEDUPE') or '').strip().lower() in _OFF_VALUES:
128
167
  return
168
+ if self._fields is None and self._limit is None:
169
+ return
129
170
  client = getattr(manager, '_client', None)
130
171
  run_id = getattr(manager, '_actor_run_id', None)
131
172
  from .charging import default_dataset_id_from_env
@@ -143,6 +184,9 @@ class ResumeDedupe:
143
184
  resumed = sum(int(stats.get(k) or 0) for k in ('resurrectCount', 'rebootCount'))
144
185
  if resumed <= 0 or int(stats.get('metamorph') or 0) > 0:
145
186
  return
187
+ self._resumed_rows = item_count
188
+ if self._fields is None:
189
+ return # no result key: only the declared limit applies
146
190
  if item_count > MAX_SAVED_ROWS:
147
191
  logger.info(
148
192
  'This run was resumed with %s saved results, more than the %s the SDK reads to skip '
@@ -183,10 +227,11 @@ class ResumeDedupe:
183
227
  self._state = 'on'
184
228
 
185
229
  async def ensure(self, manager: Any) -> bool:
230
+ """True when this push needs the resumed-run path (saved rows to skip, or a declared limit)."""
186
231
  if self._state == 'unknown':
187
232
  async with self._lock:
188
233
  await self._load(manager)
189
- return self._state == 'on'
234
+ return self._state == 'on' or self.remaining() is not None
190
235
 
191
236
  @property
192
237
  def lock(self) -> asyncio.Lock:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scrapely-python
3
- Version: 0.1.47
3
+ Version: 0.1.48
4
4
  Summary: Scrapely Python SDK - A toolkit for building Actors on the Scrapely platform
5
5
  Author-email: Scrapely <hello@scrape.ly>
6
6
  License-Expression: MIT AND Apache-2.0