Skip to main content

Official Python SDK for the Browserbeam API — browser automation built for AI agents

Project description

Browserbeam Python SDK

Official Python SDK for the Browserbeam API — browser automation built for AI agents.

Installation

pip install browserbeam

Quick Start

from browserbeam import Browserbeam

client = Browserbeam(api_key="sk_live_...")

session = client.sessions.create(url="https://example.com")

# Page state is available immediately
print(session.page.title)
print(session.page.interactive_elements)

# Interact with the page
session.click(ref="e1")

# Extract with CSS, AI, and JS selectors combined
result = session.extract(
    products=[{
        "_parent": ".product-card",
        "_limit": 3,
        "name": "h2 >> text",                          # CSS selector
        "price": ".price >> text",                     # CSS selector
        "url": "a >> href",                            # CSS attribute
        "rating": "ai >> the star rating out of 5",    # AI selector
        "in_stock": "js >> el.querySelector('.stock')?.textContent.includes('In stock')",  # JS
    }]
)
print(result.extraction)

# Close when done
session.close()

Async Support

from browserbeam import AsyncBrowserbeam

client = AsyncBrowserbeam(api_key="sk_live_...")

session = await client.sessions.create(url="https://example.com")
await session.click(ref="e1")
result = await session.extract(title="h1 >> text")
print(result.extraction)
await session.close()

Configuration

client = Browserbeam(
    api_key="sk_live_...",       # or set BROWSERBEAM_API_KEY env var
    base_url="https://api.browserbeam.com",  # default
    timeout=120.0,               # request timeout in seconds
)

Session Options

session = client.sessions.create(
    url="https://example.com",
    viewport={"width": 1280, "height": 720},
    user_agent="Mozilla/5.0 ...",  # omit for automatic rotation
    locale="en-US",
    timezone="America/New_York",
    block_resources=["image", "font"],
    auto_dismiss_blockers=True,
    timeout=300,
)

Proxies

All sessions use a datacenter proxy by default (country auto-detected from the URL's TLD). No configuration needed. To customize:

# Use a residential proxy for a specific country
session = client.sessions.create(
    url="https://example.com",
    proxy={"kind": "residential", "country": "us"},
)

# Or bring your own proxy (overrides managed proxy)
session = client.sessions.create(
    url="https://example.com",
    proxy="http://user:pass@proxy:8080",
)

Available Methods

Method Description
session.goto(url) Navigate to a URL
session.observe() Get page state as markdown. Supports mode="full" for all sections.
session.click(ref=) Click an element by ref, text, or label
session.fill(value, ref=) Fill an input field
session.type(value, label=) Type text character by character
session.select(value, label=) Select a dropdown option
session.check(label=) Toggle a checkbox
session.scroll(to="bottom") Scroll the page
session.scroll_collect() Scroll and collect all content
session.screenshot() Take a screenshot
session.extract(**schema) Extract structured data
session.fill_form(fields, submit=) Fill and submit a form
session.wait(ms=) Wait for time, selector, or text
session.pdf() Generate a PDF
session.execute_js(code) Run JavaScript
session.close() Close the session

Page Map & Full Mode

The first observe call automatically includes a page.map — a lightweight structural outline of the page's landmark regions (header, nav, main, aside, footer) with CSS selectors and descriptive hints. Use it to discover what content is available outside the main area.

res = session.observe()
for entry in res.page.map:
    print(f"{entry.section}: {entry.hint}")
# nav: Home · Docs · Pricing
# main: Getting started with Browserbeam...
# aside: Related posts · Popular tags

To re-request the map on subsequent calls:

session.observe(include_page_map=True)

When you need content from all page sections (sidebars, footer links, nav items), use mode="full". The response markdown is organized by region headers:

full = session.observe(mode="full", max_text_length=20_000)
print(full.page.markdown.content)
# ## [nav]
# Home · Docs · Pricing
# ## [main]
# ...article content...
# ## [aside]
# Related posts · ...

Both parameters work identically with AsyncSession.

Session Management

# List active sessions
sessions = client.sessions.list(status="active")

# Get session info
info = client.sessions.get("ses_abc123")

# Destroy a session
client.sessions.destroy("ses_abc123")

Error Handling

from browserbeam import Browserbeam, RateLimitError, SessionNotFoundError

client = Browserbeam()

try:
    session = client.sessions.create(url="https://example.com")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except SessionNotFoundError as e:
    print(f"Session not found: {e.message}")

Documentation

Full API documentation at browserbeam.com/docs.

License

MIT

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

browserbeam-0.4.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

browserbeam-0.4.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file browserbeam-0.4.0.tar.gz.

File metadata

  • Download URL: browserbeam-0.4.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for browserbeam-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b056ab41af6d754d659a162286874d0f374661ab9a534e71ef62c0d379554bd9
MD5 7754dada5e982d6e9382d3e99df26c88
BLAKE2b-256 7e9c7e90ac4bcf7e5d5e36c53e6e7a8496b358a0ae6a577f103d33c3fbf09ad8

See more details on using hashes here.

File details

Details for the file browserbeam-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: browserbeam-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for browserbeam-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d36919dccbdc397ff20e5b8f2a2bb62c70a5012268a62de96fbf56b461e36a64
MD5 31be9ae4011fc578dde620e3528dedc7
BLAKE2b-256 466b66cf453c64aa01b277611cfb997555b6716516a5bb748722292d1c4ec9bf

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