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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.7.0"
".": "1.8.0"
}
2 changes: 1 addition & 1 deletion .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
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brainbase-egrigokhan%2Fbrainbase-0c00485d66a3b7505f3247467ef293fa5fb43a64e90a8b03a4127a2d9b15e6ab.yml
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.8.0 (2025-02-04)

Full Changelog: [v1.7.0...v1.8.0](https://github.com/BrainbaseHQ/brainbase-python-sdk/compare/v1.7.0...v1.8.0)

### Features

* **api:** update via SDK Studio ([#35](https://github.com/BrainbaseHQ/brainbase-python-sdk/issues/35)) ([7dd48a6](https://github.com/BrainbaseHQ/brainbase-python-sdk/commit/7dd48a6db45effaa20e9a3263d3c0b9b4803bef3))

## 1.7.0 (2025-02-04)

Full Changelog: [v1.6.0...v1.7.0](https://github.com/BrainbaseHQ/brainbase-python-sdk/compare/v1.6.0...v1.7.0)
Expand Down
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,32 @@ pip install brainbase-labs
The full API of this library can be found in [api.md](api.md).

```python
import os
from brainbase import Brainbase

client = Brainbase(
api_key="My API Key",
api_key=os.environ.get("BRAINBASE_API_KEY"), # This is the default and can be omitted
)

client.workers.list()
```

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

## Async usage

Simply import `AsyncBrainbase` instead of `Brainbase` and use `await` with each API call:

```python
import os
import asyncio
from brainbase import AsyncBrainbase

client = AsyncBrainbase(
api_key="My API Key",
api_key=os.environ.get("BRAINBASE_API_KEY"), # This is the default and can be omitted
)


Expand Down Expand Up @@ -77,9 +84,7 @@ All errors inherit from `brainbase.APIError`.
import brainbase
from brainbase import Brainbase

client = Brainbase(
api_key="My API Key",
)
client = Brainbase()

try:
client.workers.list()
Expand Down Expand Up @@ -122,7 +127,6 @@ from brainbase import Brainbase
client = Brainbase(
# default is 2
max_retries=0,
api_key="My API Key",
)

# Or, configure per-request:
Expand All @@ -141,13 +145,11 @@ from brainbase import Brainbase
client = Brainbase(
# 20 seconds (default is 1 minute)
timeout=20.0,
api_key="My API Key",
)

# More granular control:
client = Brainbase(
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
api_key="My API Key",
)

# Override per-request:
Expand Down Expand Up @@ -191,9 +193,7 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
```py
from brainbase import Brainbase

client = Brainbase(
api_key="My API Key",
)
client = Brainbase()
response = client.workers.with_raw_response.list()
print(response.headers.get('X-My-Header'))

Expand Down Expand Up @@ -274,7 +274,6 @@ client = Brainbase(
proxy="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
api_key="My API Key",
)
```

Expand All @@ -291,9 +290,7 @@ By default the library closes underlying HTTP connections whenever the client is
```py
from brainbase import Brainbase

with Brainbase(
api_key="My API Key",
) as client:
with Brainbase() as client:
# make requests here
...

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "brainbase-labs"
version = "1.7.0"
version = "1.8.0"
description = "The official Python library for the brainbase API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
12 changes: 12 additions & 0 deletions src/brainbase/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def __init__(
def qs(self) -> Querystring:
return Querystring(array_format="comma")

@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
return {"x-api-key": api_key}

@property
@override
def default_headers(self) -> dict[str, str | Omit]:
Expand Down Expand Up @@ -275,6 +281,12 @@ def __init__(
def qs(self) -> Querystring:
return Querystring(array_format="comma")

@property
@override
def auth_headers(self) -> dict[str, str]:
api_key = self.api_key
return {"x-api-key": api_key}

@property
@override
def default_headers(self) -> dict[str, str | Omit]:
Expand Down
2 changes: 1 addition & 1 deletion src/brainbase/_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__ = "brainbase"
__version__ = "1.7.0" # x-release-please-version
__version__ = "1.8.0" # x-release-please-version
22 changes: 21 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from brainbase._types import Omit
from brainbase._models import BaseModel, FinalRequestOptions
from brainbase._constants import RAW_RESPONSE_HEADER
from brainbase._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
from brainbase._exceptions import APIStatusError, BrainbaseError, APITimeoutError, APIResponseValidationError
from brainbase._base_client import (
DEFAULT_TIMEOUT,
HTTPX_DEFAULT_TIMEOUT,
Expand Down Expand Up @@ -334,6 +334,16 @@ def test_default_headers_option(self) -> None:
assert request.headers.get("x-foo") == "stainless"
assert request.headers.get("x-stainless-lang") == "my-overriding-header"

def test_validate_headers(self) -> None:
client = Brainbase(base_url=base_url, api_key=api_key, _strict_response_validation=True)
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
assert request.headers.get("x-api-key") == api_key

with pytest.raises(BrainbaseError):
with update_env(**{"BRAINBASE_API_KEY": Omit()}):
client2 = Brainbase(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2

def test_default_query_option(self) -> None:
client = Brainbase(
base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"}
Expand Down Expand Up @@ -1080,6 +1090,16 @@ def test_default_headers_option(self) -> None:
assert request.headers.get("x-foo") == "stainless"
assert request.headers.get("x-stainless-lang") == "my-overriding-header"

def test_validate_headers(self) -> None:
client = AsyncBrainbase(base_url=base_url, api_key=api_key, _strict_response_validation=True)
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
assert request.headers.get("x-api-key") == api_key

with pytest.raises(BrainbaseError):
with update_env(**{"BRAINBASE_API_KEY": Omit()}):
client2 = AsyncBrainbase(base_url=base_url, api_key=None, _strict_response_validation=True)
_ = client2

def test_default_query_option(self) -> None:
client = AsyncBrainbase(
base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"}
Expand Down