Skip to content

chore(toolbox-core): deprecate add_headers feature #278

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 12 commits into from
Jun 11, 2025
Merged
23 changes: 7 additions & 16 deletions packages/toolbox-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,15 @@ that fresh credentials or header values can be used.

### Configuration

You can configure these dynamic headers in two ways:
You can configure these dynamic headers as seen below:

1. **During Client Initialization**

```python
from toolbox_core import ToolboxClient

async with ToolboxClient("toolbox-url", client_headers={"header1": header1_getter, "header2": header2_getter, ...}) as client:
```

1. **After Client Initialization**

```python
from toolbox_core import ToolboxClient
```python
from toolbox_core import ToolboxClient

async with ToolboxClient("toolbox-url") as client:
client.add_headers({"header1": header1_getter, "header2": header2_getter, ...})
```
async with ToolboxClient("toolbox-url", client_headers={"header1": header1_getter, "header2": header2_getter, ...}) as client:
# Use client
pass
```

### Authenticating with Google Cloud Servers

Expand Down
1 change: 1 addition & 0 deletions packages/toolbox-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors = [
dependencies = [
"pydantic>=2.7.0,<3.0.0",
"aiohttp>=3.8.6,<4.0.0",
"deprecated>=1.2.15,<2.0.0",
]

classifiers = [
Expand Down
1 change: 1 addition & 0 deletions packages/toolbox-core/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
aiohttp==3.12.12
pydantic==2.11.5
deprecated==1.2.15
6 changes: 4 additions & 2 deletions packages/toolbox-core/src/toolbox_core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import Any, Awaitable, Callable, Mapping, Optional, Union

from aiohttp import ClientSession
from deprecated import deprecated

from .protocol import ManifestSchema, ToolSchema
from .tool import ToolboxTool
Expand Down Expand Up @@ -340,16 +341,17 @@ async def load_toolset(

return tools

@deprecated(
"Use the `client_headers` parameter in the ToolboxClient constructor instead."
)
def add_headers(
self,
headers: Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]]]],
) -> None:
"""
Add headers to be included in each request sent through this client.

Args:
headers: Headers to include in each request sent through this client.

Raises:
ValueError: If any of the headers are already registered in the client.
"""
Expand Down
5 changes: 5 additions & 0 deletions packages/toolbox-core/src/toolbox_core/sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from threading import Thread
from typing import Any, Awaitable, Callable, Mapping, Optional, Union

from deprecated import deprecated

from .client import ToolboxClient
from .sync_tool import ToolboxSyncTool

Expand Down Expand Up @@ -153,6 +155,9 @@ def load_toolset(
for async_tool in async_tools
]

@deprecated(
"Use the `client_headers` parameter in the ToolboxClient constructor instead."
)
def add_headers(
self,
headers: Mapping[
Expand Down