Complete API reference for the Sentience Python SDK. All functions with parameters, return values, and examples.
Creates a browser instance with the Sentience extension loaded.
api_key (str, optional): Your SentienceAPI subscription keyapi_url (str, optional): Custom API endpointheadless (bool, optional): Run browser in headless mode# Free tier (local processing only)
browser = SentienceBrowser(headless=False)
# Pro tier (server-side processing)
browser = SentienceBrowser(api_key="sk_...", headless=True)
# Context manager (auto-closes)
with SentienceBrowser(api_key="sk_...") as browser:
browser.page.goto("https://example.com")
# Browser automatically closes when doneCaptures the current page state and returns all interactive elements with semantic information.
When api_key is provided, this calls the server-side /v1/snapshot endpoint which consumes 1 credit per call (metered billing).
browser (SentienceBrowser): Browser instancescreenshot (bool or dict, optional): Capture screenshot. True for PNG, or {"format": "jpeg", "quality": 80}limit (int, optional): Maximum elements to return (default: 50 server, all local)filter (dict, optional): Filter options (min_area, allowed_roles, min_z_index)use_api (bool, optional): Force server API (True) or local (False)Snapshot object with: elements, url, viewport, timestamp, screenshot
# Basic snapshot
snap = snapshot(browser)
# With screenshot and limit
snap = snapshot(browser, screenshot=True, limit=200)
# Force local processing (no credits)
snap = snapshot(browser, use_api=False)
# With filtering
snap = snapshot(browser, filter={
"min_area": 100,
"allowed_roles": ["button", "link"]
})id: Unique identifier for clickingrole: Semantic role (button, link, textbox, etc.)text: Visible text contentimportance: AI importance score (0-1000)bbox: Bounding box (x, y, width, height)visual_cues: Visual analysis (is_primary, is_clickable, background_color)in_viewport: Is element visible?is_occluded: Is element covered?Finds the single best matching element (by importance score).
button = find(snap, "role=button text~'Submit'")
if button:
print(f"Found: {button.text} (importance: {button.importance})")Finds all matching elements (returns list).
all_buttons = query(snap, "role=button")
print(f"Found {len(all_buttons)} buttons")=Exact match: "role=button"!=Not equal: "role!=link"~Contains: "text~'sign in'"^=Starts with: "text^='Add'"$=Ends with: "text$='Cart'">/<Comparisons: "importance>500"# Find by role
button = find(snap, "role=button")
# Find by text (contains, case-insensitive)
link = find(snap, "role=link text~'more info'")
# Multiple conditions (AND)
primary_btn = find(snap, "role=button clickable=true importance>800")
# Spatial filtering
top_left = find(snap, "bbox.x<=100 bbox.y<=200")
# Visibility checks
visible_link = find(snap, "role=link visible=true in_viewport=true")Clicks an element by ID. Uses realistic mouse simulation by default.
browser (SentienceBrowser): Browser instanceelement_id (int): Element ID from snapshotuse_mouse (bool): Use Playwright mouse.click() (default) or JS clicktake_snapshot (bool): Capture snapshot after clickActionResult with: success, duration_ms, outcome, url_changed
result = click(browser, button.id)
if result.success:
print(f"Click succeeded: {result.outcome}")
if result.url_changed:
print(f"Navigated to: {browser.page.url}")Clicks at the center of a rectangle. Shows visual feedback (red border).
# Click at specific coordinates
click_rect(browser, {"x": 100, "y": 200, "w": 50, "h": 30})
# Click using element's bounding box
snap = snapshot(browser)
element = find(snap, "role=button")
click_rect(browser, {
"x": element.bbox.x,
"y": element.bbox.y,
"w": element.bbox.width,
"h": element.bbox.height
})
# Without highlight (for headless/CI)
click_rect(browser, {"x": 100, "y": 200, "w": 50, "h": 30}, highlight=False)Types text into an input field.
# Find input and type
snap = snapshot(browser)
email_input = find(snap, "role=textbox")
type_text(browser, email_input.id, "user@example.com")Presses a keyboard key (Enter, Escape, Tab, etc.).
press(browser, "Enter") # Submit form
press(browser, "Escape") # Close modalWaits for an element matching the selector to appear. Auto-optimizes polling interval based on API usage.
browser (SentienceBrowser): Browser instanceselector (str): Query DSL selectortimeout (float): Maximum time to wait in seconds (default: 10.0)interval (float, optional): Polling interval (auto: 0.25s local, 1.5s remote)use_api (bool, optional): Force server API or local extensionWaitResult with: found, element, duration_ms, timeout
# Wait for button to appear
result = wait_for(browser, "role=button text~'Submit'", timeout=5.0)
if result.found:
print(f"Found after {result.duration_ms}ms")
click(browser, result.element.id)
# Wait for clickable element
result = wait_for(browser, "clickable=true", timeout=10.0)
# Wait with custom interval (local processing)
result = wait_for(browser, "role=button", timeout=5.0, interval=0.5, use_api=False)Creates an assertion builder for fluent testing.
.to_exist(timeout=5.0): Assert element exists.to_be_visible(timeout=5.0): Assert element is visible.to_have_text(text, timeout=5.0): Assert element contains text.to_have_count(n, timeout=5.0): Assert query returns N elements# Assertions
expect(browser, "role=button text='Submit'").to_exist(timeout=5.0)
expect(browser, "role=heading").to_be_visible()
expect(browser, "role=button").to_have_text("Submit")
expect(browser, "role=link").to_have_count(10)Extracts page content as text, markdown, or raw HTML.
format (str): Output format - "raw", "text", or "markdown" (default)enhance_markdown (bool): Use markdownify for better conversion# Get markdown content
result = read(browser, format="markdown")
print(result["content"])
# Get plain text
result = read(browser, format="text")
print(result["content"])
# Get raw HTML
result = read(browser, format="raw")
html = result["content"]Captures a screenshot of the current page.
format (str): Image format - "png" or "jpeg"quality (int): JPEG quality (1-100, default: 80)import base64
# Capture PNG screenshot
data_url = screenshot(browser, format="png")
# Save to file
image_data = base64.b64decode(data_url.split(",")[1])
with open("screenshot.png", "wb") as f:
f.write(image_data)
# JPEG with quality control
data_url = screenshot(browser, format="jpeg", quality=85)