Skip to content

API Reference parrot_tools.scraping.session_manager

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.scraping.session_manager

View source

SessionManager — BrowserContext lifecycle per session label.

Owns a single Playwright Browser and creates/caches/closes one BrowserContext per session label. Sessions sharing a label share authentication state (cookies, storage); distinct labels are isolated.

Contexts are created lazily on first use and closed deterministically once the last :class:FlowNode referencing a session has completed (:meth:close_if_last), with :meth:close_all as a cleanup safety net (FEAT-222, Module 7).

Alias FlowNode

Re-exported from parrot_tools.scraping.flow_models.FlowNode.

Class SessionManager

Manage Playwright BrowserContexts keyed by session label.

Parameter Type Default Description
browser Any A live Playwright Browser instance.
default_context_kwargs Optional[Dict[str, Any]] None Keyword arguments applied to every context (viewport, locale, storage_state, proxy, …).
session_configs Optional[Dict[str, Dict[str, Any]]] None Optional per-session overrides merged on top of default_context_kwargs (e.g. a distinct storage_state for an authenticated session).

Method SessionManager.get_context

Return the BrowserContext for session, creating it lazily.

The first call for a label creates the context (merging default_context_kwargs with any per-session override); subsequent calls return the cached context.

get_context(session: str) -> Any

Parameter Type Default Description
session str

Returns: Any

Method SessionManager.new_page

Create and return a new Page within session's context.

new_page(session: str) -> Any

Parameter Type Default Description
session str

Returns: Any

Method SessionManager.precompute_last_use

Record the last node id that uses each session, in topo order.

Iterating in execution order means the final assignment per session is its last-used node — the point at which the context can be closed.

precompute_last_use(topo_order: List[FlowNode]) -> Dict[str, str]

Parameter Type Default Description
topo_order List[FlowNode] Nodes in execution (topological) order.

Returns: Dict[str, str] — Mapping of session -> last node id.

Method SessionManager.close_if_last

Close session's context if node_id was its last user.

No-op when the session has more nodes pending or is unknown.

close_if_last(session: str, node_id: str) -> None

Parameter Type Default Description
session str
node_id str

Method SessionManager.close_all

Close every remaining context (cleanup safety net).

close_all() -> None

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally