Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions browserbase/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import os
import time

try:
import tomllib
except ImportError:
import tomli as tomllib
from typing import Literal, Optional, Sequence, Union

import httpx
from playwright.sync_api import sync_playwright
from pydantic import BaseModel, Field, TypeAdapter

# Read version from pyproject.toml
with open(os.path.join(os.path.dirname(__file__), "..", "pyproject.toml"), "rb") as f:
pyproject = tomllib.load(f)
BROWSERBASE_CLIENT_SDK_VERSION = pyproject["project"]["version"]

client_name = f"browserbase-python=={BROWSERBASE_CLIENT_SDK_VERSION}"
BrowserType = Literal["chrome", "firefox", "edge", "safari"]
DeviceType = Literal["desktop", "mobile"]
OperatingSystem = Literal["windows", "macos", "linux", "ios", "android"]
Expand Down Expand Up @@ -142,6 +153,7 @@ def list_sessions(self) -> list[Session]:
f"{self.api_url}/v1/sessions",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
"Content-Type": "application/json",
},
)
Expand All @@ -164,6 +176,7 @@ def create_session(self, options: Optional[CreateSessionOptions] = None) -> Sess
f"{self.api_url}/v1/sessions",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
"Content-Type": "application/json",
},
json=payload,
Expand All @@ -185,6 +198,7 @@ def complete_session(self, session_id: str) -> Session:
f"{self.api_url}/v1/sessions/{session_id}",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
"Content-Type": "application/json",
},
json={
Expand All @@ -201,6 +215,7 @@ def get_session(self, session_id: str) -> Session:
f"{self.api_url}/v1/sessions/{session_id}",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
"Content-Type": "application/json",
},
)
Expand All @@ -213,6 +228,7 @@ def get_session_recording(self, session_id: str) -> list[SessionRecording]:
f"{self.api_url}/v1/sessions/{session_id}/recording",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
"Content-Type": "application/json",
},
)
Expand All @@ -231,6 +247,7 @@ def fetch_download():
f"{self.api_url}/v1/sessions/{session_id}/downloads",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
},
)
content = response.read()
Expand All @@ -250,6 +267,7 @@ def get_debug_connection_urls(self, session_id: str) -> DebugConnectionURLs:
f"{self.api_url}/v1/sessions/{session_id}/debug",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
"Content-Type": "application/json",
},
)
Expand All @@ -262,6 +280,7 @@ def get_session_logs(self, session_id: str) -> list[SessionLog]:
f"{self.api_url}/v1/sessions/{session_id}/logs",
headers={
"x-bb-api-key": self.api_key,
"x-client-name": client_name,
"Content-Type": "application/json",
},
)
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "browserbase"
version = "0.3.7"
version = "0.3.8"
authors = [
{ name="Browserbase", email="support@browserbase.com" },
]
Expand All @@ -16,7 +16,8 @@ classifiers = [
dependencies = [
"playwright >= 1.43.0",
"pydantic >= 2.7.1",
"httpx >= 0.27.0"
"httpx >= 0.27.0",
"tomli >= 2.0.1",
]

[project.urls]
Expand Down