diff --git a/.stats.yml b/.stats.yml index 571d6bb0..681b4257 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 15 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brainbase-egrigokhan%2Fbrainbase-0c00485d66a3b7505f3247467ef293fa5fb43a64e90a8b03a4127a2d9b15e6ab.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brainbase-egrigokhan%2Fbrainbase-a197a88d1abbdbd5c886875d2cf12ffd6abf79aec7d4dbd0439ed50197692eba.yml diff --git a/README.md b/README.md index 354cab72..0868a8cb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It is generated with [Stainless](https://www.stainlessapi.com/). ## Documentation -The REST API documentation can be found on [docs.usebrainbase.xyz](https://docs.usebrainbase.xyz). The full API of this library can be found in [api.md](api.md). +The REST API documentation can be found on [docs.brainbase.com](https://docs.brainbase.com). The full API of this library can be found in [api.md](api.md). ## Installation @@ -24,32 +24,25 @@ 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=os.environ.get("BRAINBASE_API_KEY"), # This is the default and can be omitted + api_key="My API Key", ) 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=os.environ.get("BRAINBASE_API_KEY"), # This is the default and can be omitted + api_key="My API Key", ) @@ -84,7 +77,9 @@ All errors inherit from `brainbase.APIError`. import brainbase from brainbase import Brainbase -client = Brainbase() +client = Brainbase( + api_key="My API Key", +) try: client.workers.list() @@ -127,6 +122,7 @@ from brainbase import Brainbase client = Brainbase( # default is 2 max_retries=0, + api_key="My API Key", ) # Or, configure per-request: @@ -145,11 +141,13 @@ 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: @@ -193,7 +191,9 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to ```py from brainbase import Brainbase -client = Brainbase() +client = Brainbase( + api_key="My API Key", +) response = client.workers.with_raw_response.list() print(response.headers.get('X-My-Header')) @@ -274,6 +274,7 @@ client = Brainbase( proxy="http://my.test.proxy.example.com", transport=httpx.HTTPTransport(local_address="0.0.0.0"), ), + api_key="My API Key", ) ``` @@ -290,7 +291,9 @@ By default the library closes underlying HTTP connections whenever the client is ```py from brainbase import Brainbase -with Brainbase() as client: +with Brainbase( + api_key="My API Key", +) as client: # make requests here ... diff --git a/src/brainbase/_client.py b/src/brainbase/_client.py index 9192a946..bbe9a56d 100644 --- a/src/brainbase/_client.py +++ b/src/brainbase/_client.py @@ -113,12 +113,6 @@ 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]: @@ -281,12 +275,6 @@ 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]: diff --git a/tests/test_client.py b/tests/test_client.py index 4bf71630..c4074ec6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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, BrainbaseError, APITimeoutError, APIResponseValidationError +from brainbase._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError from brainbase._base_client import ( DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, @@ -334,16 +334,6 @@ 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"} @@ -1090,16 +1080,6 @@ 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"}