From cd269d05638ac18b006ced57194ca963dc9d3f26 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 23:41:49 +0000 Subject: [PATCH] SDK regeneration --- poetry.lock | 10 +++++----- pyproject.toml | 4 ++-- requirements.txt | 2 +- src/credal/client.py | 10 ++++++++++ src/credal/core/client_wrapper.py | 16 ++++++++++++---- src/credal/core/pydantic_utilities.py | 6 +++--- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/poetry.lock b/poetry.lock index 6a8c4dd..d29d247 100644 --- a/poetry.lock +++ b/poetry.lock @@ -38,13 +38,13 @@ trio = ["trio (>=0.26.1)"] [[package]] name = "certifi" -version = "2025.4.26" +version = "2025.6.15" description = "Python package for providing Mozilla's CA Bundle." optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "certifi-2025.4.26-py3-none-any.whl", hash = "sha256:30350364dfe371162649852c63336a15c70c6510c2ad5015b21c2345311805f3"}, - {file = "certifi-2025.4.26.tar.gz", hash = "sha256:0a816057ea3cdefcef70270d2c515e4506bbc954f417fa5ade2021213bb8f0c6"}, + {file = "certifi-2025.6.15-py3-none-any.whl", hash = "sha256:2e0c7ce7cb5d8f8634ca55d2ba7e6ec2689a2fd6537d8dec1296a477a4910057"}, + {file = "certifi-2025.6.15.tar.gz", hash = "sha256:d747aa5a8b9bbbb1bb8c22bb13e22bd1f18e9796defa16bab421f7f7a317323b"}, ] [[package]] @@ -558,4 +558,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "d39278e84d2af85466d79752e4adc65f6e091ba932380df7596969b5864c80c3" +content-hash = "3c4bf0b75d27d2ce3738ca3d6b64dfb03909c56fb8e280a98890abd4619134d8" diff --git a/pyproject.toml b/pyproject.toml index b376130..8a39a71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "credal" [tool.poetry] name = "credal" -version = "0.0.28" +version = "0.0.29" description = "" readme = "README.md" authors = [] @@ -38,7 +38,7 @@ python = "^3.8" httpx = ">=0.21.2" httpx-sse = "0.4.0" pydantic = ">= 1.9.2" -pydantic-core = "^2.18.2" +pydantic-core = ">=2.18.2" typing_extensions = ">= 4.0.0" [tool.poetry.group.dev.dependencies] diff --git a/requirements.txt b/requirements.txt index 2154037..f129cb3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ httpx>=0.21.2 httpx-sse==0.4.0 pydantic>= 1.9.2 -pydantic-core==2.18.2 +pydantic-core>=2.18.2 typing_extensions>= 4.0.0 diff --git a/src/credal/client.py b/src/credal/client.py index 532746a..80ca26b 100644 --- a/src/credal/client.py +++ b/src/credal/client.py @@ -34,6 +34,9 @@ class CredalApi: api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]] + headers : typing.Optional[typing.Dict[str, str]] + Additional headers to send with every request. + timeout : typing.Optional[float] 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. @@ -58,6 +61,7 @@ def __init__( base_url: typing.Optional[str] = None, environment: CredalApiEnvironment = CredalApiEnvironment.PRODUCTION, api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CREDAL_API_KEY"), + headers: typing.Optional[typing.Dict[str, str]] = None, timeout: typing.Optional[float] = None, follow_redirects: typing.Optional[bool] = True, httpx_client: typing.Optional[httpx.Client] = None, @@ -72,6 +76,7 @@ def __init__( self._client_wrapper = SyncClientWrapper( base_url=_get_base_url(base_url=base_url, environment=environment), api_key=api_key, + headers=headers, httpx_client=httpx_client if httpx_client is not None else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects) @@ -106,6 +111,9 @@ class AsyncCredalApi: api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]] + headers : typing.Optional[typing.Dict[str, str]] + Additional headers to send with every request. + timeout : typing.Optional[float] 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. @@ -130,6 +138,7 @@ def __init__( base_url: typing.Optional[str] = None, environment: CredalApiEnvironment = CredalApiEnvironment.PRODUCTION, api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CREDAL_API_KEY"), + headers: typing.Optional[typing.Dict[str, str]] = None, timeout: typing.Optional[float] = None, follow_redirects: typing.Optional[bool] = True, httpx_client: typing.Optional[httpx.AsyncClient] = None, @@ -144,6 +153,7 @@ def __init__( self._client_wrapper = AsyncClientWrapper( base_url=_get_base_url(base_url=base_url, environment=environment), api_key=api_key, + headers=headers, httpx_client=httpx_client if httpx_client is not None else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects) diff --git a/src/credal/core/client_wrapper.py b/src/credal/core/client_wrapper.py index 824324e..d99e68e 100644 --- a/src/credal/core/client_wrapper.py +++ b/src/credal/core/client_wrapper.py @@ -11,19 +11,22 @@ def __init__( self, *, api_key: typing.Union[str, typing.Callable[[], str]], + headers: typing.Optional[typing.Dict[str, str]] = None, base_url: str, timeout: typing.Optional[float] = None, ): self._api_key = api_key + self._headers = headers self._base_url = base_url self._timeout = timeout def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { - "User-Agent": "credal/0.0.28", + "User-Agent": "credal/0.0.29", "X-Fern-Language": "Python", "X-Fern-SDK-Name": "credal", - "X-Fern-SDK-Version": "0.0.28", + "X-Fern-SDK-Version": "0.0.29", + **(self.get_custom_headers() or {}), } headers["Authorization"] = f"Bearer {self._get_api_key()}" return headers @@ -34,6 +37,9 @@ def _get_api_key(self) -> str: else: return self._api_key() + def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]: + return self._headers + def get_base_url(self) -> str: return self._base_url @@ -46,11 +52,12 @@ def __init__( self, *, api_key: typing.Union[str, typing.Callable[[], str]], + headers: typing.Optional[typing.Dict[str, str]] = None, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client, ): - super().__init__(api_key=api_key, base_url=base_url, timeout=timeout) + super().__init__(api_key=api_key, headers=headers, base_url=base_url, timeout=timeout) self.httpx_client = HttpClient( httpx_client=httpx_client, base_headers=self.get_headers, @@ -64,11 +71,12 @@ def __init__( self, *, api_key: typing.Union[str, typing.Callable[[], str]], + headers: typing.Optional[typing.Dict[str, str]] = None, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient, ): - super().__init__(api_key=api_key, base_url=base_url, timeout=timeout) + super().__init__(api_key=api_key, headers=headers, base_url=base_url, timeout=timeout) self.httpx_client = AsyncHttpClient( httpx_client=httpx_client, base_headers=self.get_headers, diff --git a/src/credal/core/pydantic_utilities.py b/src/credal/core/pydantic_utilities.py index 0360ef4..7db2950 100644 --- a/src/credal/core/pydantic_utilities.py +++ b/src/credal/core/pydantic_utilities.py @@ -59,9 +59,9 @@ class UniversalBaseModel(pydantic.BaseModel): protected_namespaces=(), ) - @pydantic.model_serializer(mode="wrap", when_used="json") # type: ignore[attr-defined] - def serialize_model(self, handler: pydantic.SerializerFunctionWrapHandler) -> Any: # type: ignore[name-defined] - serialized = handler(self) + @pydantic.model_serializer(mode="plain", when_used="json") # type: ignore[attr-defined] + def serialize_model(self) -> Any: # type: ignore[name-defined] + serialized = self.model_dump() data = {k: serialize_datetime(v) if isinstance(v, dt.datetime) else v for k, v in serialized.items()} return data