Skip to content

Commit 6076bcb

Browse files
SDK regeneration (#44)
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
1 parent 48ec74b commit 6076bcb

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "credal"
33

44
[tool.poetry]
55
name = "credal"
6-
version = "0.0.28"
6+
version = "0.0.29"
77
description = ""
88
readme = "README.md"
99
authors = []
@@ -38,7 +38,7 @@ python = "^3.8"
3838
httpx = ">=0.21.2"
3939
httpx-sse = "0.4.0"
4040
pydantic = ">= 1.9.2"
41-
pydantic-core = "^2.18.2"
41+
pydantic-core = ">=2.18.2"
4242
typing_extensions = ">= 4.0.0"
4343

4444
[tool.poetry.group.dev.dependencies]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
httpx>=0.21.2
22
httpx-sse==0.4.0
33
pydantic>= 1.9.2
4-
pydantic-core==2.18.2
4+
pydantic-core>=2.18.2
55
typing_extensions>= 4.0.0

src/credal/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class CredalApi:
3434
3535
3636
api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
37+
headers : typing.Optional[typing.Dict[str, str]]
38+
Additional headers to send with every request.
39+
3740
timeout : typing.Optional[float]
3841
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
3942
@@ -58,6 +61,7 @@ def __init__(
5861
base_url: typing.Optional[str] = None,
5962
environment: CredalApiEnvironment = CredalApiEnvironment.PRODUCTION,
6063
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CREDAL_API_KEY"),
64+
headers: typing.Optional[typing.Dict[str, str]] = None,
6165
timeout: typing.Optional[float] = None,
6266
follow_redirects: typing.Optional[bool] = True,
6367
httpx_client: typing.Optional[httpx.Client] = None,
@@ -72,6 +76,7 @@ def __init__(
7276
self._client_wrapper = SyncClientWrapper(
7377
base_url=_get_base_url(base_url=base_url, environment=environment),
7478
api_key=api_key,
79+
headers=headers,
7580
httpx_client=httpx_client
7681
if httpx_client is not None
7782
else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
@@ -106,6 +111,9 @@ class AsyncCredalApi:
106111
107112
108113
api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
114+
headers : typing.Optional[typing.Dict[str, str]]
115+
Additional headers to send with every request.
116+
109117
timeout : typing.Optional[float]
110118
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
111119
@@ -130,6 +138,7 @@ def __init__(
130138
base_url: typing.Optional[str] = None,
131139
environment: CredalApiEnvironment = CredalApiEnvironment.PRODUCTION,
132140
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CREDAL_API_KEY"),
141+
headers: typing.Optional[typing.Dict[str, str]] = None,
133142
timeout: typing.Optional[float] = None,
134143
follow_redirects: typing.Optional[bool] = True,
135144
httpx_client: typing.Optional[httpx.AsyncClient] = None,
@@ -144,6 +153,7 @@ def __init__(
144153
self._client_wrapper = AsyncClientWrapper(
145154
base_url=_get_base_url(base_url=base_url, environment=environment),
146155
api_key=api_key,
156+
headers=headers,
147157
httpx_client=httpx_client
148158
if httpx_client is not None
149159
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)

src/credal/core/client_wrapper.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ def __init__(
1111
self,
1212
*,
1313
api_key: typing.Union[str, typing.Callable[[], str]],
14+
headers: typing.Optional[typing.Dict[str, str]] = None,
1415
base_url: str,
1516
timeout: typing.Optional[float] = None,
1617
):
1718
self._api_key = api_key
19+
self._headers = headers
1820
self._base_url = base_url
1921
self._timeout = timeout
2022

2123
def get_headers(self) -> typing.Dict[str, str]:
2224
headers: typing.Dict[str, str] = {
23-
"User-Agent": "credal/0.0.28",
25+
"User-Agent": "credal/0.0.29",
2426
"X-Fern-Language": "Python",
2527
"X-Fern-SDK-Name": "credal",
26-
"X-Fern-SDK-Version": "0.0.28",
28+
"X-Fern-SDK-Version": "0.0.29",
29+
**(self.get_custom_headers() or {}),
2730
}
2831
headers["Authorization"] = f"Bearer {self._get_api_key()}"
2932
return headers
@@ -34,6 +37,9 @@ def _get_api_key(self) -> str:
3437
else:
3538
return self._api_key()
3639

40+
def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]:
41+
return self._headers
42+
3743
def get_base_url(self) -> str:
3844
return self._base_url
3945

@@ -46,11 +52,12 @@ def __init__(
4652
self,
4753
*,
4854
api_key: typing.Union[str, typing.Callable[[], str]],
55+
headers: typing.Optional[typing.Dict[str, str]] = None,
4956
base_url: str,
5057
timeout: typing.Optional[float] = None,
5158
httpx_client: httpx.Client,
5259
):
53-
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
60+
super().__init__(api_key=api_key, headers=headers, base_url=base_url, timeout=timeout)
5461
self.httpx_client = HttpClient(
5562
httpx_client=httpx_client,
5663
base_headers=self.get_headers,
@@ -64,11 +71,12 @@ def __init__(
6471
self,
6572
*,
6673
api_key: typing.Union[str, typing.Callable[[], str]],
74+
headers: typing.Optional[typing.Dict[str, str]] = None,
6775
base_url: str,
6876
timeout: typing.Optional[float] = None,
6977
httpx_client: httpx.AsyncClient,
7078
):
71-
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
79+
super().__init__(api_key=api_key, headers=headers, base_url=base_url, timeout=timeout)
7280
self.httpx_client = AsyncHttpClient(
7381
httpx_client=httpx_client,
7482
base_headers=self.get_headers,

src/credal/core/pydantic_utilities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class UniversalBaseModel(pydantic.BaseModel):
5959
protected_namespaces=(),
6060
)
6161

62-
@pydantic.model_serializer(mode="wrap", when_used="json") # type: ignore[attr-defined]
63-
def serialize_model(self, handler: pydantic.SerializerFunctionWrapHandler) -> Any: # type: ignore[name-defined]
64-
serialized = handler(self)
62+
@pydantic.model_serializer(mode="plain", when_used="json") # type: ignore[attr-defined]
63+
def serialize_model(self) -> Any: # type: ignore[name-defined]
64+
serialized = self.model_dump()
6565
data = {k: serialize_datetime(v) if isinstance(v, dt.datetime) else v for k, v in serialized.items()}
6666
return data
6767

0 commit comments

Comments
 (0)