browserbase 0.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Browserbase Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: browserbase
3
+ Version: 0.0.7
4
+ Summary: Browserbase Python SDK
5
+ Author-email: Browserbase <info@browserbase.com>
6
+ Project-URL: Homepage, https://github.com/browserbase/python-sdk
7
+ Project-URL: Issues, https://github.com/browserbase/python-sdk/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: playwright>=1.43.0
15
+
16
+ # Browserbase Python SDK
17
+
18
+ Example usage:
19
+
20
+ ```
21
+ pip install browserbase
22
+ ```
23
+
24
+ ```py
25
+ from browserbase import Browserbase
26
+
27
+ # Init the SDK
28
+ browserbase = Browserbase(os.environ["BROWSERBASE_KEY"])
29
+
30
+ # Load a webpage
31
+ result = browserbase.load("https://example.com")
32
+
33
+ # Load multiple webpages (returns iterator)
34
+ result = browserbase.load(["https://example.com"])
35
+
36
+ # Text-only mode
37
+ result = browserbase.load("https://example.com", text_content=True)
38
+
39
+ # Screenshot (returns bytes)
40
+ result = browserbase.screenshot("https://example.com", full_page=True)
41
+ ```
@@ -0,0 +1,26 @@
1
+ # Browserbase Python SDK
2
+
3
+ Example usage:
4
+
5
+ ```
6
+ pip install browserbase
7
+ ```
8
+
9
+ ```py
10
+ from browserbase import Browserbase
11
+
12
+ # Init the SDK
13
+ browserbase = Browserbase(os.environ["BROWSERBASE_KEY"])
14
+
15
+ # Load a webpage
16
+ result = browserbase.load("https://example.com")
17
+
18
+ # Load multiple webpages (returns iterator)
19
+ result = browserbase.load(["https://example.com"])
20
+
21
+ # Text-only mode
22
+ result = browserbase.load("https://example.com", text_content=True)
23
+
24
+ # Screenshot (returns bytes)
25
+ result = browserbase.screenshot("https://example.com", full_page=True)
26
+ ```
@@ -0,0 +1,88 @@
1
+ import os
2
+ from typing import List, Union
3
+ from playwright.sync_api import sync_playwright
4
+
5
+
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")
11
+
12
+ self.api_key = api_key
13
+
14
+ def load(self, url: Union[str, List[str]], **args):
15
+ if isinstance(url, str):
16
+ return self.load_url(url, **args)
17
+ elif isinstance(url, list):
18
+ return self.load_urls(url, **args)
19
+ else:
20
+ raise TypeError("Input must be a URL string or a list of URLs")
21
+
22
+ def load_url(self, url: str, text_content: bool = False):
23
+ """Load a page in a headless browser and return the contents"""
24
+ if not url:
25
+ raise ValueError("Page URL was not provided")
26
+
27
+ with sync_playwright() as p:
28
+ browser = p.chromium.connect_over_cdp(
29
+ "wss://api.browserbase.com?apiKey=" + self.api_key
30
+ )
31
+ default_context = browser.contexts[0]
32
+ page = default_context.pages[0]
33
+ page.goto(url)
34
+ html = page.content()
35
+ if text_content:
36
+ readable = page.evaluate("""async () => {
37
+ const readability = await import('https://cdn.skypack.dev/@mozilla/readability');
38
+ return (new readability.Readability(document)).parse();
39
+ }""")
40
+
41
+ html = f"{readable['title']}\n{readable['textContent']}"
42
+ browser.close()
43
+
44
+ return html
45
+
46
+ def load_urls(self, urls: List[str], text_content: bool = False):
47
+ """Load multiple pages in a headless browser and return the contents"""
48
+ if not urls:
49
+ raise ValueError("Page URL was not provided")
50
+
51
+ with sync_playwright() as p:
52
+ browser = p.chromium.connect_over_cdp(
53
+ "wss://api.browserbase.com?apiKey=" + self.api_key
54
+ )
55
+
56
+ default_context = browser.contexts[0]
57
+ page = default_context.pages[0]
58
+
59
+ for url in urls:
60
+ page.goto(url)
61
+ html = page.content()
62
+ if text_content:
63
+ readable = page.evaluate("""async () => {
64
+ const readability = await import('https://cdn.skypack.dev/@mozilla/readability');
65
+ return (new readability.Readability(document)).parse();
66
+ }""")
67
+
68
+ html = f"{readable['title']}\n{readable['textContent']}"
69
+ yield html
70
+
71
+ browser.close()
72
+
73
+ def screenshot(self, url: str, full_page: bool = False):
74
+ """Load a page in a headless browser and return a screenshot as bytes"""
75
+ if not url:
76
+ raise ValueError("Page URL was not provided")
77
+
78
+ with sync_playwright() as p:
79
+ browser = p.chromium.connect_over_cdp(
80
+ "wss://api.browserbase.com?apiKey=" + self.api_key
81
+ )
82
+
83
+ page = browser.new_page()
84
+ page.goto(url)
85
+ screenshot = page.screenshot(full_page=full_page)
86
+ browser.close()
87
+
88
+ return screenshot
@@ -0,0 +1,22 @@
1
+ from base64 import b64encode
2
+ from enum import Enum
3
+
4
+
5
+ class GPT4VImageDetail(Enum):
6
+ low = "low"
7
+ high = "high"
8
+ auto = "auto"
9
+
10
+
11
+ def GPT4VImage(img: bytes, detail: GPT4VImageDetail = GPT4VImageDetail.auto):
12
+ if not img:
13
+ raise ValueError("Image was not provided")
14
+
15
+ img_encoded = b64encode(img).decode()
16
+ return {
17
+ "type": "image_url",
18
+ "image_url": {
19
+ "url": f"data:image/jpeg;base64,{img_encoded}",
20
+ "detail": detail.value,
21
+ },
22
+ }
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: browserbase
3
+ Version: 0.0.7
4
+ Summary: Browserbase Python SDK
5
+ Author-email: Browserbase <info@browserbase.com>
6
+ Project-URL: Homepage, https://github.com/browserbase/python-sdk
7
+ Project-URL: Issues, https://github.com/browserbase/python-sdk/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: playwright>=1.43.0
15
+
16
+ # Browserbase Python SDK
17
+
18
+ Example usage:
19
+
20
+ ```
21
+ pip install browserbase
22
+ ```
23
+
24
+ ```py
25
+ from browserbase import Browserbase
26
+
27
+ # Init the SDK
28
+ browserbase = Browserbase(os.environ["BROWSERBASE_KEY"])
29
+
30
+ # Load a webpage
31
+ result = browserbase.load("https://example.com")
32
+
33
+ # Load multiple webpages (returns iterator)
34
+ result = browserbase.load(["https://example.com"])
35
+
36
+ # Text-only mode
37
+ result = browserbase.load("https://example.com", text_content=True)
38
+
39
+ # Screenshot (returns bytes)
40
+ result = browserbase.screenshot("https://example.com", full_page=True)
41
+ ```
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ browserbase/__init__.py
5
+ browserbase.egg-info/PKG-INFO
6
+ browserbase.egg-info/SOURCES.txt
7
+ browserbase.egg-info/dependency_links.txt
8
+ browserbase.egg-info/requires.txt
9
+ browserbase.egg-info/top_level.txt
10
+ browserbase/helpers/gpt4.py
@@ -0,0 +1 @@
1
+ playwright>=1.43.0
@@ -0,0 +1 @@
1
+ browserbase
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "browserbase"
3
+ version = "0.0.7"
4
+ authors = [
5
+ { name="Browserbase", email="info@browserbase.com" },
6
+ ]
7
+ description = "Browserbase Python SDK"
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Operating System :: OS Independent",
14
+ ]
15
+
16
+ dependencies = [
17
+ "playwright >= 1.43.0"
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/browserbase/python-sdk"
22
+ Issues = "https://github.com/browserbase/python-sdk/issues"
23
+
24
+ [build-system]
25
+ requires = ["setuptools>=61.0"]
26
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+