feat(sdk-python): add Browserbase client_options to launch and connect
Merged
MI
9d ago+255+255+012345678901234567890123456789-38-38-01234567890123456789
why
Stacked on #3118, which adds clientOptions to the TypeScript SDK. This PR adds the same option to Python, so callers can tune the Browserbase client Stagehand builds for session management without injecting their own client.
what changed
client_options: BrowserbaseClientOptionsonbrowserbase.launch()andbrowserbase.connect(). Fields:timeout(seconds),max_retries,default_headers,default_query,http_client. It's a public TypedDict backed by a strict Pydantic runtime model, so unknown keys such asapi_keyorbase_urlare rejected._OfficialBrowserbaseAPIbuilds everyAsyncBrowserbasewith these options.api_keyandbase_urlstay top-level.http_client: httpx.AsyncClientis the Python counterpart to TSfetch: custom transports, proxies, mocks, request/response hooks. The SDK'sAsyncBrowserbase.close()closes its HTTP client, so for a caller-supplied client Stagehand buildsAsyncBrowserbasearound it without closing it. The caller owns the client and must keep it open untilbrowser.close()returns. Clients Stagehand creates are still closed.httpxbecomes a direct dependency because it now appears in a public type; it was already in the lock file throughbrowserbase.- Removes the Python exemption #3118 added to the parity test, and adds
BrowserbaseClientOptionsto the check that keeps Python's input types and runtime models in sync. - Extends the docs section with a Python example and a minor changeset for
stagehand-python.
test plan
- pytest: 754 passed. New tests cover passing options through launch and connect, rejecting invalid options before any API call (including a sync
httpx.Client), and building a realAsyncBrowserbasewith the options applied. - A full launch-and-close lifecycle through a caller
http_clientwith a mock transport: all four requests (extension upload, session create, release, extension delete) go through it, and it is still open afterwards. With the ownership check disabled, this test fails at session create. -
ty check, ruff check and ruff format,uv lock --check,generate.py --check -
rules/ast-grepparity tests with the Python exemption removed, and the docs tests - No live Browserbase session was launched