sweef-browser
Python SDK for Sweef, a browser engine for AI agents written in Go. Synchronous, standard library only, typed, Python 3.8+. The API follows Playwright's sync API where it can, and pages are read as a YAML accessibility tree in which every control carries a [ref=eN] handle you can pass back as a selector.
The SDK talks to a sweef binary over a local socket, so you need the binary too:
go install github.com/sweefbrowser/sweef/cmd/sweef@latest # or download a release; put it on PATH or set SWEEF_BIN
pip install sweef-browser
Quick start
from sweef import Sweef
with Sweef.launch() as sw: # starts `sweef serve` on a private socket, stops it on exit
page = sw.new_page("https://example.com")
print(page.title()) # Example Domain
print(page.snapshot(interactive_only=True)) # - link "Learn more" [ref=e1]: ...
png = page.screenshot() # PNG bytes
print(len(png), "bytes of PNG")
Connecting
Sweef.launch(addr=None, binary=None, args=None) |
start a private sweef serve and connect; close() (or with) stops it |
Sweef.connect("unix:/path" | "host:port") |
attach to a running sweef serve --addr ... |
Sweef.session(name=None) |
attach to the session CLI's daemon, so a script and sweef open/click/... drive the same pages |
Pages
import re
from sweef import Sweef
with Sweef.launch() as sw:
page = sw.new_page("https://news.ycombinator.com/")
tree = page.snapshot() # options: interactive_only, delta, selector, max_chars
ref = re.search(r'link "new" \[ref=(e\d+)\]', tree).group(1)
page.click(ref) # refs, CSS, text=, role=, label=, placeholder=, testid=
page.get_by_role("link", name="past").click()
print(page.snapshot(delta=True)) # only the lines that changed
- Reading:
title(),url(),content(),text_content(sel),snapshot(...),accessibility_tree(),screenshot(path=, full_page=, width=, height=),screenshot_text(),pdf(path=, format=),frames(),popups(). - Acting:
click,fill,type,press(keys and combinations such asControl+a),check,uncheck,select_option,hover,focus,tap,drag_and_drop,scroll,keyboard.type/press,mouse.click/move/down/up/wheel. - Locators:
page.locator(sel)withclick,fill,text_content,inner_html,get_attribute,input_value,count,is_visible,is_checked,bounding_box,wait_for,nth,first,last. - JavaScript:
evaluate(expr)orevaluate("s => s.length", arg),add_init_script,expose_binding+binding_calls. - Waiting (the page keeps running meanwhile):
wait_for_selector,wait_for_function,wait_for_load_state,wait_for_url,wait_for_timeout. - Network:
route(glob, json=... | body=..., status=, action=),unroute,unroute_all,routes,network_log,har,set_extra_http_headers,downloads,download. - Logs and dialogs:
console_messages,events,arm_dialog("accept"),dialogs. - Emulation:
set_viewport_size,set_user_agent,set_geolocation,grant_permissions,set_offline,emulate_media(color_scheme).
Batches: many steps, one round trip
from sweef import Sweef
with Sweef.launch() as sw:
page = sw.new_page()
r = page.batch([
"open https://the-internet.herokuapp.com/login",
"fill #username tomsmith",
"fill #password SuperSecretPassword!",
"click button[type=submit]",
"expect text 'You logged into a secure area'",
{"method": "Page.title"}, # any RPC method works as a step
], observe="interactive")
print(r["ok"], r["totalMs"], r["observation"])
Contexts
ctx = sw.new_context(user_agent="my-agent/1.0", viewport={"width": 390, "height": 844})
p = ctx.new_page("https://example.com")
print(ctx.cookies())
ctx.storage_state(path="state.json")
ctx.close()
Every RPC method of the engine is reachable with sw.call(method, params); see the method list in the main README.
Tests
SWEEF_BIN=/path/to/sweef python -m unittest discover -s tests runs the suite against a real sweef serve and a local HTTP fixture (no network).
License: Apache-2.0.
Metadata
Release files for sweef-browser 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sweef_browser-0.2.0.tar.gz | 19.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sweef_browser-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.6 kB
Release files / sweef_browser-0.2.0.tar.gz
| Download URL | sweef_browser-0.2.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d816a7ba1acf82bf874d6daa5f4a20af8985319369a1e127900517099fabadb0
|
|
BLAKE2b-256 checksum How to use checksums |
d4c5b9c2bca43b5b10b3f1a9370e6ca8d1d114d62d7881f433e65fc0309bfbcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / sweef_browser-0.2.0-py3-none-any.whl
| Download URL | sweef_browser-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a3b1cedb4d31839c3f7c718bdbaaa96be2ee9f3836db143bc8cfa8e54fc4c26
|
|
BLAKE2b-256 checksum How to use checksums |
06dcdca755aac64f82b989b57342601949fe67698b04cbac4dd11d3399df16bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for sweef-browser 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.