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
Release history Release notifications | RSS feed
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 browserfabric-1.0.1.tar.gz.
File metadata
- Download URL: browserfabric-1.0.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cd3ae6a8d84955c1676c9054bef2483322170462f1e014d39368161a5107754
|
|
| MD5 |
ce879b655197ae94f75802c6e4267686
|
|
| BLAKE2b-256 |
bbc4630b0588f17e56872b42858d11cc5689957cfbf4b4997cbe65a6de8e1578
|
File details
Details for the file browserfabric-1.0.1-py3-none-any.whl.
File metadata
- Download URL: browserfabric-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d36533641dce13ab840100095fcb8d5d312781d65a12b8faa63a17690af449f8
|
|
| MD5 |
7796ca14f0c5514190cd8e6f9d207fae
|
|
| BLAKE2b-256 |
479701cfe61117a99e47c7bbc94d068b014d1f72af697640f0a83eaa56d7e82a
|