Skip to content

API Reference parrot_tools.scraping.driver_context

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

parrot_tools.scraping.driver_context

View source

Driver Context Manager — manages browser driver lifecycle.

Provides a plugin-style DriverRegistry for registering driver factories and an async context manager driver_context() that handles session-based (persistent) and per-operation (fresh) driver modes.

Alias AbstractDriver

Re-exported from parrot_tools.scraping.drivers.abstract.AbstractDriver.

Alias DriverConfig

Re-exported from parrot_tools.scraping.toolkit_models.DriverConfig.

Class DriverRegistry

Plugin-style registry for browser driver factories.

Driver factories are callables that accept a DriverConfig and return a setup object with an async def get_driver() method.

Usage::

DriverRegistry.register("selenium", my_selenium_factory)
factory = DriverRegistry.get("selenium")

Method DriverRegistry.register

Register a driver factory for a given driver type.

register(driver_type: str, factory: Callable[[DriverConfig], Any]) -> None

Parameter Type Default Description
driver_type str Identifier for the driver (e.g. "selenium", "playwright").
factory Callable[[DriverConfig], Any] Callable that accepts a DriverConfig and returns a setup object with async def get_driver().

Method DriverRegistry.unregister

Remove a registered driver factory.

unregister(driver_type: str) -> None

Parameter Type Default Description
driver_type str Identifier to remove.

Method DriverRegistry.get

Get a registered driver factory.

get(driver_type: str) -> Callable[[DriverConfig], Any]

Parameter Type Default Description
driver_type str Identifier of the driver factory.

Returns: Callable[[DriverConfig], Any] — The registered factory callable.

Raises:

  • ValueError — If the driver type is not registered.

Method DriverRegistry.list_registered

Return list of registered driver type names.

list_registered() -> list[str]

Returns: list[str] — List of driver type identifiers.

Function driver_context

Async context manager that yields a browser driver.

In session mode (session_driver provided), the existing driver is yielded without lifecycle management. In fresh mode, a new driver is created from the registry, yielded, and quit on exit.

driver_context(config: DriverConfig, session_driver: Optional[Any] = None) -> AsyncIterator[Any]

Parameter Type Default Description
config DriverConfig Driver configuration.
session_driver Optional[Any] None Existing driver to reuse (session mode). If None, a fresh driver is created and destroyed.

Returns: AsyncIterator[Any]

Attribute logger

Alias resolve_browser_binary

Re-exported from parrot_tools.scraping.toolkit_models.resolve_browser_binary.

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