Skip to content
Open
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
12 changes: 10 additions & 2 deletions tavily/tavily.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,15 @@ class Client(TavilyClient):
WARNING! This class is deprecated. Please use TavilyClient instead.
"""

def __init__(self, kwargs):
def __init__(self, kwargs=None, **legacy_kwargs):
warnings.warn("Client is deprecated, please use TavilyClient instead",
DeprecationWarning, stacklevel=2)
super().__init__(kwargs)

if isinstance(kwargs, dict):
init_kwargs = {**kwargs, **legacy_kwargs}
elif kwargs is not None:
init_kwargs = {"api_key": kwargs, **legacy_kwargs}
else:
init_kwargs = legacy_kwargs

super().__init__(**init_kwargs)
14 changes: 14 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@ def test_invalid_api_key():
with pytest.raises(InvalidAPIKeyError):
print(async_tavily.httpx.AsyncClient.post)
print(asyncio.run(async_tavily.AsyncTavilyClient(api_key="invalid_api_key").search("What is Tavily?")))


def test_deprecated_client_accepts_keyword_args():
with pytest.warns(DeprecationWarning):
client = sync_tavily.Client(api_key="tvly-test")
assert client.api_key == "tvly-test"
client.close()


def test_deprecated_client_accepts_legacy_dict_kwargs():
with pytest.warns(DeprecationWarning):
client = sync_tavily.Client({"api_key": "tvly-test"})
assert client.api_key == "tvly-test"
client.close()