Skip to content

Commit c3fd039

Browse files
feat(api): update via SDK Studio (#35)
1 parent 24ddbf1 commit c3fd039

File tree

6 files changed

+66
-144
lines changed

6 files changed

+66
-144
lines changed

Diff for: README.md

+25-22
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ from browserbase import Browserbase
3333
client = Browserbase(
3434
# This is the default and can be omitted
3535
api_key=os.environ.get("BROWSERBASE_API_KEY"),
36-
# or 'production' | 'local'; defaults to "production".
37-
environment="development",
3836
)
3937

40-
context = client.contexts.create(
41-
project_id="projectId",
38+
session = client.sessions.create(
39+
project_id="your_project_id",
40+
proxies=True,
4241
)
43-
print(context.id)
42+
print(session.id)
4443
```
4544

4645
While you can provide an `api_key` keyword argument,
@@ -60,16 +59,15 @@ from browserbase import AsyncBrowserbase
6059
client = AsyncBrowserbase(
6160
# This is the default and can be omitted
6261
api_key=os.environ.get("BROWSERBASE_API_KEY"),
63-
# or 'production' | 'local'; defaults to "production".
64-
environment="development",
6562
)
6663

6764

6865
async def main() -> None:
69-
context = await client.contexts.create(
70-
project_id="projectId",
66+
session = await client.sessions.create(
67+
project_id="your_project_id",
68+
proxies=True,
7169
)
72-
print(context.id)
70+
print(session.id)
7371

7472

7573
asyncio.run(main())
@@ -102,8 +100,9 @@ from browserbase import Browserbase
102100
client = Browserbase()
103101

104102
try:
105-
client.contexts.create(
106-
project_id="projectId",
103+
client.sessions.create(
104+
project_id="your_project_id",
105+
proxies=True,
107106
)
108107
except browserbase.APIConnectionError as e:
109108
print("The server could not be reached")
@@ -147,8 +146,9 @@ client = Browserbase(
147146
)
148147

149148
# Or, configure per-request:
150-
client.with_options(max_retries=5).contexts.create(
151-
project_id="projectId",
149+
client.with_options(max_retries=5).sessions.create(
150+
project_id="your_project_id",
151+
proxies=True,
152152
)
153153
```
154154

@@ -172,8 +172,9 @@ client = Browserbase(
172172
)
173173

174174
# Override per-request:
175-
client.with_options(timeout=5.0).contexts.create(
176-
project_id="projectId",
175+
client.with_options(timeout=5.0).sessions.create(
176+
project_id="your_project_id",
177+
proxies=True,
177178
)
178179
```
179180

@@ -213,13 +214,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
213214
from browserbase import Browserbase
214215

215216
client = Browserbase()
216-
response = client.contexts.with_raw_response.create(
217-
project_id="projectId",
217+
response = client.sessions.with_raw_response.create(
218+
project_id="your_project_id",
219+
proxies=True,
218220
)
219221
print(response.headers.get('X-My-Header'))
220222

221-
context = response.parse() # get the object that `contexts.create()` would have returned
222-
print(context.id)
223+
session = response.parse() # get the object that `sessions.create()` would have returned
224+
print(session.id)
223225
```
224226

225227
These methods return an [`APIResponse`](https://github.com/browserbase/sdk-python/tree/main/src/browserbase/_response.py) object.
@@ -233,8 +235,9 @@ The above interface eagerly reads the full response body when you make the reque
233235
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.
234236

235237
```python
236-
with client.contexts.with_streaming_response.create(
237-
project_id="projectId",
238+
with client.sessions.with_streaming_response.create(
239+
project_id="your_project_id",
240+
proxies=True,
238241
) as response:
239242
print(response.headers.get("X-My-Header"))
240243

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)