Skip to main content

BrowserFabric Python SDK - Client library for BrowserFabric browser automation API

Project description

BrowserFabric

Python SDK for BrowserFabric — cloud browser automation API with persistent sessions and CDP access.

Install

pip install browserfabric

Quick Start

import browserfabric
import asyncio

async def main():
    async with browserfabric.browser() as session:
        await session.navigate("https://example.com")
        await session.click("a")
        await session.screenshot("result.png")

asyncio.run(main())

Authentication

Set your API key as an environment variable or pass it directly:

# Via environment variable
export BROWSERFABRIC_API_KEY=bf_your_key_here

# Or pass directly
async with browserfabric.browser(api_key="bf_...") as session:
    ...

Persistent Sessions

Save and restore browser state (cookies, localStorage) across sessions:

# Save state on close
async with browserfabric.browser(persist=True) as session:
    await session.navigate("https://app.example.com/login")
    await session.type("#email", "user@example.com")
    await session.type("#password", "secret")
    await session.click("#submit")
    ctx = await session.save_context("my-app-login")

# Restore later
async with browserfabric.browser(context_id=ctx["context_id"]) as session:
    # Already logged in
    await session.navigate("https://app.example.com/dashboard")

CDP WebSocket

Connect with Playwright directly for full browser control:

from playwright.async_api import async_playwright

# Get the CDP WebSocket URL from session info
info = await session.session_info()
ws_url = info["ws_url"]

# Connect with Playwright
pw = await async_playwright().start()
browser = await pw.chromium.connect_over_cdp(ws_url)
page = browser.contexts[0].pages[0]
await page.goto("https://example.com")

Available Methods

Method Description
navigate(url) Go to a URL
click(selector) Click an element
type(selector, text) Type into an input
find(selector) Find elements
screenshot(filename) Take a screenshot
observe() Get interactive DOM elements
snapshot() Get accessibility tree
page_info() Get page URL and title
session_info() Get session metadata + CDP URL
save_context(name) Save browser state
close() Close the session

Self-Hosted

Point to your own BrowserFabric instance:

async with browserfabric.browser(base_url="http://your-server:9000") as session:
    ...

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

browserfabric-1.0.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

browserfabric-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file browserfabric-1.0.0.tar.gz.

File metadata

  • Download URL: browserfabric-1.0.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for browserfabric-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1a89489ea487249973ffac98b43cb7c1bfa99d92aa888c73ddc05c4beed57fd5
MD5 bee4984ccc2bf9669eb7e27284189fd0
BLAKE2b-256 9d00334026c2efa00e20c3e40030dfff7cf1f00af3e6cd2cb60fcbbcb0ab62c2

See more details on using hashes here.

File details

Details for the file browserfabric-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: browserfabric-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for browserfabric-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24086662ffd7bbed8d94eba521efe62b95159acb64ada2f5fe28c994d013d0d7
MD5 12210f2cbbec8417c817760a4c555bd5
BLAKE2b-256 5df889e76a99d0aaa7bb6b974791a9e5ed9bcd623101cfd165b88fa1d7f817e6

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