1
1
import os
2
- from typing import List , Union
2
+ from typing import Optional , Sequence , Union
3
3
from playwright .sync_api import sync_playwright
4
4
5
5
6
6
class Browserbase :
7
- def __init__ (self , api_key : str = os .environ ["BROWSERBASE_KEY" ]):
8
- """Create new Browserbase instance"""
9
- if not api_key :
10
- raise ValueError ("Browserbase API key was not provided" )
7
+ def __init__ (self , api_key : Optional [str ] = None ):
8
+ """Create new Browserbase SDK client instance"""
9
+ self .api_key = api_key or os .environ ["BROWSERBASE_API_KEY" ]
11
10
12
- self .api_key = api_key
13
-
14
- def load (self , url : Union [str , List [str ]], ** args ):
11
+ def load (self , url : Union [str , Sequence [str ]], ** args ):
15
12
if isinstance (url , str ):
16
13
return self .load_url (url , ** args )
17
- elif isinstance (url , list ):
14
+ elif isinstance (url , Sequence ):
18
15
return self .load_urls (url , ** args )
19
16
else :
20
- raise TypeError ("Input must be a URL string or a list of URLs" )
17
+ raise TypeError ("Input must be a URL string or a Sequence of URLs" )
21
18
22
19
def load_url (self , url : str , text_content : bool = False ):
23
20
"""Load a page in a headless browser and return the contents"""
@@ -43,7 +40,7 @@ def load_url(self, url: str, text_content: bool = False):
43
40
44
41
return html
45
42
46
- def load_urls (self , urls : List [str ], text_content : bool = False ):
43
+ def load_urls (self , urls : Sequence [str ], text_content : bool = False ):
47
44
"""Load multiple pages in a headless browser and return the contents"""
48
45
if not urls :
49
46
raise ValueError ("Page URL was not provided" )
0 commit comments