diff --git a/README.md b/README.md
index fe9edc6f..0868a8cb 100644
--- a/README.md
+++ b/README.md
@@ -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("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 `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("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/api.md b/api.md
index 77b07ee9..6f634335 100644
--- a/api.md
+++ b/api.md
@@ -2,7 +2,7 @@
Methods:
-- client.workers.create(id, \*\*params) -> None
+- client.workers.create(\*\*params) -> None
- client.workers.retrieve(id) -> None
- client.workers.list() -> None
- client.workers.delete(id) -> None
diff --git a/src/brainbase/_client.py b/src/brainbase/_client.py
index c42e10d6..ad7c930e 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/src/brainbase/resources/workers/workers.py b/src/brainbase/resources/workers/workers.py
index eb3d3e1c..9d2eb83c 100644
--- a/src/brainbase/resources/workers/workers.py
+++ b/src/brainbase/resources/workers/workers.py
@@ -69,10 +69,9 @@ def with_streaming_response(self) -> WorkersResourceWithStreamingResponse:
def create(
self,
- id: str,
*,
+ name: str,
description: str | NotGiven = NOT_GIVEN,
- name: str | NotGiven = NOT_GIVEN,
status: str | 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.
@@ -82,7 +81,7 @@ def create(
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> None:
"""
- Update a worker
+ Create a new worker
Args:
extra_headers: Send extra headers
@@ -93,15 +92,13 @@ def create(
timeout: Override the client-level default timeout for this request, in seconds
"""
- if not id:
- raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return self._post(
- f"/api/workers/{id}",
+ "/api/workers",
body=maybe_transform(
{
- "description": description,
"name": name,
+ "description": description,
"status": status,
},
worker_create_params.WorkerCreateParams,
@@ -231,10 +228,9 @@ def with_streaming_response(self) -> AsyncWorkersResourceWithStreamingResponse:
async def create(
self,
- id: str,
*,
+ name: str,
description: str | NotGiven = NOT_GIVEN,
- name: str | NotGiven = NOT_GIVEN,
status: str | 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.
@@ -244,7 +240,7 @@ async def create(
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> None:
"""
- Update a worker
+ Create a new worker
Args:
extra_headers: Send extra headers
@@ -255,15 +251,13 @@ async def create(
timeout: Override the client-level default timeout for this request, in seconds
"""
- if not id:
- raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
return await self._post(
- f"/api/workers/{id}",
+ "/api/workers",
body=await async_maybe_transform(
{
- "description": description,
"name": name,
+ "description": description,
"status": status,
},
worker_create_params.WorkerCreateParams,
diff --git a/src/brainbase/types/worker_create_params.py b/src/brainbase/types/worker_create_params.py
index f84e516c..757c0420 100644
--- a/src/brainbase/types/worker_create_params.py
+++ b/src/brainbase/types/worker_create_params.py
@@ -2,14 +2,14 @@
from __future__ import annotations
-from typing_extensions import TypedDict
+from typing_extensions import Required, TypedDict
__all__ = ["WorkerCreateParams"]
class WorkerCreateParams(TypedDict, total=False):
- description: str
+ name: Required[str]
- name: str
+ description: str
status: str
diff --git a/tests/api_resources/test_workers.py b/tests/api_resources/test_workers.py
index a6c4d926..5f524f47 100644
--- a/tests/api_resources/test_workers.py
+++ b/tests/api_resources/test_workers.py
@@ -19,7 +19,7 @@ class TestWorkers:
@parametrize
def test_method_create(self, client: Brainbase) -> None:
worker = client.workers.create(
- id="id",
+ name="name",
)
assert worker is None
@@ -27,9 +27,8 @@ def test_method_create(self, client: Brainbase) -> None:
@parametrize
def test_method_create_with_all_params(self, client: Brainbase) -> None:
worker = client.workers.create(
- id="id",
- description="description",
name="name",
+ description="description",
status="status",
)
assert worker is None
@@ -38,7 +37,7 @@ def test_method_create_with_all_params(self, client: Brainbase) -> None:
@parametrize
def test_raw_response_create(self, client: Brainbase) -> None:
response = client.workers.with_raw_response.create(
- id="id",
+ name="name",
)
assert response.is_closed is True
@@ -50,7 +49,7 @@ def test_raw_response_create(self, client: Brainbase) -> None:
@parametrize
def test_streaming_response_create(self, client: Brainbase) -> None:
with client.workers.with_streaming_response.create(
- id="id",
+ name="name",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -60,14 +59,6 @@ def test_streaming_response_create(self, client: Brainbase) -> None:
assert cast(Any, response.is_closed) is True
- @pytest.mark.skip()
- @parametrize
- def test_path_params_create(self, client: Brainbase) -> None:
- with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"):
- client.workers.with_raw_response.create(
- id="",
- )
-
@pytest.mark.skip()
@parametrize
def test_method_retrieve(self, client: Brainbase) -> None:
@@ -188,7 +179,7 @@ class TestAsyncWorkers:
@parametrize
async def test_method_create(self, async_client: AsyncBrainbase) -> None:
worker = await async_client.workers.create(
- id="id",
+ name="name",
)
assert worker is None
@@ -196,9 +187,8 @@ async def test_method_create(self, async_client: AsyncBrainbase) -> None:
@parametrize
async def test_method_create_with_all_params(self, async_client: AsyncBrainbase) -> None:
worker = await async_client.workers.create(
- id="id",
- description="description",
name="name",
+ description="description",
status="status",
)
assert worker is None
@@ -207,7 +197,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncBrainbase)
@parametrize
async def test_raw_response_create(self, async_client: AsyncBrainbase) -> None:
response = await async_client.workers.with_raw_response.create(
- id="id",
+ name="name",
)
assert response.is_closed is True
@@ -219,7 +209,7 @@ async def test_raw_response_create(self, async_client: AsyncBrainbase) -> None:
@parametrize
async def test_streaming_response_create(self, async_client: AsyncBrainbase) -> None:
async with async_client.workers.with_streaming_response.create(
- id="id",
+ name="name",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -229,14 +219,6 @@ async def test_streaming_response_create(self, async_client: AsyncBrainbase) ->
assert cast(Any, response.is_closed) is True
- @pytest.mark.skip()
- @parametrize
- async def test_path_params_create(self, async_client: AsyncBrainbase) -> None:
- with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"):
- await async_client.workers.with_raw_response.create(
- id="",
- )
-
@pytest.mark.skip()
@parametrize
async def test_method_retrieve(self, async_client: AsyncBrainbase) -> None:
diff --git a/tests/test_client.py b/tests/test_client.py
index c3570edb..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(**{"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(**{"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"}