stagehand-middleware (Python)
The facade's run, snapshot and screenshot tools for Python, over an existing
stagehand.Stagehand. It is a thin host for the facade bundle that
@browserbasehq/stagehand-integrations builds (dist/facade-bundle.json): the
JavaScript sent to experimental_batch and the model-facing contract (tool names,
descriptions, input schemas, error messages and result caps) come from that
bundle, so agents see the same tools as with the TypeScript facade.
from stagehand import Stagehand
from stagehand_middleware.facade import StagehandFacadeTools, facade_instructions, facade_tools
stagehand = await Stagehand.create(...)
tools = StagehandFacadeTools(stagehand, artifact_root="artifacts")
await tools.run(code="await page.goto('https://example.com'); return await page.title();")
tree = await tools.snapshot()
await tools.run(actions=[{"op": "click", "id": "0-7"}])
image = await tools.screenshot(type="jpeg", quality=40)
facade_tools() # tools/list entries to register with an agent framework
facade_instructions() # the agent instructions for the system prompt
runcode runs inside an async function with Playwright-shapedpage,contextandbrowser. An error it throws is raised asStagehandFacadeExecutionError(with the JavaScriptnameandstack).StagehandFacadeInputErrorcovers bad input and contract errors (stale snapshot IDs, malformed run results, artifact paths and caps, a closed facade). Other failures keep their own types: an error from the batch or RPC call itself (for examplestagehand.rpc_client.RPCError) propagates unchanged, a snapshot or screenshot past its capture deadline raisesTimeoutError, and a failed close raisesStagehandFacadeCleanupError(or anExceptionGroupwith the run's own error). Code that does not parse as an async function body raisesSyntaxErrorbefore anything is sent.- Screenshots saved with a
pathare written underartifact_root(default: the current directory). A path must stay within it and must not pass through a symlink. browser.close()in run code closes the Stagehand and its browser once the call finishes (passon_close_requestedto own that cleanup); later calls fail.quiet_wait=True(experimental, off by default) makes apage.waitForTimeout(ms)longer than 400 ms in run code return once the page is quiet (DOM loaded, no mutation in the main document for 400 ms; shadow roots are not observed), never later thanms. Shorter waits sleep in full.
This host has no keeper tab and does not latch session loss; the TypeScript
StagehandFacadeTools does both.
Development
src/stagehand_middleware/facade/_bundle.json is a copy of the built bundle.
After changing the TypeScript facade, rebuild the integrations package and run
pnpm run sync:python in packages/integrations/core;
tests/facade-python-bundle.test.ts and
node scripts/sync-python-facade-bundle.mjs --check (which CI runs in the
Python job) fail while the copy is stale. The package also checks the copy's
sha256 when it loads it.
uv run ruff format --check
uv run ruff check
uv run ty check
uv run pytest
tests/test_conformance.py runs the cases in ../conformance against this host.
tests/test_browser.py drives a local Chrome end to end; it is skipped unless
STAGEHAND_INTEGRATIONS_BROWSER_TESTS=1 (set CHROME_PATH if the Stagehand SDK
does not find Chrome).
Metadata
Release files for stagehand-middleware 0.1.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 | |
|---|---|---|---|---|
| stagehand_middleware-0.1.0.tar.gz | 62.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stagehand_middleware-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 128.1 kB
Release files / stagehand_middleware-0.1.0.tar.gz
| Download URL | stagehand_middleware-0.1.0.tar.gz |
|---|---|
| Size | 62.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d09647a30bec55865f92169d54ac4b9c74db19c67ad9db65aa7e0f47362cffb2
|
|
BLAKE2b-256 checksum How to use checksums |
119b1e3bb478e29d31679afc3ef5e10989e9a9453593443d7f3ff08d104f0532
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / stagehand_middleware-0.1.0-py3-none-any.whl
| Download URL | stagehand_middleware-0.1.0-py3-none-any.whl |
|---|---|
| Size | 65.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed04255cc9ca7050f4ed661db547108b6f3fcb71006daa992be9cd34002ae251
|
|
BLAKE2b-256 checksum How to use checksums |
1cfd5be653d7703c3ce5841829e173a49305ab2acbacc4588f10d06a590a672b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for stagehand-middleware 0.1.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.