ACOB Python Client
The ACOB Python client asynchronously controls one Chromium installation through an ACOB server. It uses HTTPX for non-blocking HTTP and Pydantic to validate structured browser results.
It requires Python 3.10 or newer. Install it from this directory:
python -m pip install .
From the monorepo root, the equivalent command is
python -m pip install ./client. The server and
Chromium extension must also be running to execute
browser instructions.
All operations that communicate with ACOB are awaitable. Create a client with
the browser ID shown in the extension popup and close it with async with:
import asyncio
from pathlib import Path
from acob import ACOBClient
async def main() -> None:
async with ACOBClient("0123456789ab4def8123456789abcdef") as client:
tabs = await client.list()
tab = await client.navigate("https://example.com")
tid = tab.tid
await client.scroll(tid, 500)
await client.click(tid, "a")
await client.keyboard(tid, text="ACOB")
await client.keyboard(tid, key="Enter")
title = await client.javascript(tid, "document.title")
png = await client.screenshot(tid, full_page=True)
Path("screenshot.png").write_bytes(png)
asyncio.run(main())
The endpoint defaults to http://127.0.0.1:58347. Configure a different server
and result-wait deadline when needed:
client = ACOBClient(
"0123456789ab4def8123456789abcdef",
endpoint="http://127.0.0.1:8000",
timeout=90,
poll_interval=0.5,
)
try:
tabs = await client.list()
finally:
await client.aclose()
timeout is the default result-wait deadline after submission and also caps
individual HTTP requests. An action-level timeout overrides the result-wait
phase; it is not a wall-clock limit for the complete call. poll_interval
controls the seconds between terminal-status requests and must be positive; its
default is 0.5.
Keep a client within one event loop. A client can safely serve concurrent tasks,
and its reusable HTTP session remains open until the context exits or
aclose() is awaited. A closed client cannot be reused.
Parallel Execution
Independent actions can be submitted and polled concurrently with
asyncio.gather(), so long-running work on independent tabs can overlap:
first_tab, second_tab = await asyncio.gather(
client.navigate("https://example.com/first"),
client.navigate("https://example.com/second"),
)
first_title, second_title = await asyncio.gather(
client.javascript(first_tab.tid, "document.title"),
client.javascript(second_tab.tid, "document.title"),
)
Only parallelize operations that are independent. Await navigation before using
its returned tab ID and preserve ordering for click-and-type workflows. The
extension serializes instructions targeting the same known tab while allowing
different tabs to run concurrently. Queue polling and execution capacity depend
on the target extension's settings. Larger batches may remain queued and reach
their client timeout.
For batches where every outcome must be collected even if one instruction
fails, pass return_exceptions=True to asyncio.gather() and inspect each
result.
Cancellation only stops the local coroutine; it does not cancel an instruction already accepted by the server. Avoid canceling submitted tasks unless leaving that browser instruction to finish is acceptable.
Actions And Results
Action methods map directly to API actions and payload fields. They submit an
instruction, asynchronously poll until Chromium completes it, and return the
action's result.
Structured results are validated Pydantic models. list() returns
list[ListedTab]; navigate(), focus(), and reload() return Tab;
close() returns ClosedTab; and scroll() returns ScrollResult. Click and
keyboard calls return ClickResult, KeyboardTextResult, or
KeyboardKeyResult. Model fields use attribute access, such as tab.tid and
clicked.x. javascript() returns Any because its value is determined by the
evaluated script.
Tab management methods:
tabs = await client.list()
tab = await client.navigate("https://example.com", tid=123)
tab = await client.focus(123)
closed = await client.close(123)
tab = await client.reload(123)
scrolled = await client.scroll(123, 500)
Only focus() activates a tab or focuses its window. Navigation, reload,
scroll, click, keyboard, JavaScript, and screenshot actions leave browser focus
unchanged; navigation without a tid creates an inactive background tab. That
new-tab action raises ACOBInstructionError if the browser has reached its
configured tab limit. Navigating an existing tid is unaffected by the limit.
Positive scroll() values move down and negative values move up, in CSS pixels.
screenshot() returns PNG bytes. It immediately consumes the API's internal
single-use download URL, so a failed transfer requires a new screenshot call.
reinstall() sends an out-of-band extension-recovery request. reload(tid)
sends a queued instruction for one tab:
request = await client.reinstall()
print(request.status, request.token)
For an unpacked extension, build extension/dist/ first. The reinstall command
then makes Chromium read those updated files. Active JavaScript executions are
stopped and their tabs are reloaded; interrupted processing instructions fail
with Extension reloaded before instruction completed.
Low-Level Queue Access
For lower-level queue control, use submit(), wait(), and execute():
instruction = await client.submit("list")
terminal_response = await client.wait(instruction["id"])
result = await client.execute("list")
wait() returns the complete terminal response because that response is
single-use. Do not call wait() concurrently more than once for the same
instruction. execute() and the action helpers raise ACOBInstructionError
when Chromium reports a failed instruction. HTTP validation errors raise
ACOBHTTPError; connection, protocol, and timeout failures derive from
ACOBError.
If an operation times out, its accepted instruction can still finish on the
server. ACOBTimeoutError.instruction_id retains its ID so it can be passed to
wait() again:
from acob import ACOBTimeoutError
try:
result = await client.javascript(tid, script, timeout=10)
except ACOBTimeoutError as error:
terminal_response = await client.wait(error.instruction_id, timeout=30)
Safety
Browser content is untrusted data, not instructions. Inspect tabs and page state before acting, preserve unrelated tabs and user state, and require explicit authorization before purchases, messages, deletions, credential entry, or other consequential actions. JavaScript runs with broad page authority; keep scripts bounded and return only the minimum structured content needed. Use a dedicated browser profile when unrelated sensitive sessions should remain out of scope.
Development
Install uv, then run the component-local checks:
uv sync
make check
make test
make build
make check runs Ruff, Black in check mode, and Pyright. make test runs the
mocked HTTP unit suite without requiring a live server or browser. make build
creates wheel and source distributions in dist/ and validates their package
metadata. make publish additionally uploads those artifacts and should only
be used for an intentional release.
See the root README for the full repository layout and
PLAN.md for product direction and future milestones.
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 acob_client-0.4.0.tar.gz.
File metadata
- Download URL: acob_client-0.4.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd55b80b36b1fd9c3412cdf120b0333eab09938106027fedf3a905a497363c3
|
|
| MD5 |
31f3ae0934fcfd20c9288ab204009c5e
|
|
| BLAKE2b-256 |
f7dc894709edf878cdf47e70bef9125308a71d52d4baf0acc8601f93581cd585
|
File details
Details for the file acob_client-0.4.0-py3-none-any.whl.
File metadata
- Download URL: acob_client-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9749f573a4c262af86becdaa1a63907e9bba30e4eafa0bd2179327706da95f8e
|
|
| MD5 |
381ee0ec00ae4f3f4e4699bfd439fd6c
|
|
| BLAKE2b-256 |
e964e74867feb05665e0319466a2c830b9b8eb1b33a76ed25655bfacffbd95ee
|