Type-safe Pydantic wrapper around Vercel's agent-browser CLI
Project description
agent-browser
A type-safe Python wrapper around Vercel's
agent-browser CLI.
Install
Install agent-browser and its browser once:
npm install -g agent-browser
agent-browser install
Then install this package:
pip install vercel-agent-browser
Python 3.10+ and Pydantic 2 are supported.
Quick start
from agent_browser import AgentBrowser, Direction, LoadState
browser = AgentBrowser()
browser.open("https://example.com")
browser.wait_for_load(LoadState.NETWORK_IDLE)
snapshot = browser.snapshot(interactive=True).data
print(snapshot.snapshot)
print(snapshot.refs["e1"].role)
browser.click("@e1")
browser.scroll(Direction.DOWN, 500)
title: str = browser.get_title().data.value
url: str = browser.get_url().data.value
browser.close()
The browser remains stateful between calls because agent-browser manages a
persistent daemon. A context manager closes the current session on exit:
from agent_browser import AgentBrowser, ClientConfig, GlobalOptions
config = ClientConfig(
timeout=60,
options=GlobalOptions(
session="research",
headed=True,
allowed_domains=("example.com", "*.example.com"),
),
)
with AgentBrowser(config) as browser:
browser.open("https://example.com")
print(browser.read().data.value)
Typed results
Every JSON-mode call returns CommandResult[T]. Its data is a Pydantic model
specific to that operation, while its other fields preserve useful process
metadata:
result = browser.get_box("@e1")
print(result.data.x, result.data.y)
print(result.command)
print(result.stderr)
print(result.duration_seconds)
Common typed payloads include:
SnapshotDataandSnapshotRefStringData,BooleanData, andIntegerDataBoundingBoxandPathDataJsonDatafor successful commands whose payload is command-specific
Pydantic validates both outgoing configuration and incoming structured data.
Errors
CLI failures raise AgentBrowserCommandError. The exception retains the
subprocess exit code, arguments, stdout/stderr, warning, and normalized Pydantic
error model:
from agent_browser import AgentBrowserCommandError
try:
browser.click("@missing")
except AgentBrowserCommandError as exc:
print(exc.error.message)
print(exc.error.code)
print(exc.returncode)
The package also distinguishes an unavailable executable, subprocess timeout,
and invalid CLI response with AgentBrowserNotFoundError,
AgentBrowserTimeoutError, and AgentBrowserResponseError.
Custom and future commands
Use run() for CLI commands not yet represented by a convenience method. Pass
an argument sequence—not a shell string:
result = browser.run(["console", "--clear"])
print(result.data.root)
You can supply your own Pydantic model for a command's data payload:
from pydantic import BaseModel
class StreamStatus(BaseModel):
enabled: bool
port: int | None = None
status = browser.run(["stream", "status"], StreamStatus).data
For compact human-readable CLI output, use run_text():
text = browser.run_text(["snapshot", "-i"]).stdout
run() always requests JSON output and parses the standard
{"success": ..., "data": ...} envelope. It also accepts raw JSON payloads for
commands such as batch that emit an array directly.
Executable and environment configuration
If agent-browser is not on PATH, point to it explicitly:
from pathlib import Path
from agent_browser import AgentBrowser, ClientConfig
browser = AgentBrowser(
ClientConfig(
executable=Path("/opt/homebrew/bin/agent-browser"),
env={"AGENT_BROWSER_ENCRYPTION_KEY": "..."},
)
)
Environment values are merged onto the current process environment. Arguments
are passed directly to subprocess.run(..., shell=False); no selector, URL,
JavaScript, password, or other input is interpreted by a shell.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vercel_agent_browser-0.1.1.tar.gz.
File metadata
- Download URL: vercel_agent_browser-0.1.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
003da6a5687da9c715c16099c213da3d89b2e65def7105528ad22f9bd1979435
|
|
| MD5 |
3c7a238eacc74eda3bdc9a8b183bc816
|
|
| BLAKE2b-256 |
719db56f3daa831cf561da4e5f42475a97dfacf5d5b2eef6c1190d6b828c368d
|
File details
Details for the file vercel_agent_browser-0.1.1-py3-none-any.whl.
File metadata
- Download URL: vercel_agent_browser-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97c2c131d8ee75d4f3fd9883cd7dbee9f36d79bb3a79849ae23c4a65330cee3b
|
|
| MD5 |
633a6ee10f33b12f253051badffbfe27
|
|
| BLAKE2b-256 |
9ba8642ecb40485e8ed25a2dac7c193fefccb8791074c770e5103c0fbeb09b42
|