Spaces:
Configuration error
Configuration error
Download clients/python/browserbase.py from AnthropicallyHuggingFaces/ai-platform-toolbox: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/browserbase.py
- Command line
-
hf download hf://spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/clients/python/browserbase.py
-
curl -L -o browserbase.py https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/browserbase.py
1.24 kB
| """Browserbase client - cloud browser sessions, live view, file download.""" | |
| import os | |
| import requests | |
| BASE = os.getenv("BROWSERBASE_API_BASE", "https://api.browserbase.com") | |
| KEY = os.getenv("BROWSERBASE_API_KEY") | |
| def _h(): | |
| if not KEY: | |
| raise RuntimeError("BROWSERBASE_API_KEY not set") | |
| return {"X-BB-API-Key": KEY, "Content-Type": "application/json"} | |
| def create_session(project_id=None, **kwargs): | |
| body = {k: v for k, v in kwargs.items() if v is not None} | |
| if project_id: | |
| body["projectId"] = project_id | |
| return requests.post(f"{BASE}/v1/sessions", headers=_h(), json=body, timeout=60).json() | |
| def get_session(session_id: str): | |
| return requests.get(f"{BASE}/v1/sessions/{session_id}", headers=_h(), timeout=60).json() | |
| def debug(session_id: str, command: str): | |
| return requests.post(f"{BASE}/v1/sessions/{session_id}/debug", headers=_h(), json={"cmd": command}, timeout=120).json() | |
| def download_file(session_id: str, path: str): | |
| return requests.get(f"{BASE}/v1/sessions/{session_id}/file?path={path}", headers=_h(), timeout=120) | |
| def update_session(session_id: str, **kwargs): | |
| return requests.post(f"{BASE}/v1/sessions/{session_id}", headers=_h(), json=kwargs, timeout=60).json() | |