Metadata-Version: 2.4
Name: stealth-browser-cloud-sdk
Version: 0.1.0
Summary: Dependency-free Python client for Stealth Browser cloud browsers and hosted agents.
Author: Stealth Browser
License-Expression: MIT
Project-URL: Repository, https://github.com/Youhai020616/stealth-browser
Keywords: browser,automation,cloud,agent,camoufox
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Python cloud SDK

`stealth_browser` is the Python client for the platform API: hosted Agent runs, cloud browsers
driven through the observation object, and the project's resources. Standard library only,
Python ≥ 3.10, synchronous (`StealthBrowser`) with an asyncio facade (`AsyncStealthBrowser`,
below). It mirrors the [JavaScript client](../../packages/cloud-sdk/README.md)
resource for resource; the one difference is that it does not run the platform contracts locally,
so a bad request is reported by the API rather than before sending. It is not packaged for PyPI
yet; publishing waits for the platform launch. Until then, put `sdks/python` on `sys.path`.

```python
import os
from stealth_browser import StealthBrowser, StealthApiError

client = StealthBrowser(os.environ["STEALTH_API_KEY"], base_url="https://…")

# A hosted Agent run: create, wait, read the result; on_event streams progress.
run = client.run("Find the cheapest 14\" laptop on the fixture site and report it.", judge=True,
                 on_event=lambda event: print(event["type"]))
print(run["status"], run["output"], run.get("data"), run.get("judgment"), run["usage"])  # data: only with output_schema

# A cloud browser, step by step, by ref.
browser = client.browsers.create({"settings": {"locale": "en-US"}})
browser.ready()
browser.navigate("https://example.com")
state = browser.observe(boxes=True)          # tree with [ref=eN], targets, tabs, dialogs, downloads
link = next((t for t in state["targets"] if t["role"] == "link"), None)
if link:
    browser.click(link["ref"])              # observation frames are handled inside
text = browser.text(format="markdown")["text"]
matches = browser.find(role="button", name="sign in")["matches"]
browser.stop()
```

## Client

`StealthBrowser(api_key, base_url=..., timeout=60.0, retries=2, opener=None)`. The key's project
is the project. `timeout` bounds each request; `retries` applies to idempotent requests only
(GETs and creates, which carry an `Idempotency-Key`). Environment proxies are ignored unless you
pass your own `urllib.request` opener.

`browser.resolve_challenge()` uses the operator-configured service once per browser; the
evidenced bridge is BOSS login Yidun v5 on 2Captcha. Use a client `timeout` of at least 160
seconds. Only `reply["result"]["status"] == "verified"` establishes website acceptance.
The client drops a consumed frame when `observation_invalidated` is true even if the mutation
returns a result. Operator keys and validation proofs are excluded. SMS/QR identity is separate.

## asyncio

`AsyncStealthBrowser` is the same client, awaitable: every method is a coroutine, `events` is
an async iterator, `browsers.create` / `attach` give an `AsyncCloudBrowser`. It is a facade over
the synchronous client, not a second transport — each call runs the verified synchronous
implementation in a worker thread (`asyncio.to_thread`), so `await` never blocks the event loop
and `asyncio.gather` runs calls concurrently, while retries, idempotency and frame handling stay
the one code path the suite pins. Standard library only.

```python
import asyncio
from stealth_browser import AsyncStealthBrowser

async def main():
    async with AsyncStealthBrowser(os.environ["STEALTH_API_KEY"], base_url="http://127.0.0.1:48633") as client:
        run = await client.runs.create({"task": "Open https://example.com and report the title."})
        async for event in client.runs.events(run["id"]):
            print(event["type"])
        browser = await client.browsers.create()
        await browser.ready()
        state = await browser.observe()
        await browser.stop()

asyncio.run(main())
```


| Surface | Methods |
| --- | --- |
| `client.run(task, **fields, poll_interval=, timeout=, on_event=)` | Create and wait; `fields` are run fields (`model_id`, `session_id`, `workspace_id`, `profile_id`, `judge`, `allowed_domains`, …) |
| `client.runs` | `create`, `get`, `list`, `cancel`, `wait`, `events` (generator), `message(run_id, text)` (queued for the agent's next step while the run runs), `withdraw_message(run_id, message_id)` |
| `client.billing` | `get` (the project's payer: balance, paid credit, concurrency; the project's month to date and budget), `set_budget(usd or None)`, `statement(month)` (per unit, model and basis, with the platform fee), `ledger(limit)`, `rates` — USD, integer micro-USD with a string beside it. A top-up is the signed-in account's action in the console; a key cannot buy credit |
| `client.agent_sessions`, `client.models()` | `list`, `get`, `rename(id, title)`, `delete(id)` (soft; a run in flight is cancelled first; idempotent), `purge(id)` (zero-data-retention projects); the catalog |
| `client.browsers` | `create` → `CloudBrowser`, `attach`, `get`, `list`, `stop`, `queue` (the admission line: its length and this project's places) |
| `client.assets` | `list`, `get`, `text`, `content` (bytes), `retry` |
| `client.profiles` | `list`, `create`, `get`, `update`, `import_state`, `save` |
| `client.workspaces` | `list`, `create`, `get`, `update`, `sessions`; `files.list/upload/download/text/move/folder/delete/archive` |
| `client.schedules` | `list`, `get`, `history`, `preview`, `run_now` |
| `client.integrations`, `client.proxies`, `client.history`, `client.usage`, `client.project` | `list`/`get`; `policy`/`credentials`; `list(**query)`; `get(days=)`; `current` |
| `client.request(method, path, body=, query=, ...)` | Any other route, with the same errors and retries |
| `verify_webhook(body, headers, secret)` | Standard Webhooks v1 check; returns the event or raises `webhook_signature` |

`CloudBrowser`: `ready`, `navigate`, `observe(boxes=, attributes=)`, `preview`, `snapshot`,
`act(name, params)` plus `click`, `type`, `select`, `press`, `scroll`, `hover`, `wait`,
`click_at`, `insert_text`, `back`, `forward`, `reload`, `switch_tab`, `close_tab`, `new_tab`, `dialog_policy`,
the read-only `find(**query)` and `text(format=, max_chars=)`, and `events`, `control`, `network_test`, `assets`,
`stop`. Frames, stale-frame retries and the read-only/page-changing distinction work as in the
JavaScript client.

## Errors and streams

Every failure is a `StealthApiError` with `status`, `code`, `request_id`, `details` and `local`.
`events()` and `on_event` use the API's server-sent events when offered (and not refused with
`rate_limited`, the API's bound on open streams per key and project) and fall back to cursor
polling; `client.diagnostics` counts both.

## Tests

`python3 -m unittest discover -s sdks/python/tests -t sdks/python` runs the suite against an
in-process fake API; the repository test runner wraps it (`tests/unit/python-sdk.test.js`) and
drives the client against a real platform and Camoufox in `tests/e2e/python-sdk.test.js`.
