feat: Expose `use_state` in `BasicCrawler` by Mantisus · Pull Request #1799 · apify/crawlee-python

Skip to content

Navigation Menu

Sign in

Appearance settings

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

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

Reviewers

@vdusek vdusek vdusek approved these changes

Assignees

@Mantisus Mantisus

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@Mantisus @vdusek @apify-service-account