Skip to content

Commit 9da7370

Browse files
committed
changed enums to literals
1 parent 3a5b0d7 commit 9da7370

File tree

2 files changed

+20
-40
lines changed

2 files changed

+20
-40
lines changed

‎browserbase/__init__.py

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
11
import os
22
import httpx
33
import time
4-
from typing import Optional, Sequence, Union, List
4+
from typing import Optional, Sequence, Union, Literal
55
from enum import Enum
6-
from pydantic import BaseModel, Field
6+
from pydantic import BaseModel
77
from playwright.sync_api import sync_playwright
88

99

10-
class BrowserType(str, Enum):
11-
CHROME = "chrome"
12-
FIREFOX = "firefox"
13-
EDGE = "edge"
14-
SAFARI = "safari"
15-
16-
17-
class DeviceType(str, Enum):
18-
DESKTOP = "desktop"
19-
MOBILE = "mobile"
20-
21-
22-
class OperatingSystem(str, Enum):
23-
WINDOWS = "windows"
24-
MACOS = "macos"
25-
LINUX = "linux"
26-
IOS = "ios"
27-
ANDROID = "android"
28-
29-
30-
class SessionStatus(str, Enum):
31-
NEW = "NEW"
32-
CREATED = "CREATED"
33-
ERROR = "ERROR"
34-
RUNNING = "RUNNING"
35-
REQUEST_RELEASE = "REQUEST_RELEASE"
36-
RELEASING = "RELEASING"
37-
COMPLETED = "COMPLETED"
10+
BrowserType = Literal["chrome", "firefox", "edge", "safari"]
11+
DeviceType = Literal["desktop", "mobile"]
12+
OperatingSystem = Literal["windows", "macos", "linux", "ios", "android"]
13+
SessionStatus = Literal[
14+
"NEW", "CREATED", "ERROR", "RUNNING", "REQUEST_RELEASE", "RELEASING", "COMPLETED"
15+
]
3816

3917

4018
class Screen(BaseModel):
@@ -47,10 +25,10 @@ class Screen(BaseModel):
4725
class Fingerprint(BaseModel):
4826
browserListQuery: Optional[str] = None
4927
httpVersion: Optional[int] = None
50-
browsers: Optional[List[BrowserType]] = None
51-
devices: Optional[List[DeviceType]] = None
52-
locales: Optional[List[str]] = None
53-
operatingSystems: Optional[List[OperatingSystem]] = None
28+
browsers: Optional[list[BrowserType]] = None
29+
devices: Optional[list[DeviceType]] = None
30+
locales: Optional[list[str]] = None
31+
operatingSystems: Optional[list[OperatingSystem]] = None
5432
screen: Optional[Screen] = None
5533

5634

@@ -129,15 +107,17 @@ def __init__(
129107
self.connect_url = connect_url or "wss://connect.browserbase.com"
130108
self.api_url = api_url or "https://www.browserbase.com"
131109

132-
def get_connect_url(self, session_id=None, proxy=False):
110+
def get_connect_url(
111+
self, session_id: Optional[str] = None, proxy: Optional[bool] = None
112+
):
133113
base_url = f"{self.connect_url}?apiKey={self.api_key}"
134114
if session_id:
135115
base_url += f"&sessionId={session_id}"
136116
if proxy:
137117
base_url += "&enableProxy=true"
138118
return base_url
139119

140-
def list_sessions(self) -> List[Session]:
120+
def list_sessions(self) -> list[Session]:
141121
response = httpx.get(
142122
f"{self.api_url}/v1/sessions",
143123
headers={
@@ -167,7 +147,7 @@ def create_session(self, options: Optional[CreateSessionOptions] = None) -> Sess
167147
response.raise_for_status()
168148
return Session(**response.json())
169149

170-
def get_session(self, session_id: str) -> List[Session]:
150+
def get_session(self, session_id: str) -> Session:
171151
response = httpx.get(
172152
f"{self.api_url}/v1/sessions/{session_id}",
173153
headers={
@@ -198,7 +178,7 @@ def update_session(
198178
response.raise_for_status()
199179
return Session(**response.json())
200180

201-
def get_session_recording(self, session_id: str) -> List[SessionRecording]:
181+
def get_session_recording(self, session_id: str) -> list[SessionRecording]:
202182
response = httpx.get(
203183
f"{self.api_url}/v1/sessions/{session_id}/recording",
204184
headers={
@@ -247,7 +227,7 @@ def get_debug_connection_urls(self, session_id: str) -> DebugConnectionURLs:
247227
response.raise_for_status()
248228
return DebugConnectionURLs(**response.json())
249229

250-
def get_session_logs(self, session_id: str) -> List[SessionLog]:
230+
def get_session_logs(self, session_id: str) -> list[SessionLog]:
251231
response = httpx.get(
252232
f"{self.api_url}/v1/sessions/{session_id}/logs",
253233
headers={

‎pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "browserbase"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
authors = [
55
{ name="Browserbase", email="info@browserbase.com" },
66
]

0 commit comments

Comments
 (0)