Skip to content

feat: Expose use_state in BasicCrawler#1799

Merged
vdusek merged 1 commit intoapify:masterfrom
Mantisus:expose-use-state
Mar 19, 2026
Merged

feat: Expose use_state in BasicCrawler#1799
vdusek merged 1 commit intoapify:masterfrom
Mantisus:expose-use-state

Conversation

@Mantisus
Copy link
Collaborator

Description

  • Expose use_state in BasicCrawler. This can be useful for passing data initialized during crawler setup into a handler.

Example:

async def main():
    crawler = BasicCrawler()
    await crawler.use_state({'state': 'init'})

    @crawler.router.default_handler
    async def handler(context):
        data = await context.use_state()

        context.log.info(f'State: {data["state"]}')

    await crawler.run(["https://www.example.com/"])


if __name__ == '__main__':
    asyncio.run(main())

@Mantisus Mantisus self-assigned this Mar 19, 2026
Copy link
Collaborator

@vdusek vdusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, all other Crawlers have it exposed, am I correct?

@Mantisus
Copy link
Collaborator Author

all other Crawlers have it exposed, am I correct?

After that PR method will be exposed in all crawlers

@vdusek vdusek merged commit d121873 into apify:master Mar 19, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants