Skip to main content

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 the sweef engine over a local socket; it installs the engine for you on first use, so this is all you need:

pip install sweef-browser

The sweef engine: installed for you

You do not download Sweef or edit PATH. The SDK finds the engine in this order:

  1. the binary option (Sweef.launch(binary=...))
  2. $SWEEF_BIN
  3. sweef on PATH
  4. the per-user cache: $XDG_CACHE_HOME/sweef/<engine-version>/sweef (default ~/.cache/...), ~/Library/Caches/sweef/... on macOS, %LOCALAPPDATA%\sweef\cache\<engine-version>\sweef.exe on Windows
  5. otherwise it downloads the pinned engine (0.1.0-alpha.5) from the GitHub release into that cache, once, and prints one line to stderr. The archive's SHA-256 is checked before anything is executed; the SDK pins the expected hashes for its default version and falls back to the release's SHA256SUMS for other versions.

pip install sweef-browser (or pipx install sweef-browser) also puts a sweef command on PATH (it runs the same engine, downloading it first if needed). sweef-install or python -m sweef downloads the engine ahead of time and prints where it is (--print-path only looks, never downloads). import sweef has no side effects; the download happens on the first Sweef.launch() / Sweef.session(). In code, sweef.ensure_binary() returns the engine path, downloading it if necessary.

Variable Effect
SWEEF_BIN use this binary, skip everything else
SWEEF_VERSION engine version to use/download instead of the pinned one
SWEEF_DOWNLOAD_BASE mirror root, layout <base>/v<version>/<asset> and SHA256SUMS (air-gapped or corporate mirrors; http:// allowed)
SWEEF_ENGINE_CACHE cache root instead of the per-user default
SWEEF_SKIP_DOWNLOAD=1 never download: behave as before and fail with the manual install instructions
HTTPS_PROXY, NO_PROXY standard proxy variables are honored

Air-gapped: mirror the release files under $SWEEF_DOWNLOAD_BASE/v<version>/, or put the engine on PATH / in SWEEF_BIN and set SWEEF_SKIP_DOWNLOAD=1. Uninstall: delete the cache directory (<cache>/sweef/<engine-version>); nothing else is written outside the package, and PATH is never modified.

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 as Control+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) with click, fill, text_content, inner_html, get_attribute, input_value, count, is_visible, is_checked, bounding_box, wait_for, nth, first, last.
  • JavaScript: evaluate(expr) or evaluate("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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sweef-browser 0.2.1
File Size Uploaded Provenance
sweef_browser-0.2.1.tar.gz 31.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sweef-browser 0.2.1
File Interpreter ABI Platform
sweef_browser-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 54.5 kB

Release files / sweef_browser-0.2.1.tar.gz

Download URL sweef_browser-0.2.1.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8f18b0191b8a8f487871fc7f5b3b66a02f89131774c4b8d12aaf91863ff66e85
BLAKE2b-256 checksum
How to use checksums
3aad2a20bf30b4438db63cf1f772002e778e078c98e06099146a8b5da0e0e8e6
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.1-py3-none-any.whl

Download URL sweef_browser-0.2.1-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
45658b2006f0a3acf802df650cad0eeabadc01c7b3cb2a9589854429d3440b8a
BLAKE2b-256 checksum
How to use checksums
1ffcff94fb04273de853652df3041afb24cfd7ef0283d1ec9e848896a9799f8c
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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page