Skip to content

Consider adding Actor.use_state #735

Closed

Description

@Pijukatel

Activity

  1. added
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Jan 13, 2026
  2. B4nan commented on Jan 15, 2026

    @B4nan
    Member

    IMO nothing to consider here, this is missing, it should be here, let's add it asap so we don't block that docs PR.

  3. B4nan commented on Jan 15, 2026

    @B4nan
    Member

    @Mantisus can you look into this please?

  4. Pijukatel commented on Jan 15, 2026

    @Pijukatel
    ContributorAuthor

    It has to take this into account apify/crawlee-python#1669

    Given the discussion here apify/crawlee-python#1669 (comment)
    the Actor.use_state should access the same state as the first default crawler. So key CRAWLEE_STATE_0 (depends on the implementation there)

  5. B4nan commented on Jan 16, 2026

    @B4nan
    Member

    Huh, I should have checked this before, but we apparently use different default state keys in the SDK and in crawlee, so what I was highlighting here (mismatch between the SDK and context version) is not really a problem.

    https://github.com/apify/crawlee/blob/master/packages/basic-crawler/src/internals/basic-crawler.ts#L491
    https://github.com/apify/apify-sdk-js/blob/master/packages/apify/src/actor.ts#L1593

    Now I'm not so sure if we should share the default key, I saw it as a nasty BC, but if it didn't work like that before, I guess we should keep the current JS behavior, so keep different default state keys for SDK and BasicCrawler.

    Thoughts @barjin @janbuchar @Pijukatel?

  6. barjin commented on Jan 16, 2026

    @barjin
    Member

    Given we want to split the Crawlee state to have a separate one for each Crawler instance, it doesn't really make sense to me to add SDK support on top of this.

    JS and Python SDK sharing the same state (key) on Actor.useState / Actor.use_state sounds nice and IMO sells the idea it's actually the "Actor's state", not some random KVS value.

  7. B4nan commented on Jan 16, 2026

    @B4nan
    Member

    it doesn't really make sense to me to add SDK support on top of this.

    Care to elaborate? It sounds like you don't want to have Actor.useState at all, but I am sure that's not the case?


    Right now I am inclined to keep the JS behavior, with a fixed SDK state key, and do the same in Python, so Actor.useState in JS uses the same state key as Actor.use_state in Python.

  8. Mantisus commented on Jan 16, 2026

    @Mantisus
    Collaborator

    I favor using different base keys for use_state in Crawlee and SDK. And accordingly, using the same key APIFY_GLOBAL_STATE in Python and JS.

    These are different entities, and as a user, I would expect the data in use_state to be associated only with a specific entity.

  9. added a commit that references this issue on Feb 19, 2026
    8a78b6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request.t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions