3
3
from __future__ import annotations
4
4
5
5
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
8
8
9
9
import httpx
10
10
33
33
)
34
34
35
35
__all__ = [
36
- "ENVIRONMENTS" ,
37
36
"Timeout" ,
38
37
"Transport" ,
39
38
"ProxiesTypes" ,
45
44
"AsyncClient" ,
46
45
]
47
46
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
-
54
47
55
48
class Browserbase (SyncAPIClient ):
56
49
contexts : resources .ContextsResource
@@ -63,14 +56,11 @@ class Browserbase(SyncAPIClient):
63
56
# client options
64
57
api_key : str
65
58
66
- _environment : Literal ["production" , "development" , "local" ] | NotGiven
67
-
68
59
def __init__ (
69
60
self ,
70
61
* ,
71
62
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 ,
74
64
timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
75
65
max_retries : int = DEFAULT_MAX_RETRIES ,
76
66
default_headers : Mapping [str , str ] | None = None ,
@@ -89,7 +79,7 @@ def __init__(
89
79
# part of our public interface in the future.
90
80
_strict_response_validation : bool = False ,
91
81
) -> None :
92
- """Construct a new synchronous browserbase client instance.
82
+ """Construct a new synchronous Browserbase client instance.
93
83
94
84
This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
95
85
"""
@@ -101,31 +91,10 @@ def __init__(
101
91
)
102
92
self .api_key = api_key
103
93
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"
129
98
130
99
super ().__init__ (
131
100
version = __version__ ,
@@ -169,7 +138,6 @@ def copy(
169
138
self ,
170
139
* ,
171
140
api_key : str | None = None ,
172
- environment : Literal ["production" , "development" , "local" ] | None = None ,
173
141
base_url : str | httpx .URL | None = None ,
174
142
timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
175
143
http_client : httpx .Client | None = None ,
@@ -205,7 +173,6 @@ def copy(
205
173
return self .__class__ (
206
174
api_key = api_key or self .api_key ,
207
175
base_url = base_url or self .base_url ,
208
- environment = environment or self ._environment ,
209
176
timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
210
177
http_client = http_client ,
211
178
max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
@@ -263,14 +230,11 @@ class AsyncBrowserbase(AsyncAPIClient):
263
230
# client options
264
231
api_key : str
265
232
266
- _environment : Literal ["production" , "development" , "local" ] | NotGiven
267
-
268
233
def __init__ (
269
234
self ,
270
235
* ,
271
236
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 ,
274
238
timeout : Union [float , Timeout , None , NotGiven ] = NOT_GIVEN ,
275
239
max_retries : int = DEFAULT_MAX_RETRIES ,
276
240
default_headers : Mapping [str , str ] | None = None ,
@@ -289,7 +253,7 @@ def __init__(
289
253
# part of our public interface in the future.
290
254
_strict_response_validation : bool = False ,
291
255
) -> None :
292
- """Construct a new async browserbase client instance.
256
+ """Construct a new async Browserbase client instance.
293
257
294
258
This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
295
259
"""
@@ -301,31 +265,10 @@ def __init__(
301
265
)
302
266
self .api_key = api_key
303
267
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"
329
272
330
273
super ().__init__ (
331
274
version = __version__ ,
@@ -369,7 +312,6 @@ def copy(
369
312
self ,
370
313
* ,
371
314
api_key : str | None = None ,
372
- environment : Literal ["production" , "development" , "local" ] | None = None ,
373
315
base_url : str | httpx .URL | None = None ,
374
316
timeout : float | Timeout | None | NotGiven = NOT_GIVEN ,
375
317
http_client : httpx .AsyncClient | None = None ,
@@ -405,7 +347,6 @@ def copy(
405
347
return self .__class__ (
406
348
api_key = api_key or self .api_key ,
407
349
base_url = base_url or self .base_url ,
408
- environment = environment or self ._environment ,
409
350
timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
410
351
http_client = http_client ,
411
352
max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
0 commit comments