pai-browser-use
⚠️ Early Stage Project This project is currently in early development. APIs and features may change. We welcome your feedback and contributions!
- 🐛 Found a bug? Submit an issue
- 💡 Have ideas or suggestions? Join the discussion
- 🤝 Want to contribute? Check out our Contributing Guide
Pydantic AI Toolsets for browser automation using Chrome DevTools Protocol (CDP).
Inspired by browser-use, designed for Pydantic AI agents.
Features
- Browser Automation Tools: Navigation, state inspection, interaction, and element queries
- Multi-Modal Screenshots: Automatic image splitting for long pages with ToolReturn support
- Type-Safe CDP Integration: Direct access to cdp-use API with full type hints
- Fully Tested: Comprehensive test suite with Docker-based Chrome container
Installation
Use pip:
pip install pai-browser-use
Or use uv:
uv add pai-browser-use
Quick Start
Prerequisites
Start a Chrome instance with CDP enabled:
# Option 1: Using Chrome directly
google-chrome --remote-debugging-port=9222
# Option 2: Using Docker container
./dev/start-browser-container.sh
Basic Usage
import os
from pydantic_ai import Agent
from pai_browser_use import BrowserUseToolset
agent = Agent(
model="anthropic:claude-sonnet-4-5",
system_prompt="You are a helpful assistant.",
toolsets=[
BrowserUseToolset(cdp_url="http://localhost:9222/json/version"),
],
)
result = await agent.run("Find the number of stars of the wh1isper/pai-browser-use repo")
print(result.output)
See examples/agent.py for a complete example.
Configuration
BrowserUseToolset supports configuration via environment variables. See .env.example for all available options.
You can override environment variables by passing explicit parameters:
toolset = BrowserUseToolset(
cdp_url="http://localhost:9222/json/version",
max_retries=10, # Override PAI_BROWSER_USE_MAX_RETRIES
prefix="custom_browser", # Override PAI_BROWSER_USE_PREFIX
always_use_new_page=True, # Override PAI_BROWSER_USE_ALWAYS_USE_NEW_PAGE
auto_cleanup_page=False, # Override PAI_BROWSER_USE_AUTO_CLEANUP_PAGE
)
Priority: Explicit parameters > Environment variables > Defaults
Page Management
always_use_new_page: WhenTrue, creates a new browser page instead of reusing existing ones. Defaults toFalse.auto_cleanup_page: WhenTrue, automatically closes created pages on context exit. Defaults toFalse.
Use Case Examples:
# Default behavior: Reuse existing page, no cleanup needed
toolset = BrowserUseToolset(cdp_url="http://localhost:9222/json/version")
# Create new page but keep it open for debugging/inspection (default when using always_use_new_page)
toolset = BrowserUseToolset(
cdp_url="http://localhost:9222/json/version",
always_use_new_page=True, # Create fresh page
# auto_cleanup_page defaults to False - page remains open
)
# Create new page and automatically clean up (for production/batch processing)
toolset = BrowserUseToolset(
cdp_url="http://localhost:9222/json/version",
always_use_new_page=True, # Create fresh page
auto_cleanup_page=True, # Clean up after execution
)
Logging
Use PAI_BROWSER_USE_LOG_LEVEL environment variable to set logging level. The default is ERROR. Set to DEBUG for more verbose logging.
Development
# Install dependencies
uv sync
# Run tests
pytest tests/
# Run example
python examples/agent.py
# Try DEBUG logging demo (shows extracted content)
PAI_BROWSER_USE_LOG_LEVEL=DEBUG python demo_debug_logging.py
License
BSD 3-Clause License - see LICENSE for details.
Metadata
Release files for pai-browser-use 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pai_browser_use-0.3.0.tar.gz | 180.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pai_browser_use-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 213.6 kB
Release files / pai_browser_use-0.3.0.tar.gz
| Download URL | pai_browser_use-0.3.0.tar.gz |
|---|---|
| Size | 180.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95e94cc36fb04b6b97db7cd6ea661bd47f82aa17b5962b3dbcfb142ced96801b
|
|
BLAKE2b-256 checksum How to use checksums |
d163e8fcabc0516cfc2371a1868c3ff550bb3d3b0d1fbdc0cb180c805d88b78a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.2
|
Release files / pai_browser_use-0.3.0-py3-none-any.whl
| Download URL | pai_browser_use-0.3.0-py3-none-any.whl |
|---|---|
| Size | 33.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72397336e46433c8c3a720d123b78599d42bb69b96e712a8c50828a0f8bfd8d0
|
|
BLAKE2b-256 checksum How to use checksums |
470179d4f5635e5979d71bafbee7fc087b264783d055425e88250719677e8423
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.2
|
Security for pai-browser-use 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.