Skip to content

Commit 1c34bf3

Browse files
committed
feat: accept API key as pydantic.SecretStr
1 parent cdcba7f commit 1c34bf3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/linkup/_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any, Literal, Optional, Union
77

88
import httpx
9-
from pydantic import BaseModel
9+
from pydantic import BaseModel, SecretStr
1010

1111
from ._errors import (
1212
LinkupAuthenticationError,
@@ -42,16 +42,18 @@ class LinkupClient:
4242

4343
def __init__(
4444
self,
45-
api_key: Optional[str] = None,
45+
api_key: Union[str, SecretStr, None] = None,
4646
base_url: str = "https://api.linkup.so/v1",
4747
) -> None:
4848
if api_key is None:
4949
api_key = os.getenv("LINKUP_API_KEY")
5050
if not api_key:
5151
raise ValueError("The Linkup API key was not provided")
52+
if isinstance(api_key, str):
53+
api_key = SecretStr(api_key)
5254

53-
self._api_key = api_key
54-
self._base_url = base_url
55+
self._api_key: SecretStr = api_key
56+
self._base_url: str = base_url
5557

5658
def search(
5759
self,
@@ -332,7 +334,7 @@ def _user_agent(self) -> str: # pragma: no cover
332334

333335
def _headers(self) -> dict[str, str]: # pragma: no cover
334336
return {
335-
"Authorization": f"Bearer {self._api_key}",
337+
"Authorization": f"Bearer {self._api_key.get_secret_value()}",
336338
"User-Agent": self._user_agent(),
337339
}
338340

0 commit comments

Comments
 (0)