@@ -213,6 +213,10 @@ class _BasicCrawlerOptions(TypedDict):
213213 """Allows overriding the default status message. The default status message is provided in the parameters.
214214 Returning `None` suppresses the status message."""
215215
216+ id : NotRequired [int ]
217+ """Id of the crawler used for state tracking. You can use same explicit id to share state between two crawlers.
218+ By default, each crawler will use own state."""
219+
216220
217221class _BasicCrawlerOptionsGeneric (TypedDict , Generic [TCrawlingContext , TStatisticsState ]):
218222 """Generic options the `BasicCrawler` constructor."""
@@ -298,7 +302,7 @@ def __init__(
298302 status_message_logging_interval : timedelta = timedelta (seconds = 10 ),
299303 status_message_callback : Callable [[StatisticsState , StatisticsState | None , str ], Awaitable [str | None ]]
300304 | None = None ,
301- crawler_id : int | None = None ,
305+ id : int | None = None ,
302306 _context_pipeline : ContextPipeline [TCrawlingContext ] | None = None ,
303307 _additional_context_managers : Sequence [AbstractAsyncContextManager ] | None = None ,
304308 _logger : logging .Logger | None = None ,
@@ -351,21 +355,20 @@ def __init__(
351355 status_message_logging_interval: Interval for logging the crawler status messages.
352356 status_message_callback: Allows overriding the default status message. The default status message is
353357 provided in the parameters. Returning `None` suppresses the status message.
354- crawler_id : Id of the crawler used for state and statistics tracking. You can use same explicit id to share
355- state and statistics between two crawlers. By default, each crawler will use own state and statistics .
358+ id : Id of the crawler used for state tracking. You can use same explicit id to share state and between two
359+ crawlers. By default, each crawler will use own state.
356360 _context_pipeline: Enables extending the request lifecycle and modifying the crawling context.
357361 Intended for use by subclasses rather than direct instantiation of `BasicCrawler`.
358362 _additional_context_managers: Additional context managers used throughout the crawler lifecycle.
359363 Intended for use by subclasses rather than direct instantiation of `BasicCrawler`.
360364 _logger: A logger instance, typically provided by a subclass, for consistent logging labels.
361365 Intended for use by subclasses rather than direct instantiation of `BasicCrawler`.
362366 """
363- if crawler_id is None :
364- # This could look into set of already used ids, but lets not overengineer this.
365- self .id = BasicCrawler .__next_id
367+ if id is None :
368+ self ._id = BasicCrawler .__next_id
366369 BasicCrawler .__next_id += 1
367370 else :
368- self .id = crawler_id
371+ self ._id = id
369372
370373 implicit_event_manager_with_explicit_config = False
371374 if not configuration :
@@ -842,7 +845,7 @@ async def _use_state(
842845 default_value : dict [str , JsonSerializable ] | None = None ,
843846 ) -> dict [str , JsonSerializable ]:
844847 kvs = await self .get_key_value_store ()
845- return await kvs .get_auto_saved_value (f'{ self ._CRAWLEE_STATE_KEY } _{ self .id } ' , default_value )
848+ return await kvs .get_auto_saved_value (f'{ self ._CRAWLEE_STATE_KEY } _{ self ._id } ' , default_value )
846849
847850 async def _save_crawler_state (self ) -> None :
848851 store = await self .get_key_value_store ()
0 commit comments