Skip to content

Commit c694662

Browse files
author
Stainless Bot
committed
feat(api): update via SDK Studio (#35)
1 parent 9d382d1 commit c694662

File tree

6 files changed

+64
-141
lines changed

6 files changed

+64
-141
lines changed

Diff for: README.md

+23-19
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ BROWSERBASE_PROJECT_ID = os.environ.get("BROWSERBASE_PROJECT_ID")
3737
bb = Browserbase(
3838
# This is the default and can be omitted
3939
api_key=BROWSERBASE_API_KEY,
40-
# or 'production' | 'local'; defaults to "production".
41-
environment="development",
4240
)
4341

44-
def run(playwright: Playwright) -> None:
45-
# Create a session on Browserbase
46-
session = bb.sessions.create(project_id=BROWSERBASE_PROJECT_ID)
42+
session = client.sessions.create(
43+
project_id=BROWSERBASE_PROJECT_ID,
44+
proxies=True,
45+
)
46+
print(session.id)
4747

48+
def run(playwright: Playwright) -> None:
4849
# Connect to the remote session
4950
chromium = playwright.chromium
5051
browser = chromium.connect_over_cdp(session.connect_url)
@@ -67,9 +68,7 @@ def run(playwright: Playwright) -> None:
6768
if __name__ == "__main__":
6869
with sync_playwright() as playwright:
6970
run(playwright)
70-
7171
```
72-
7372
## Examples
7473

7574
See the [examples](examples) directory for more usage examples.
@@ -112,8 +111,9 @@ from browserbase import Browserbase
112111
client = Browserbase()
113112

114113
try:
115-
client.contexts.create(
116-
project_id="projectId",
114+
client.sessions.create(
115+
project_id="your_project_id",
116+
proxies=True,
117117
)
118118
except browserbase.APIConnectionError as e:
119119
print("The server could not be reached")
@@ -157,8 +157,9 @@ client = Browserbase(
157157
)
158158

159159
# Or, configure per-request:
160-
client.with_options(max_retries=5).contexts.create(
161-
project_id="projectId",
160+
client.with_options(max_retries=5).sessions.create(
161+
project_id="your_project_id",
162+
proxies=True,
162163
)
163164
```
164165

@@ -182,8 +183,9 @@ client = Browserbase(
182183
)
183184

184185
# Override per-request:
185-
client.with_options(timeout=5.0).contexts.create(
186-
project_id="projectId",
186+
client.with_options(timeout=5.0).sessions.create(
187+
project_id="your_project_id",
188+
proxies=True,
187189
)
188190
```
189191

@@ -223,13 +225,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
223225
from browserbase import Browserbase
224226

225227
client = Browserbase()
226-
response = client.contexts.with_raw_response.create(
227-
project_id="projectId",
228+
response = client.sessions.with_raw_response.create(
229+
project_id="your_project_id",
230+
proxies=True,
228231
)
229232
print(response.headers.get('X-My-Header'))
230233

231-
context = response.parse() # get the object that `contexts.create()` would have returned
232-
print(context.id)
234+
session = response.parse() # get the object that `sessions.create()` would have returned
235+
print(session.id)
233236
```
234237

235238
These methods return an [`APIResponse`](https://github.com/browserbase/sdk-python/tree/main/src/browserbase/_response.py) object.
@@ -243,8 +246,9 @@ The above interface eagerly reads the full response body when you make the reque
243246
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
244247

245248
```python
246-
with client.contexts.with_streaming_response.create(
247-
project_id="projectId",
249+
with client.sessions.with_streaming_response.create(
250+
project_id="your_project_id",
251+
proxies=True,
248252
) as response:
249253
print(response.headers.get("X-My-Header"))
250254

Diff for: SECURITY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ or products provided by Browserbase please follow the respective company's secur
2020

2121
### Browserbase Terms and Policies
2222

23-
Please contact dev-feedback@browserbase.com for any questions or concerns regarding security of our services.
23+
Please contact support@browserbase.com for any questions or concerns regarding security of our services.
2424

2525
---
2626

Diff for: pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[project]
22
name = "browserbase"
33
version = "0.1.0-alpha.6"
4-
description = "The official Python library for the browserbase API"
4+
description = "The official Python library for the Browserbase API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"
77
authors = [
8-
{ name = "Browserbase", email = "dev-feedback@browserbase.com" },
8+
{ name = "Browserbase", email = "support@browserbase.com" },
99
]
1010
dependencies = [
1111
"httpx>=0.23.0, <1",

Diff for: src/browserbase/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from ._types import NOT_GIVEN, NoneType, NotGiven, Transport, ProxiesTypes
55
from ._utils import file_from_path
66
from ._client import (
7-
ENVIRONMENTS,
87
Client,
98
Stream,
109
Timeout,
@@ -69,7 +68,6 @@
6968
"AsyncStream",
7069
"Browserbase",
7170
"AsyncBrowserbase",
72-
"ENVIRONMENTS",
7371
"file_from_path",
7472
"BaseModel",
7573
"DEFAULT_TIMEOUT",

Diff for: src/browserbase/_client.py

+14-73
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Any, Dict, Union, Mapping, cast
7-
from typing_extensions import Self, Literal, override
6+
from typing import Any, Union, Mapping
7+
from typing_extensions import Self, override
88

99
import httpx
1010

@@ -33,7 +33,6 @@
3333
)
3434

3535
__all__ = [
36-
"ENVIRONMENTS",
3736
"Timeout",
3837
"Transport",
3938
"ProxiesTypes",
@@ -45,12 +44,6 @@
4544
"AsyncClient",
4645
]
4746

48-
ENVIRONMENTS: Dict[str, str] = {
49-
"production": "https://api.browserbase.com",
50-
"development": "https://api.dev.browserbase.com",
51-
"local": "http://api.localhost",
52-
}
53-
5447

5548
class Browserbase(SyncAPIClient):
5649
contexts: resources.ContextsResource
@@ -63,14 +56,11 @@ class Browserbase(SyncAPIClient):
6356
# client options
6457
api_key: str
6558

66-
_environment: Literal["production", "development", "local"] | NotGiven
67-
6859
def __init__(
6960
self,
7061
*,
7162
api_key: str | None = None,
72-
environment: Literal["production", "development", "local"] | NotGiven = NOT_GIVEN,
73-
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
63+
base_url: str | httpx.URL | None = None,
7464
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
7565
max_retries: int = DEFAULT_MAX_RETRIES,
7666
default_headers: Mapping[str, str] | None = None,
@@ -89,7 +79,7 @@ def __init__(
8979
# part of our public interface in the future.
9080
_strict_response_validation: bool = False,
9181
) -> None:
92-
"""Construct a new synchronous browserbase client instance.
82+
"""Construct a new synchronous Browserbase client instance.
9383
9484
This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
9585
"""
@@ -101,31 +91,10 @@ def __init__(
10191
)
10292
self.api_key = api_key
10393

104-
self._environment = environment
105-
106-
base_url_env = os.environ.get("BROWSERBASE_BASE_URL")
107-
if is_given(base_url) and base_url is not None:
108-
# cast required because mypy doesn't understand the type narrowing
109-
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
110-
elif is_given(environment):
111-
if base_url_env and base_url is not None:
112-
raise ValueError(
113-
"Ambiguous URL; The `BROWSERBASE_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
114-
)
115-
116-
try:
117-
base_url = ENVIRONMENTS[environment]
118-
except KeyError as exc:
119-
raise ValueError(f"Unknown environment: {environment}") from exc
120-
elif base_url_env is not None:
121-
base_url = base_url_env
122-
else:
123-
self._environment = environment = "production"
124-
125-
try:
126-
base_url = ENVIRONMENTS[environment]
127-
except KeyError as exc:
128-
raise ValueError(f"Unknown environment: {environment}") from exc
94+
if base_url is None:
95+
base_url = os.environ.get("BROWSERBASE_BASE_URL")
96+
if base_url is None:
97+
base_url = f"https://api.browserbase.com"
12998

13099
super().__init__(
131100
version=__version__,
@@ -169,7 +138,6 @@ def copy(
169138
self,
170139
*,
171140
api_key: str | None = None,
172-
environment: Literal["production", "development", "local"] | None = None,
173141
base_url: str | httpx.URL | None = None,
174142
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
175143
http_client: httpx.Client | None = None,
@@ -205,7 +173,6 @@ def copy(
205173
return self.__class__(
206174
api_key=api_key or self.api_key,
207175
base_url=base_url or self.base_url,
208-
environment=environment or self._environment,
209176
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
210177
http_client=http_client,
211178
max_retries=max_retries if is_given(max_retries) else self.max_retries,
@@ -263,14 +230,11 @@ class AsyncBrowserbase(AsyncAPIClient):
263230
# client options
264231
api_key: str
265232

266-
_environment: Literal["production", "development", "local"] | NotGiven
267-
268233
def __init__(
269234
self,
270235
*,
271236
api_key: str | None = None,
272-
environment: Literal["production", "development", "local"] | NotGiven = NOT_GIVEN,
273-
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
237+
base_url: str | httpx.URL | None = None,
274238
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
275239
max_retries: int = DEFAULT_MAX_RETRIES,
276240
default_headers: Mapping[str, str] | None = None,
@@ -289,7 +253,7 @@ def __init__(
289253
# part of our public interface in the future.
290254
_strict_response_validation: bool = False,
291255
) -> None:
292-
"""Construct a new async browserbase client instance.
256+
"""Construct a new async Browserbase client instance.
293257
294258
This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
295259
"""
@@ -301,31 +265,10 @@ def __init__(
301265
)
302266
self.api_key = api_key
303267

304-
self._environment = environment
305-
306-
base_url_env = os.environ.get("BROWSERBASE_BASE_URL")
307-
if is_given(base_url) and base_url is not None:
308-
# cast required because mypy doesn't understand the type narrowing
309-
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
310-
elif is_given(environment):
311-
if base_url_env and base_url is not None:
312-
raise ValueError(
313-
"Ambiguous URL; The `BROWSERBASE_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
314-
)
315-
316-
try:
317-
base_url = ENVIRONMENTS[environment]
318-
except KeyError as exc:
319-
raise ValueError(f"Unknown environment: {environment}") from exc
320-
elif base_url_env is not None:
321-
base_url = base_url_env
322-
else:
323-
self._environment = environment = "production"
324-
325-
try:
326-
base_url = ENVIRONMENTS[environment]
327-
except KeyError as exc:
328-
raise ValueError(f"Unknown environment: {environment}") from exc
268+
if base_url is None:
269+
base_url = os.environ.get("BROWSERBASE_BASE_URL")
270+
if base_url is None:
271+
base_url = f"https://api.browserbase.com"
329272

330273
super().__init__(
331274
version=__version__,
@@ -369,7 +312,6 @@ def copy(
369312
self,
370313
*,
371314
api_key: str | None = None,
372-
environment: Literal["production", "development", "local"] | None = None,
373315
base_url: str | httpx.URL | None = None,
374316
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
375317
http_client: httpx.AsyncClient | None = None,
@@ -405,7 +347,6 @@ def copy(
405347
return self.__class__(
406348
api_key=api_key or self.api_key,
407349
base_url=base_url or self.base_url,
408-
environment=environment or self._environment,
409350
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
410351
http_client=http_client,
411352
max_retries=max_retries if is_given(max_retries) else self.max_retries,

0 commit comments

Comments
 (0)