Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc2da25

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): api update (#51)
1 parentb17a3b8 commitdc2da25

File tree

11 files changed

+62
-29
lines changed

11 files changed

+62
-29
lines changed

‎.stats.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints:18
2-
openapi_spec_url:https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-d8e42f141c0955e8100ca3ce041ce8dedf5dcf68b04e554a5704e4c2003c2fd4.yml
2+
openapi_spec_url:https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-7f88912695bab2b98cb73137e6f36125d02fdfaf8eed4532ee1c82385609a259.yml

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![PyPI version](https://img.shields.io/pypi/v/browserbase.svg)](https://pypi.org/project/browserbase/)
44

5-
The Browserbase Python library provides convenient access to the Browserbase REST API from any Python 3.7+
5+
The Browserbase Python library provides convenient access to the Browserbase REST API from any Python 3.8+
66
application. The library includes type definitions for all request params and response fields,
77
and offers both synchronous and asynchronous clients powered by[httpx](https://github.com/encode/httpx).
88

@@ -340,7 +340,7 @@ print(browserbase.__version__)
340340

341341
##Requirements
342342

343-
Python 3.7 or higher.
343+
Python 3.8 or higher.
344344

345345
##Contributing
346346

‎pyproject.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ dependencies = [
1616
"sniffio",
1717
"cached-property; python_version < '3.8'",
1818
]
19-
requires-python =">= 3.7"
19+
requires-python =">= 3.8"
2020
classifiers = [
2121
"Typing :: Typed",
2222
"Intended Audience :: Developers",
23-
"Programming Language :: Python :: 3.7",
2423
"Programming Language :: Python :: 3.8",
2524
"Programming Language :: Python :: 3.9",
2625
"Programming Language :: Python :: 3.10",
@@ -148,7 +147,7 @@ filterwarnings = [
148147
# there are a couple of flags that are still disabled by
149148
# default in strict mode as they are experimental and niche.
150149
typeCheckingMode ="strict"
151-
pythonVersion ="3.7"
150+
pythonVersion ="3.8"
152151

153152
exclude = [
154153
"_dev",

‎src/browserbase/_compat.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
fromtypingimportTYPE_CHECKING,Any,Union,Generic,TypeVar,Callable,cast,overload
44
fromdatetimeimportdate,datetime
5-
fromtyping_extensionsimportSelf
5+
fromtyping_extensionsimportSelf,Literal
66

77
importpydantic
88
frompydantic.fieldsimportFieldInfo
@@ -137,9 +137,11 @@ def model_dump(
137137
exclude_unset:bool=False,
138138
exclude_defaults:bool=False,
139139
warnings:bool=True,
140+
mode:Literal["json","python"]="python",
140141
)->dict[str,Any]:
141-
ifPYDANTIC_V2:
142+
ifPYDANTIC_V2orhasattr(model,"model_dump"):
142143
returnmodel.model_dump(
144+
mode=mode,
143145
exclude=exclude,
144146
exclude_unset=exclude_unset,
145147
exclude_defaults=exclude_defaults,

‎src/browserbase/_models.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
PropertyInfo,
3838
is_list,
3939
is_given,
40+
json_safe,
4041
lru_cache,
4142
is_mapping,
4243
parse_date,
@@ -279,8 +280,8 @@ def model_dump(
279280
Returns:
280281
A dictionary representation of the model.
281282
"""
282-
ifmode!="python":
283-
raiseValueError("modeis only supported in Pydantic v2")
283+
ifmodenotin {"json","python"}:
284+
raiseValueError("modemust be either 'json' or 'python'")
284285
ifround_trip!=False:
285286
raiseValueError("round_trip is only supported in Pydantic v2")
286287
ifwarnings!=True:
@@ -289,7 +290,7 @@ def model_dump(
289290
raiseValueError("context is only supported in Pydantic v2")
290291
ifserialize_as_any!=False:
291292
raiseValueError("serialize_as_any is only supported in Pydantic v2")
292-
returnsuper().dict(# pyright: ignore[reportDeprecated]
293+
dumped=super().dict(# pyright: ignore[reportDeprecated]
293294
include=include,
294295
exclude=exclude,
295296
by_alias=by_alias,
@@ -298,6 +299,8 @@ def model_dump(
298299
exclude_none=exclude_none,
299300
)
300301

302+
returncast(dict[str,Any],json_safe(dumped))ifmode=="json"elsedumped
303+
301304
@override
302305
defmodel_dump_json(
303306
self,

‎src/browserbase/_utils/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
is_listasis_list,
77
is_givenasis_given,
88
is_tupleasis_tuple,
9+
json_safeasjson_safe,
910
lru_cacheaslru_cache,
1011
is_mappingasis_mapping,
1112
is_tuple_tasis_tuple_t,

‎src/browserbase/_utils/_transform.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ def _transform_recursive(
173173
# Iterable[T]
174174
or (is_iterable_type(stripped_type)andis_iterable(data)andnotisinstance(data,str))
175175
):
176+
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
177+
# intended as an iterable, so we don't transform it.
178+
ifisinstance(data,dict):
179+
returncast(object,data)
180+
176181
inner_type=extract_type_arg(stripped_type,0)
177182
return [_transform_recursive(d,annotation=annotation,inner_type=inner_type)fordindata]
178183

@@ -186,7 +191,7 @@ def _transform_recursive(
186191
returndata
187192

188193
ifisinstance(data,pydantic.BaseModel):
189-
returnmodel_dump(data,exclude_unset=True)
194+
returnmodel_dump(data,exclude_unset=True,mode="json")
190195

191196
annotated_type=_get_annotated_type(annotation)
192197
ifannotated_typeisNone:
@@ -324,7 +329,7 @@ async def _async_transform_recursive(
324329
returndata
325330

326331
ifisinstance(data,pydantic.BaseModel):
327-
returnmodel_dump(data,exclude_unset=True)
332+
returnmodel_dump(data,exclude_unset=True,mode="json")
328333

329334
annotated_type=_get_annotated_type(annotation)
330335
ifannotated_typeisNone:

‎src/browserbase/_utils/_utils.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
overload,
1717
)
1818
frompathlibimportPath
19+
fromdatetimeimportdate,datetime
1920
fromtyping_extensionsimportTypeGuard
2021

2122
importsniffio
@@ -395,3 +396,19 @@ def lru_cache(*, maxsize: int | None = 128) -> Callable[[CallableT], CallableT]:
395396
maxsize=maxsize,
396397
)
397398
returncast(Any,wrapper)# type: ignore[no-any-return]
399+
400+
401+
defjson_safe(data:object)->object:
402+
"""Translates a mapping / sequence recursively in the same fashion
403+
as `pydantic` v2's `model_dump(mode="json")`.
404+
"""
405+
ifis_mapping(data):
406+
return {json_safe(key):json_safe(value)forkey,valueindata.items()}
407+
408+
ifis_iterable(data)andnotisinstance(data, (str,bytes,bytearray)):
409+
return [json_safe(item)foritemindata]
410+
411+
ifisinstance(data, (datetime,date)):
412+
returndata.isoformat()
413+
414+
returndata

‎src/browserbase/types/sessions/session_recording.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111

1212
classSessionRecording(BaseModel):
13-
id:str
14-
1513
data:Dict[str,object]
1614
"""
1715
See

‎tests/test_models.py‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,15 @@ class Model(BaseModel):
520520
assertm3.to_dict(exclude_none=True)== {}
521521
assertm3.to_dict(exclude_defaults=True)== {}
522522

523-
ifPYDANTIC_V2:
524-
525-
classModel2(BaseModel):
526-
created_at:datetime
523+
classModel2(BaseModel):
524+
created_at:datetime
527525

528-
time_str="2024-03-21T11:39:01.275859"
529-
m4=Model2.construct(created_at=time_str)
530-
assertm4.to_dict(mode="python")== {"created_at":datetime.fromisoformat(time_str)}
531-
assertm4.to_dict(mode="json")== {"created_at":time_str}
532-
else:
533-
withpytest.raises(ValueError,match="mode is only supported in Pydantic v2"):
534-
m.to_dict(mode="json")
526+
time_str="2024-03-21T11:39:01.275859"
527+
m4=Model2.construct(created_at=time_str)
528+
assertm4.to_dict(mode="python")== {"created_at":datetime.fromisoformat(time_str)}
529+
assertm4.to_dict(mode="json")== {"created_at":time_str}
535530

531+
ifnotPYDANTIC_V2:
536532
withpytest.raises(ValueError,match="warnings is only supported in Pydantic v2"):
537533
m.to_dict(warnings=False)
538534

@@ -558,9 +554,6 @@ class Model(BaseModel):
558554
assertm3.model_dump(exclude_none=True)== {}
559555

560556
ifnotPYDANTIC_V2:
561-
withpytest.raises(ValueError,match="mode is only supported in Pydantic v2"):
562-
m.model_dump(mode="json")
563-
564557
withpytest.raises(ValueError,match="round_trip is only supported in Pydantic v2"):
565558
m.model_dump(round_trip=True)
566559

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp