Skip to content
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
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 15
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brainbase-egrigokhan%2Fbrainbase-a197a88d1abbdbd5c886875d2cf12ffd6abf79aec7d4dbd0439ed50197692eba.yml
configured_endpoints: 14
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brainbase-egrigokhan%2Fbrainbase-0c00485d66a3b7505f3247467ef293fa5fb43a64e90a8b03a4127a2d9b15e6ab.yml
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import os
from brainbase import Brainbase

client = Brainbase(
bearer_token=os.environ.get("BEARER_TOKEN"), # This is the default and can be omitted
api_key=os.environ.get("API_KEY"), # This is the default and can be omitted
)

client.workers.list()
```

While you can provide a `bearer_token` keyword argument,
While you can provide an `api_key` keyword argument,
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
to add `BEARER_TOKEN="My Bearer Token"` to your `.env` file
so that your Bearer Token is not stored in source control.
to add `API_KEY="My API Key"` to your `.env` file
so that your API Key is not stored in source control.

## Async usage

Expand All @@ -49,7 +49,7 @@ import asyncio
from brainbase import AsyncBrainbase

client = AsyncBrainbase(
bearer_token=os.environ.get("BEARER_TOKEN"), # This is the default and can be omitted
api_key=os.environ.get("API_KEY"), # This is the default and can be omitted
)


Expand Down
5 changes: 2 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

Methods:

- <code title="post /api/workers">client.workers.<a href="./src/brainbase/resources/workers/workers.py">create</a>(\*\*<a href="src/brainbase/types/worker_create_params.py">params</a>) -> None</code>
- <code title="post /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">create</a>(id, \*\*<a href="src/brainbase/types/worker_create_params.py">params</a>) -> None</code>
- <code title="get /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">retrieve</a>(id) -> None</code>
- <code title="get /api/workers">client.workers.<a href="./src/brainbase/resources/workers/workers.py">list</a>() -> None</code>
- <code title="post /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">create_id</a>(id, \*\*<a href="src/brainbase/types/worker_create_id_params.py">params</a>) -> None</code>
- <code title="delete /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">delete_id</a>(id) -> None</code>
- <code title="delete /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">delete</a>(id) -> None</code>

## Deployments

Expand Down
48 changes: 24 additions & 24 deletions src/brainbase/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class Brainbase(SyncAPIClient):
with_streaming_response: BrainbaseWithStreamedResponse

# client options
bearer_token: str
api_key: str

def __init__(
self,
*,
bearer_token: str | None = None,
api_key: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
Expand All @@ -78,15 +78,15 @@ def __init__(
) -> None:
"""Construct a new synchronous brainbase client instance.

This automatically infers the `bearer_token` argument from the `BEARER_TOKEN` environment variable if it is not provided.
This automatically infers the `api_key` argument from the `API_KEY` environment variable if it is not provided.
"""
if bearer_token is None:
bearer_token = os.environ.get("BEARER_TOKEN")
if bearer_token is None:
if api_key is None:
api_key = os.environ.get("API_KEY")
if api_key is None:
raise BrainbaseError(
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the BEARER_TOKEN environment variable"
"The api_key client option must be set either by passing api_key to the client or by setting the API_KEY environment variable"
)
self.bearer_token = bearer_token
self.api_key = api_key

if base_url is None:
base_url = os.environ.get("BRAINBASE_BASE_URL")
Expand Down Expand Up @@ -116,8 +116,8 @@ def qs(self) -> Querystring:
@property
@override
def auth_headers(self) -> dict[str, str]:
bearer_token = self.bearer_token
return {"Authorization": f"Bearer {bearer_token}"}
api_key = self.api_key
return {"x-api-key": api_key}

@property
@override
Expand All @@ -131,7 +131,7 @@ def default_headers(self) -> dict[str, str | Omit]:
def copy(
self,
*,
bearer_token: str | None = None,
api_key: str | 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 @@ -165,7 +165,7 @@ def copy(

http_client = http_client or self._client
return self.__class__(
bearer_token=bearer_token or self.bearer_token,
api_key=api_key or self.api_key,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
Expand Down Expand Up @@ -219,12 +219,12 @@ class AsyncBrainbase(AsyncAPIClient):
with_streaming_response: AsyncBrainbaseWithStreamedResponse

# client options
bearer_token: str
api_key: str

def __init__(
self,
*,
bearer_token: str | None = None,
api_key: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
Expand All @@ -246,15 +246,15 @@ def __init__(
) -> None:
"""Construct a new async brainbase client instance.

This automatically infers the `bearer_token` argument from the `BEARER_TOKEN` environment variable if it is not provided.
This automatically infers the `api_key` argument from the `API_KEY` environment variable if it is not provided.
"""
if bearer_token is None:
bearer_token = os.environ.get("BEARER_TOKEN")
if bearer_token is None:
if api_key is None:
api_key = os.environ.get("API_KEY")
if api_key is None:
raise BrainbaseError(
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the BEARER_TOKEN environment variable"
"The api_key client option must be set either by passing api_key to the client or by setting the API_KEY environment variable"
)
self.bearer_token = bearer_token
self.api_key = api_key

if base_url is None:
base_url = os.environ.get("BRAINBASE_BASE_URL")
Expand Down Expand Up @@ -284,8 +284,8 @@ def qs(self) -> Querystring:
@property
@override
def auth_headers(self) -> dict[str, str]:
bearer_token = self.bearer_token
return {"Authorization": f"Bearer {bearer_token}"}
api_key = self.api_key
return {"x-api-key": api_key}

@property
@override
Expand All @@ -299,7 +299,7 @@ def default_headers(self) -> dict[str, str | Omit]:
def copy(
self,
*,
bearer_token: str | None = None,
api_key: str | 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 @@ -333,7 +333,7 @@ def copy(

http_client = http_client or self._client
return self.__class__(
bearer_token=bearer_token or self.bearer_token,
api_key=api_key or self.api_key,
base_url=base_url or self.base_url,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
Expand Down
Loading