Python SDK for Sentience AI Agent Browser Automation
Project description
Sentience Python SDK
📜 License: Apache License 2.0
Python SDK for Sentience AI Agent Browser Automation.
Installation
cd sdk-python
pip install -e .
# Install Playwright browsers (required)
playwright install chromium
Quick Start
from sentience import SentienceBrowser, snapshot, find, click
# Start browser with extension
with SentienceBrowser(headless=False) as browser:
browser.page.goto("https://example.com")
browser.page.wait_for_load_state("networkidle")
# Take snapshot
snap = snapshot(browser)
print(f"Found {len(snap.elements)} elements")
# Find and click a link
link = find(snap, "role=link")
if link:
result = click(browser, link.id)
print(f"Click success: {result.success}")
Features
Day 2: Browser Harness
SentienceBrowser- Launch Playwright with extension loaded- Automatic extension loading and verification
Day 3: Snapshot
snapshot(browser, options)- Capture page state- Pydantic models for type safety
snapshot.save(filepath)- Save to JSON
Content Reading & Screenshots
read(browser, format="text|markdown")- Read page content as text or markdown- Enhanced markdown conversion using
markdownify(better than extension's lightweight conversion) - Supports
enhance_markdown=Trueto use improved conversion
- Enhanced markdown conversion using
screenshot(browser, format="png|jpeg", quality=80)- Capture standalone screenshot- Returns base64-encoded data URL
- Supports PNG and JPEG formats with quality control
Day 4: Query Engine
query(snapshot, selector)- Find elements matching selectorfind(snapshot, selector)- Find single best match- String DSL:
"role=button text~'Sign in'" - 📖 Complete DSL Query Guide - Comprehensive documentation with all operators, fields, and examples
Day 5: Actions
click(browser, element_id)- Click elementtype_text(browser, element_id, text)- Type into elementpress(browser, key)- Press keyboard key
Day 6: Wait & Assert
wait_for(browser, selector, timeout)- Wait for elementexpect(browser, selector)- Assertion helper.to_exist().to_be_visible().to_have_text(text).to_have_count(n)
Content Reading
-
read(browser, format="raw|text|markdown")- Read page content- Default format:
"raw"- Returns HTML suitable for Turndown/markdownify format="raw"- Get cleaned HTMLformat="markdown"- Get high-quality markdown (uses markdownify internally)format="text"- Get plain text
Examples:
from sentience import read # Get raw HTML (default) result = read(browser) html = result["content"] # Get high-quality markdown (uses markdownify automatically) result = read(browser, format="markdown") markdown = result["content"]
See
examples/read_markdown.pyfor complete examples. - Default format:
Examples
See examples/ directory:
hello.py- Extension bridge verificationbasic_agent.py- Basic snapshotquery_demo.py- Query enginewait_and_click.py- Wait and actionsread_markdown.py- Reading page content and converting to markdown
Content Reading Example
from sentience import SentienceBrowser, read
with SentienceBrowser() as browser:
browser.page.goto("https://example.com")
browser.page.wait_for_load_state("networkidle")
# Read as enhanced markdown (better quality)
result = read(browser, format="markdown", enhance_markdown=True)
print(result["content"]) # High-quality markdown
Screenshot Example
from sentience import SentienceBrowser, screenshot
import base64
with SentienceBrowser() as browser:
browser.page.goto("https://example.com")
browser.page.wait_for_load_state("networkidle")
# 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)
Testing
pytest tests/
Documentation
- 📖 Query DSL Guide - Complete guide to the semantic query language
- API Contract:
../spec/SNAPSHOT_V1.md - Type Definitions:
../spec/sdk-types.md
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
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 sentience_python-0.10.3.tar.gz.
File metadata
- Download URL: sentience_python-0.10.3.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19f763646841087e9fee6442324fbc4ac0f2fd561ab9ab3667779d6e26b42b06
|
|
| MD5 |
92f648b56021d5666ec36649aed0afda
|
|
| BLAKE2b-256 |
da009340e9baae4d77daf37037e271c161cd2fa745fcaf544844c2b002c19b9f
|
File details
Details for the file sentience_python-0.10.3-py3-none-any.whl.
File metadata
- Download URL: sentience_python-0.10.3-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b07f7dfd16a2feb270a662bedb854622deb9b170f256d206e8b5d4527b64a8d
|
|
| MD5 |
c26ea6be3f7f58e5b39c412fbb10e567
|
|
| BLAKE2b-256 |
e8bef5dd53aec35bcb5a011afe0bea969c46fdb84e0cc7b0337808b0224d141d
|