Skip to content

feat(api): update via SDK Studio #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 18
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-0069ed71133ac7b0add07abd8562396c4b8e3c9a212e14a7586782eeed2ff373.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fbrowserbase-0d0ad7d4de2fa0b930b8d72fe6539ab248c7ed684b2e12b327b3bc0a466f9cde.yml
4 changes: 2 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
@@ -45,12 +45,12 @@ Methods:
Types:

```python
from browserbase.types import Session, SessionLiveURLs, SessionListResponse
from browserbase.types import Session, SessionLiveURLs, SessionCreateResponse, SessionListResponse
```

Methods:

- <code title="post /v1/sessions">client.sessions.<a href="./src/browserbase/resources/sessions/sessions.py">create</a>(\*\*<a href="src/browserbase/types/session_create_params.py">params</a>) -> <a href="./src/browserbase/types/session.py">Session</a></code>
- <code title="post /v1/sessions">client.sessions.<a href="./src/browserbase/resources/sessions/sessions.py">create</a>(\*\*<a href="src/browserbase/types/session_create_params.py">params</a>) -> <a href="./src/browserbase/types/session_create_response.py">SessionCreateResponse</a></code>
- <code title="get /v1/sessions/{id}">client.sessions.<a href="./src/browserbase/resources/sessions/sessions.py">retrieve</a>(id) -> <a href="./src/browserbase/types/session.py">Session</a></code>
- <code title="post /v1/sessions/{id}">client.sessions.<a href="./src/browserbase/resources/sessions/sessions.py">update</a>(id, \*\*<a href="src/browserbase/types/session_update_params.py">params</a>) -> <a href="./src/browserbase/types/session.py">Session</a></code>
- <code title="get /v1/sessions">client.sessions.<a href="./src/browserbase/resources/sessions/sessions.py">list</a>(\*\*<a href="src/browserbase/types/session_list_params.py">params</a>) -> <a href="./src/browserbase/types/session_list_response.py">SessionListResponse</a></code>
4 changes: 2 additions & 2 deletions src/browserbase/resources/sessions/downloads.py
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ def list(
"""
if not id:
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
extra_headers = {"Accept": "application/zip", **(extra_headers or {})}
return self._get(
f"/v1/sessions/{id}/downloads",
options=make_request_options(
@@ -122,7 +122,7 @@ async def list(
"""
if not id:
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
extra_headers = {"Accept": "application/zip", **(extra_headers or {})}
return await self._get(
f"/v1/sessions/{id}/downloads",
options=make_request_options(
22 changes: 15 additions & 7 deletions src/browserbase/resources/sessions/sessions.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

from __future__ import annotations

from typing import Union, Iterable
from typing_extensions import Literal

import httpx
@@ -57,6 +56,7 @@
from ...types.session import Session
from ...types.session_live_urls import SessionLiveURLs
from ...types.session_list_response import SessionListResponse
from ...types.session_create_response import SessionCreateResponse

__all__ = ["SessionsResource", "AsyncSessionsResource"]

@@ -104,15 +104,16 @@ def create(
browser_settings: session_create_params.BrowserSettings | NotGiven = NOT_GIVEN,
extension_id: str | NotGiven = NOT_GIVEN,
keep_alive: bool | NotGiven = NOT_GIVEN,
proxies: Union[bool, Iterable[session_create_params.ProxiesUnionMember1]] | NotGiven = NOT_GIVEN,
proxies: object | NotGiven = NOT_GIVEN,
region: Literal["us-west-2", "us-east-1", "eu-central-1", "ap-southeast-1"] | NotGiven = NOT_GIVEN,
api_timeout: int | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Session:
) -> SessionCreateResponse:
"""Create a Session
Args:
@@ -130,6 +131,8 @@ def create(
proxies: Proxy configuration. Can be true for default proxy, or an array of proxy
configurations.
region: The region where the Session should run.
api_timeout: Duration in seconds after which the session will automatically end. Defaults to
the Project's `defaultTimeout`.
@@ -150,14 +153,15 @@ def create(
"extension_id": extension_id,
"keep_alive": keep_alive,
"proxies": proxies,
"region": region,
"timeout": api_timeout,
},
session_create_params.SessionCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Session,
cast_to=SessionCreateResponse,
)

def retrieve(
@@ -354,15 +358,16 @@ async def create(
browser_settings: session_create_params.BrowserSettings | NotGiven = NOT_GIVEN,
extension_id: str | NotGiven = NOT_GIVEN,
keep_alive: bool | NotGiven = NOT_GIVEN,
proxies: Union[bool, Iterable[session_create_params.ProxiesUnionMember1]] | NotGiven = NOT_GIVEN,
proxies: object | NotGiven = NOT_GIVEN,
region: Literal["us-west-2", "us-east-1", "eu-central-1", "ap-southeast-1"] | NotGiven = NOT_GIVEN,
api_timeout: int | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Session:
) -> SessionCreateResponse:
"""Create a Session
Args:
@@ -380,6 +385,8 @@ async def create(
proxies: Proxy configuration. Can be true for default proxy, or an array of proxy
configurations.
region: The region where the Session should run.
api_timeout: Duration in seconds after which the session will automatically end. Defaults to
the Project's `defaultTimeout`.
@@ -400,14 +407,15 @@ async def create(
"extension_id": extension_id,
"keep_alive": keep_alive,
"proxies": proxies,
"region": region,
"timeout": api_timeout,
},
session_create_params.SessionCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Session,
cast_to=SessionCreateResponse,
)

async def retrieve(
1 change: 1 addition & 0 deletions src/browserbase/types/__init__.py
Original file line number Diff line number Diff line change
@@ -17,3 +17,4 @@
from .context_create_response import ContextCreateResponse as ContextCreateResponse
from .context_update_response import ContextUpdateResponse as ContextUpdateResponse
from .extension_create_params import ExtensionCreateParams as ExtensionCreateParams
from .session_create_response import SessionCreateResponse as SessionCreateResponse
68 changes: 7 additions & 61 deletions src/browserbase/types/session_create_params.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@

from __future__ import annotations

from typing import List, Union, Iterable
from typing_extensions import Literal, Required, Annotated, TypeAlias, TypedDict
from typing import List
from typing_extensions import Literal, Required, Annotated, TypedDict

from .._utils import PropertyInfo

@@ -14,10 +14,6 @@
"BrowserSettingsFingerprint",
"BrowserSettingsFingerprintScreen",
"BrowserSettingsViewport",
"ProxiesUnionMember1",
"ProxiesUnionMember1BrowserbaseProxyConfig",
"ProxiesUnionMember1BrowserbaseProxyConfigGeolocation",
"ProxiesUnionMember1ExternalProxyConfig",
]


@@ -42,12 +38,15 @@ class SessionCreateParams(TypedDict, total=False):
This is available on the Startup plan only.
"""

proxies: Union[bool, Iterable[ProxiesUnionMember1]]
proxies: object
"""Proxy configuration.
Can be true for default proxy, or an array of proxy configurations.
"""

region: Literal["us-west-2", "us-east-1", "eu-central-1", "ap-southeast-1"]
"""The region where the Session should run."""

api_timeout: Annotated[int, PropertyInfo(alias="timeout")]
"""Duration in seconds after which the session will automatically end.
@@ -59,7 +58,7 @@ class BrowserSettingsContext(TypedDict, total=False):
id: Required[str]
"""The Context ID."""

persist: Required[bool]
persist: bool
"""Whether or not to persist the context after browsing. Defaults to `false`."""


@@ -131,56 +130,3 @@ class BrowserSettings(TypedDict, total=False):
"""Enable or disable captcha solving in the browser. Defaults to `true`."""

viewport: BrowserSettingsViewport


class ProxiesUnionMember1BrowserbaseProxyConfigGeolocation(TypedDict, total=False):
country: Required[str]
"""Country code in ISO 3166-1 alpha-2 format"""

city: str
"""Name of the city. Use spaces for multi-word city names. Optional."""

state: str
"""US state code (2 characters). Must also specify US as the country. Optional."""


class ProxiesUnionMember1BrowserbaseProxyConfig(TypedDict, total=False):
type: Required[Literal["browserbase"]]
"""Type of proxy.
Always use 'browserbase' for the Browserbase managed proxy network.
"""

domain_pattern: Annotated[str, PropertyInfo(alias="domainPattern")]
"""Domain pattern for which this proxy should be used.
If omitted, defaults to all domains. Optional.
"""

geolocation: ProxiesUnionMember1BrowserbaseProxyConfigGeolocation
"""Configuration for geolocation"""


class ProxiesUnionMember1ExternalProxyConfig(TypedDict, total=False):
server: Required[str]
"""Server URL for external proxy. Required."""

type: Required[Literal["external"]]
"""Type of proxy. Always 'external' for this config."""

domain_pattern: Annotated[str, PropertyInfo(alias="domainPattern")]
"""Domain pattern for which this proxy should be used.
If omitted, defaults to all domains. Optional.
"""

password: str
"""Password for external proxy authentication. Optional."""

username: str
"""Username for external proxy authentication. Optional."""


ProxiesUnionMember1: TypeAlias = Union[
ProxiesUnionMember1BrowserbaseProxyConfig, ProxiesUnionMember1ExternalProxyConfig
]
57 changes: 57 additions & 0 deletions src/browserbase/types/session_create_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Optional
from datetime import datetime
from typing_extensions import Literal

from pydantic import Field as FieldInfo

from .._models import BaseModel

__all__ = ["SessionCreateResponse"]


class SessionCreateResponse(BaseModel):
id: str

connect_url: str = FieldInfo(alias="connectUrl")
"""WebSocket URL to connect to the Session."""

created_at: datetime = FieldInfo(alias="createdAt")

expires_at: datetime = FieldInfo(alias="expiresAt")

keep_alive: bool = FieldInfo(alias="keepAlive")
"""Indicates if the Session was created to be kept alive upon disconnections"""

project_id: str = FieldInfo(alias="projectId")
"""The Project ID linked to the Session."""

proxy_bytes: int = FieldInfo(alias="proxyBytes")
"""Bytes used via the [Proxy](/features/stealth-mode#proxies-and-residential-ips)"""

region: Literal["us-west-2", "us-east-1", "eu-central-1", "ap-southeast-1"]
"""The region where the Session is running."""

selenium_remote_url: str = FieldInfo(alias="seleniumRemoteUrl")
"""HTTP URL to connect to the Session."""

signing_key: str = FieldInfo(alias="signingKey")
"""Signing key to use when connecting to the Session via HTTP."""

started_at: datetime = FieldInfo(alias="startedAt")

status: Literal["RUNNING", "ERROR", "TIMED_OUT", "COMPLETED"]

updated_at: datetime = FieldInfo(alias="updatedAt")

avg_cpu_usage: Optional[int] = FieldInfo(alias="avgCpuUsage", default=None)
"""CPU used by the Session"""

context_id: Optional[str] = FieldInfo(alias="contextId", default=None)
"""Optional. The Context linked to the Session."""

ended_at: Optional[datetime] = FieldInfo(alias="endedAt", default=None)

memory_usage: Optional[int] = FieldInfo(alias="memoryUsage", default=None)
"""Memory used by the Session"""
23 changes: 13 additions & 10 deletions tests/api_resources/test_sessions.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
Session,
SessionLiveURLs,
SessionListResponse,
SessionCreateResponse,
)

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
@@ -26,7 +27,7 @@ def test_method_create(self, client: Browserbase) -> None:
session = client.sessions.create(
project_id="projectId",
)
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

@parametrize
def test_method_create_with_all_params(self, client: Browserbase) -> None:
@@ -62,10 +63,11 @@ def test_method_create_with_all_params(self, client: Browserbase) -> None:
},
extension_id="extensionId",
keep_alive=True,
proxies=True,
proxies={},
region="us-west-2",
api_timeout=60,
)
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

@parametrize
def test_raw_response_create(self, client: Browserbase) -> None:
@@ -76,7 +78,7 @@ def test_raw_response_create(self, client: Browserbase) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
session = response.parse()
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

@parametrize
def test_streaming_response_create(self, client: Browserbase) -> None:
@@ -87,7 +89,7 @@ def test_streaming_response_create(self, client: Browserbase) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

session = response.parse()
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

assert cast(Any, response.is_closed) is True

@@ -254,7 +256,7 @@ async def test_method_create(self, async_client: AsyncBrowserbase) -> None:
session = await async_client.sessions.create(
project_id="projectId",
)
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

@parametrize
async def test_method_create_with_all_params(self, async_client: AsyncBrowserbase) -> None:
@@ -290,10 +292,11 @@ async def test_method_create_with_all_params(self, async_client: AsyncBrowserbas
},
extension_id="extensionId",
keep_alive=True,
proxies=True,
proxies={},
region="us-west-2",
api_timeout=60,
)
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

@parametrize
async def test_raw_response_create(self, async_client: AsyncBrowserbase) -> None:
@@ -304,7 +307,7 @@ async def test_raw_response_create(self, async_client: AsyncBrowserbase) -> None
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
session = await response.parse()
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

@parametrize
async def test_streaming_response_create(self, async_client: AsyncBrowserbase) -> None:
@@ -315,7 +318,7 @@ async def test_streaming_response_create(self, async_client: AsyncBrowserbase) -
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

session = await response.parse()
assert_matches_type(Session, session, path=["response"])
assert_matches_type(SessionCreateResponse, session, path=["response"])

assert cast(Any, response.is_closed) is True