|
| 1 | +# Sentience Python SDK |
| 2 | + |
| 3 | +**Status**: ✅ Week 1 Complete |
| 4 | + |
| 5 | +Python SDK for Sentience AI Agent Browser Automation. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +cd sdk-python |
| 11 | +pip install -e . |
| 12 | +``` |
| 13 | + |
| 14 | +## Quick Start |
| 15 | + |
| 16 | +```python |
| 17 | +from sentience import SentienceBrowser, snapshot, find, click |
| 18 | + |
| 19 | +# Start browser with extension |
| 20 | +with SentienceBrowser(headless=False) as browser: |
| 21 | + browser.page.goto("https://example.com") |
| 22 | + browser.page.wait_for_load_state("networkidle") |
| 23 | + |
| 24 | + # Take snapshot |
| 25 | + snap = snapshot(browser) |
| 26 | + print(f"Found {len(snap.elements)} elements") |
| 27 | + |
| 28 | + # Find and click a link |
| 29 | + link = find(snap, "role=link") |
| 30 | + if link: |
| 31 | + result = click(browser, link.id) |
| 32 | + print(f"Click success: {result.success}") |
| 33 | +``` |
| 34 | + |
| 35 | +## Features |
| 36 | + |
| 37 | +### Day 2: Browser Harness |
| 38 | +- `SentienceBrowser` - Launch Playwright with extension loaded |
| 39 | +- Automatic extension loading and verification |
| 40 | + |
| 41 | +### Day 3: Snapshot |
| 42 | +- `snapshot(browser, options)` - Capture page state |
| 43 | +- Pydantic models for type safety |
| 44 | +- `snapshot.save(filepath)` - Save to JSON |
| 45 | + |
| 46 | +### Day 4: Query Engine |
| 47 | +- `query(snapshot, selector)` - Find elements matching selector |
| 48 | +- `find(snapshot, selector)` - Find single best match |
| 49 | +- String DSL: `"role=button text~'Sign in'"` |
| 50 | + |
| 51 | +### Day 5: Actions |
| 52 | +- `click(browser, element_id)` - Click element |
| 53 | +- `type_text(browser, element_id, text)` - Type into element |
| 54 | +- `press(browser, key)` - Press keyboard key |
| 55 | + |
| 56 | +### Day 6: Wait & Assert |
| 57 | +- `wait_for(browser, selector, timeout)` - Wait for element |
| 58 | +- `expect(browser, selector)` - Assertion helper |
| 59 | + - `.to_exist()` |
| 60 | + - `.to_be_visible()` |
| 61 | + - `.to_have_text(text)` |
| 62 | + - `.to_have_count(n)` |
| 63 | + |
| 64 | +## Examples |
| 65 | + |
| 66 | +See `examples/` directory: |
| 67 | +- `hello.py` - Extension bridge verification |
| 68 | +- `basic_agent.py` - Basic snapshot |
| 69 | +- `query_demo.py` - Query engine |
| 70 | +- `wait_and_click.py` - Wait and actions |
| 71 | + |
| 72 | +## Testing |
| 73 | + |
| 74 | +```bash |
| 75 | +pytest tests/ |
| 76 | +``` |
| 77 | + |
| 78 | +## Documentation |
| 79 | + |
| 80 | +- API Contract: `../spec/SNAPSHOT_V1.md` |
| 81 | +- Type Definitions: `../spec/sdk-types.md` |
0 commit comments