Skip to main content

Python SDK for controlling the native agent-browser engine in-process

Project description

pyagentbrowser

Python bindings for the native Rust agent-browser engine, exposing snapshots, element refs, action evidence, browser state, and policy confirmations without shelling out.

The distribution is pyagentbrowser. The import package is agentbrowser.

Install

uv add pyagentbrowser
# or
python -m pip install pyagentbrowser

Requires Python 3.10 through 3.14 and a Chrome/Chromium browser available to agent-browser. See docs/install.md for Chrome and source build notes.

Basic Usage

from agentbrowser import Browser

with Browser(headless=True) as browser:
    browser.page.open("https://example.com")
    page = browser.agent.observe()
    print(page.text)

    browser.find.text("More information").click()

Default Session

For notebooks, scripts, and REPLs:

import agentbrowser as ab

ab.configure(headless=True, allowed_domains="*.example.com")
ab.page.open("example.com")

page = ab.agent.observe()
ab.find.text("More information").click()

print(ab.page.title(), ab.page.url())
ab.close()

The root helpers are namespace proxies over one process-local default Browser. They expose the same synchronous namespaces as Browser, including ab.page, ab.agent, ab.find, ab.capture, ab.tabs, ab.frames, ab.cdp, ab.network, ab.cookies, ab.storage, ab.scripts, and ab.diagnostics.

In notebooks, interrupted runs can leave the process-local default browser in a bad native state. Use ab.reset(force=True) to discard it, or pass force=True to ab.configure(...) when replacing it.

When attaching to a running Chrome, configure connects immediately so tab and state helpers are available before navigation:

browser = ab.configure(cdp_port=9222)
print(browser.tabs.list())

For notebook scratchpads, labelled tabs and XPath locators cover repeatable page exploration without one-off JavaScript glue:

browser.tabs.open("https://example.com", label="scratch")
browser.page.ready(timeout_ms=15_000)

print(browser.find.xpath("//h1").text())
print(browser.find.xpath("//a[contains(., 'More information')]").attribute("href"))

Snapshot Refs And Evidence

from agentbrowser import Browser

with Browser(headless=True) as browser:
    browser.launch()
    browser.page.set_content(
        """
        <label>Email <input aria-label="Email" /></label>
        <label>Password <input aria-label="Password" type="password" /></label>
        <button onclick="document.body.dataset.done = 'yes'">Continue</button>
        <p aria-live="polite"></p>
        <script>
        document.querySelector("button").addEventListener("click", () => {
          document.querySelector("p").textContent = "Signed in"
        })
        </script>
        """
    )

    page = browser.agent.observe()
    page.find(name="Email").fill("ada@example.com")
    page.find(name="Password").fill("correct horse battery staple")

    evidence = page.find(role="button", name="Continue", exact=True).click_and_observe(
        wait_for_text="Signed in"
    )
    print(evidence.after.text)
    print(evidence.diff.text)

Snapshot refs belong to the page state that produced them. After navigation or large DOM changes, take a fresh snapshot. After click_and_observe(), continue from evidence.after.

Optional Extras

uv add "pyagentbrowser[images]"  # Screenshot.image and Screenshot.pil()
uv add "pyagentbrowser[cdp]"     # frame/context evaluation via browser.cdp
shot = browser.capture.screenshot("page.png", full_page=True)
print(shot.path, shot.bytes())

frame = browser.frames.get(selector="#target-frame")
print(frame.evaluate("location.href"))
print(browser.cdp.evaluate("document.title", frame="#target-frame"))

Headless Chromium screenshots hide native scrollbars by default. Construct Browser(hide_scrollbars=False) when scrollbars are part of the artifact.

Tool Boundary

Use pyagentbrowser when Python code needs native agent-browser artifacts in-process. Use browser-use for autonomous agent loops, Playwright for deterministic browser testing, Selenium for WebDriver/Grid infrastructure, and the upstream agent-browser CLI for shell workflows and starting the dashboard UI. See docs/choosing-a-tool.md.

Links

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

pyagentbrowser-0.27.1rc0.tar.gz (646.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyagentbrowser-0.27.1rc0-cp314-cp314-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyagentbrowser-0.27.1rc0-cp313-cp313-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyagentbrowser-0.27.1rc0-cp312-cp312-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyagentbrowser-0.27.1rc0-cp311-cp311-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyagentbrowser-0.27.1rc0-cp310-cp310-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pyagentbrowser-0.27.1rc0.tar.gz.

File metadata

  • Download URL: pyagentbrowser-0.27.1rc0.tar.gz
  • Upload date:
  • Size: 646.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pyagentbrowser-0.27.1rc0.tar.gz
Algorithm Hash digest
SHA256 82481e1bfc1e4ffeb9c20eada5e48d9c2863dffc70c04de6b83d22948643e2e1
MD5 1be77e8ae682de281829e3734ba2fc0b
BLAKE2b-256 16573938ee57ce01bd3dba214e55bdd8b49007ca524bbe337a4d4ed14b589a76

See more details on using hashes here.

File details

Details for the file pyagentbrowser-0.27.1rc0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyagentbrowser-0.27.1rc0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ed0a35e0cbbfedb82dd3606923471824818cdd395d0c8f06e475a63fefb1b75e
MD5 6353181d02c73130a2e15208d3ec3f20
BLAKE2b-256 7adf8646d2eed5e2af5282b00301bb28cf674d754376a84d857d3412b321a7d6

See more details on using hashes here.

File details

Details for the file pyagentbrowser-0.27.1rc0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyagentbrowser-0.27.1rc0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb1ef3e37bafa7c8d269ea835b057fc423e0c99c4722eacbee3d3e61d0c6e4f9
MD5 f35c4b66c4a62fc0cde13f79ee202190
BLAKE2b-256 48193d1dbf2e9eca50cd99499f759a0e39fc5795c39a2d41b20f4341a0e958f8

See more details on using hashes here.

File details

Details for the file pyagentbrowser-0.27.1rc0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyagentbrowser-0.27.1rc0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20f3f6aca768b6f94faeaaf4b2411db0ccdf5d44c66f2ca828d0ed36152b2da4
MD5 17067def9c78711bcf429cc7ff54c147
BLAKE2b-256 2f6e836ad9b235920990d274bcd2bd14fb929fbdb8330467f81052421dfc0fe6

See more details on using hashes here.

File details

Details for the file pyagentbrowser-0.27.1rc0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyagentbrowser-0.27.1rc0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4a76ca30fde3befcde064c80e5a4c5aa7b2a5861aefd72167852d136f6292d30
MD5 89affa14ab1cec6457b9eff5c9c73216
BLAKE2b-256 d5c2a405b95bf4918e73a7251a06194829c4c2e6c6f141ba9b477c4dccaa19cf

See more details on using hashes here.

File details

Details for the file pyagentbrowser-0.27.1rc0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyagentbrowser-0.27.1rc0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e5991851f213d6cbb37f08391f8c31109a356d25115b783488693549f8fddb2
MD5 a019ce8052959fae08598521c7afe03c
BLAKE2b-256 fa44c06e996fe0c91acbba1c668cb88c108eba94f54637459900cfe56455e662

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page