Skip to content

release: 0.1.0-alpha.7 #37

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 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
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 .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.6"
".": "0.1.0-alpha.7"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.7 (2024-10-28)

Full Changelog: [v0.1.0-alpha.6...v0.1.0-alpha.7](https://github.com/browserbase/sdk-python/compare/v0.1.0-alpha.6...v0.1.0-alpha.7)

### Features

* **api:** update via SDK Studio ([#35](https://github.com/browserbase/sdk-python/issues/35)) ([c694662](https://github.com/browserbase/sdk-python/commit/c69466218e105b524b4ad98208283b96eccf056d))

## 0.1.0-alpha.6 (2024-10-28)

Full Changelog: [v0.1.0-alpha.5...v0.1.0-alpha.6](https://github.com/browserbase/sdk-python/compare/v0.1.0-alpha.5...v0.1.0-alpha.6)
Expand Down
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ BROWSERBASE_PROJECT_ID = os.environ.get("BROWSERBASE_PROJECT_ID")
bb = Browserbase(
# This is the default and can be omitted
api_key=BROWSERBASE_API_KEY,
# or 'production' | 'local'; defaults to "production".
environment="development",
)

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

def run(playwright: Playwright) -> None:
# Connect to the remote session
chromium = playwright.chromium
browser = chromium.connect_over_cdp(session.connect_url)
Expand All @@ -67,9 +68,7 @@ def run(playwright: Playwright) -> None:
if __name__ == "__main__":
with sync_playwright() as playwright:
run(playwright)

```

## Examples

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

try:
client.contexts.create(
project_id="projectId",
client.sessions.create(
project_id="your_project_id",
proxies=True,
)
except browserbase.APIConnectionError as e:
print("The server could not be reached")
Expand Down Expand Up @@ -157,8 +157,9 @@ client = Browserbase(
)

# Or, configure per-request:
client.with_options(max_retries=5).contexts.create(
project_id="projectId",
client.with_options(max_retries=5).sessions.create(
project_id="your_project_id",
proxies=True,
)
```

Expand All @@ -182,8 +183,9 @@ client = Browserbase(
)

# Override per-request:
client.with_options(timeout=5.0).contexts.create(
project_id="projectId",
client.with_options(timeout=5.0).sessions.create(
project_id="your_project_id",
proxies=True,
)
```

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

client = Browserbase()
response = client.contexts.with_raw_response.create(
project_id="projectId",
response = client.sessions.with_raw_response.create(
project_id="your_project_id",
proxies=True,
)
print(response.headers.get('X-My-Header'))

context = response.parse() # get the object that `contexts.create()` would have returned
print(context.id)
session = response.parse() # get the object that `sessions.create()` would have returned
print(session.id)
```

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

```python
with client.contexts.with_streaming_response.create(
project_id="projectId",
with client.sessions.with_streaming_response.create(
project_id="your_project_id",
proxies=True,
) as response:
print(response.headers.get("X-My-Header"))

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ or products provided by Browserbase please follow the respective company's secur

### Browserbase Terms and Policies

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

---

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[project]
name = "browserbase"
version = "0.1.0-alpha.6"
description = "The official Python library for the browserbase API"
version = "0.1.0-alpha.7"
description = "The official Python library for the Browserbase API"
dynamic = ["readme"]
license = "Apache-2.0"
authors = [
{ name = "Browserbase", email = "dev-feedback@browserbase.com" },
{ name = "Browserbase", email = "support@browserbase.com" },
]
dependencies = [
"httpx>=0.23.0, <1",
Expand Down
2 changes: 0 additions & 2 deletions src/browserbase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from ._types import NOT_GIVEN, NoneType, NotGiven, Transport, ProxiesTypes
from ._utils import file_from_path
from ._client import (
ENVIRONMENTS,
Client,
Stream,
Timeout,
Expand Down Expand Up @@ -69,7 +68,6 @@
"AsyncStream",
"Browserbase",
"AsyncBrowserbase",
"ENVIRONMENTS",
"file_from_path",
"BaseModel",
"DEFAULT_TIMEOUT",
Expand Down
87 changes: 14 additions & 73 deletions src/browserbase/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from __future__ import annotations

import os
from typing import Any, Dict, Union, Mapping, cast
from typing_extensions import Self, Literal, override
from typing import Any, Union, Mapping
from typing_extensions import Self, override

import httpx

Expand Down Expand Up @@ -33,7 +33,6 @@
)

__all__ = [
"ENVIRONMENTS",
"Timeout",
"Transport",
"ProxiesTypes",
Expand All @@ -45,12 +44,6 @@
"AsyncClient",
]

ENVIRONMENTS: Dict[str, str] = {
"production": "https://api.browserbase.com",
"development": "https://api.dev.browserbase.com",
"local": "http://api.localhost",
}


class Browserbase(SyncAPIClient):
contexts: resources.ContextsResource
Expand All @@ -63,14 +56,11 @@ class Browserbase(SyncAPIClient):
# client options
api_key: str

_environment: Literal["production", "development", "local"] | NotGiven

def __init__(
self,
*,
api_key: str | None = None,
environment: Literal["production", "development", "local"] | NotGiven = NOT_GIVEN,
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
Expand All @@ -89,7 +79,7 @@ def __init__(
# part of our public interface in the future.
_strict_response_validation: bool = False,
) -> None:
"""Construct a new synchronous browserbase client instance.
"""Construct a new synchronous Browserbase client instance.

This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
"""
Expand All @@ -101,31 +91,10 @@ def __init__(
)
self.api_key = api_key

self._environment = environment

base_url_env = os.environ.get("BROWSERBASE_BASE_URL")
if is_given(base_url) and base_url is not None:
# cast required because mypy doesn't understand the type narrowing
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
elif is_given(environment):
if base_url_env and base_url is not None:
raise ValueError(
"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",
)

try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
elif base_url_env is not None:
base_url = base_url_env
else:
self._environment = environment = "production"

try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
if base_url is None:
base_url = os.environ.get("BROWSERBASE_BASE_URL")
if base_url is None:
base_url = f"https://api.browserbase.com"

super().__init__(
version=__version__,
Expand Down Expand Up @@ -169,7 +138,6 @@ def copy(
self,
*,
api_key: str | None = None,
environment: Literal["production", "development", "local"] | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.Client | None = None,
Expand Down Expand Up @@ -205,7 +173,6 @@ def copy(
return self.__class__(
api_key=api_key or self.api_key,
base_url=base_url or self.base_url,
environment=environment or self._environment,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
Expand Down Expand Up @@ -263,14 +230,11 @@ class AsyncBrowserbase(AsyncAPIClient):
# client options
api_key: str

_environment: Literal["production", "development", "local"] | NotGiven

def __init__(
self,
*,
api_key: str | None = None,
environment: Literal["production", "development", "local"] | NotGiven = NOT_GIVEN,
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
Expand All @@ -289,7 +253,7 @@ def __init__(
# part of our public interface in the future.
_strict_response_validation: bool = False,
) -> None:
"""Construct a new async browserbase client instance.
"""Construct a new async Browserbase client instance.

This automatically infers the `api_key` argument from the `BROWSERBASE_API_KEY` environment variable if it is not provided.
"""
Expand All @@ -301,31 +265,10 @@ def __init__(
)
self.api_key = api_key

self._environment = environment

base_url_env = os.environ.get("BROWSERBASE_BASE_URL")
if is_given(base_url) and base_url is not None:
# cast required because mypy doesn't understand the type narrowing
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
elif is_given(environment):
if base_url_env and base_url is not None:
raise ValueError(
"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",
)

try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
elif base_url_env is not None:
base_url = base_url_env
else:
self._environment = environment = "production"

try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
if base_url is None:
base_url = os.environ.get("BROWSERBASE_BASE_URL")
if base_url is None:
base_url = f"https://api.browserbase.com"

super().__init__(
version=__version__,
Expand Down Expand Up @@ -369,7 +312,6 @@ def copy(
self,
*,
api_key: str | None = None,
environment: Literal["production", "development", "local"] | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.AsyncClient | None = None,
Expand Down Expand Up @@ -405,7 +347,6 @@ def copy(
return self.__class__(
api_key=api_key or self.api_key,
base_url=base_url or self.base_url,
environment=environment or self._environment,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
Expand Down
2 changes: 1 addition & 1 deletion src/browserbase/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "browserbase"
__version__ = "0.1.0-alpha.6" # x-release-please-version
__version__ = "0.1.0-alpha.7" # x-release-please-version
Loading
Loading