Skip to content

feat(crawlers)!: Introduce protocols for SessionPool and Session - #2579

Draft
Mantisus wants to merge 2 commits into
apify:v2from
Mantisus:session-pool-protocol
Draft

Mantisus wants to merge 2 commits into
apify:v2from
Mantisus:session-pool-protocol

Conversation

@Mantisus

@Mantisus Mantisus commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Description

The session_pool option of the crawlers takes any session pool implementation: an async context manager with an active property and a get_session(session_id=None) method, whose sessions have id, cookies, proxy_info, is_usable, mark_good(), mark_bad() and retire(). context.session and the session argument of the HTTP clients are typed by these members, so other Session attributes, such as user_data, need a cast.

robots.txt is fetched through the proxy of a session from the pool, so a proxy from create_session_settings or create_session_function applies to it too. The crawler enters its own pool when it checks robots.txt before the run. With a passed pool that isn't entered, add_requests() raises once it has to fetch a robots.txt file.

Issues

Testing

  • Unit tests for a custom session pool, the bound-session stand-in and robots.txt fetched through a session.

✍️ Drafted by Claude Code

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Dec 3, 2026
@Mantisus
Mantisus marked this pull request as draft December 3, 2026 15:12
@Mantisus Mantisus self-assigned this Dec 3, 2026
@Mantisus Mantisus changed the title feat(crawlers)!: Accept any session pool implementation feat(crawlers)!: Introduce protocols for SessionPool and Session Dec 3, 2026
@Mantisus
Mantisus force-pushed the session-pool-protocol branch from 0e5ef92 to 38312c7 Compare December 3, 2026 15:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant