Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"cliVersion": "4.107.0",
"cliVersion": "5.44.2",
"generatorName": "fernapi/fern-python-sdk",
"generatorVersion": "5.8.3",
"generatorVersion": "5.14.8",
"generatorConfig": {
"client": {
"class_name": "BaseClient",
Expand All @@ -19,5 +19,5 @@
"originGitCommit": "d228f82e93aaa8aa77f978d458cf912f3daaa8c1",
"originGitCommitIsDirty": true,
"invokedBy": "manual",
"sdkVersion": "7.1.2"
"sdkVersion": "7.3.1"
}
847 changes: 440 additions & 407 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dynamic = ["version"]

[tool.poetry]
name = "deepgram-sdk"
version = "7.3.0"
version = "7.3.1"
description = ""
readme = "README.md"
authors = []
Expand Down Expand Up @@ -42,7 +42,7 @@ aiohttp = { version = ">=3.13.4,<4", optional = true, python = ">=3.9"}
httpx = ">=0.21.2"
httpx-aiohttp = { version = "0.1.8", optional = true, python = ">=3.9"}
pydantic = ">= 1.9.2"
pydantic-core = ">=2.18.2,<2.44.0"
pydantic-core = ">=2.18.2,<3.0.0"
typing_extensions = ">= 4.0.0"
websockets = ">=12.0"

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
httpx>=0.21.2
pydantic>= 1.9.2
pydantic-core>=2.18.2,<2.44.0
pydantic-core>=2.18.2,<3.0.0
typing_extensions>= 4.0.0
websockets>=12.0
12 changes: 12 additions & 0 deletions src/deepgram/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class BaseClient:
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.

max_retries : typing.Optional[int]
The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.

follow_redirects : typing.Optional[bool]
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

Expand All @@ -69,13 +72,15 @@ def __init__(
api_key: typing.Optional[str] = os.getenv("DEEPGRAM_API_KEY"),
headers: typing.Optional[typing.Dict[str, str]] = None,
timeout: typing.Optional[float] = None,
max_retries: typing.Optional[int] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.Client] = None,
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
):
_defaulted_timeout = (
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
)
_defaulted_max_retries = max_retries if max_retries is not None else 2
if api_key is None:
raise ApiError(
body="The client must be instantiated be either passing in api_key or setting DEEPGRAM_API_KEY"
Expand All @@ -90,6 +95,7 @@ def __init__(
if follow_redirects is not None
else httpx.Client(timeout=_defaulted_timeout),
timeout=_defaulted_timeout,
max_retries=_defaulted_max_retries,
logging=logging,
)
self._agent: typing.Optional[AgentClient] = None
Expand Down Expand Up @@ -206,6 +212,9 @@ class AsyncBaseClient:
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.

max_retries : typing.Optional[int]
The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.

follow_redirects : typing.Optional[bool]
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

Expand All @@ -231,13 +240,15 @@ def __init__(
api_key: typing.Optional[str] = os.getenv("DEEPGRAM_API_KEY"),
headers: typing.Optional[typing.Dict[str, str]] = None,
timeout: typing.Optional[float] = None,
max_retries: typing.Optional[int] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.AsyncClient] = None,
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
):
_defaulted_timeout = (
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
)
_defaulted_max_retries = max_retries if max_retries is not None else 2
if api_key is None:
raise ApiError(
body="The client must be instantiated be either passing in api_key or setting DEEPGRAM_API_KEY"
Expand All @@ -250,6 +261,7 @@ def __init__(
if httpx_client is not None
else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
timeout=_defaulted_timeout,
max_retries=_defaulted_max_retries,
logging=logging,
)
self._agent: typing.Optional[AsyncAgentClient] = None
Expand Down
31 changes: 27 additions & 4 deletions src/deepgram/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ def __init__(
headers: typing.Optional[typing.Dict[str, str]] = None,
environment: DeepgramClientEnvironment,
timeout: typing.Optional[float] = None,
max_retries: int = 2,
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
):
self.api_key = api_key
self._headers = headers
self._environment = environment
self._timeout = timeout
self._max_retries = max_retries
self._logging = logging

def get_headers(self) -> typing.Dict[str, str]:
import platform

headers: typing.Dict[str, str] = {
"User-Agent": "deepgram-sdk/7.1.2",
"User-Agent": "deepgram-sdk/7.3.1",
"X-Fern-Language": "Python",
"X-Fern-Runtime": f"python/{platform.python_version()}",
"X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
"X-Fern-SDK-Name": "deepgram-sdk",
"X-Fern-SDK-Version": "7.1.2",
"X-Fern-SDK-Version": "7.3.1",
**(self.get_custom_headers() or {}),
}
headers["Authorization"] = f"Token {self.api_key}"
Expand All @@ -48,6 +50,9 @@ def get_environment(self) -> DeepgramClientEnvironment:
def get_timeout(self) -> typing.Optional[float]:
return self._timeout

def get_max_retries(self) -> int:
return self._max_retries


class SyncClientWrapper(BaseClientWrapper):
def __init__(
Expand All @@ -57,14 +62,23 @@ def __init__(
headers: typing.Optional[typing.Dict[str, str]] = None,
environment: DeepgramClientEnvironment,
timeout: typing.Optional[float] = None,
max_retries: int = 2,
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
httpx_client: httpx.Client,
):
super().__init__(api_key=api_key, headers=headers, environment=environment, timeout=timeout, logging=logging)
super().__init__(
api_key=api_key,
headers=headers,
environment=environment,
timeout=timeout,
max_retries=max_retries,
logging=logging,
)
self.httpx_client = HttpClient(
httpx_client=httpx_client,
base_headers=self.get_headers,
base_timeout=self.get_timeout,
base_max_retries=self.get_max_retries(),
logging_config=self._logging,
)

Expand All @@ -77,16 +91,25 @@ def __init__(
headers: typing.Optional[typing.Dict[str, str]] = None,
environment: DeepgramClientEnvironment,
timeout: typing.Optional[float] = None,
max_retries: int = 2,
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
httpx_client: httpx.AsyncClient,
):
super().__init__(api_key=api_key, headers=headers, environment=environment, timeout=timeout, logging=logging)
super().__init__(
api_key=api_key,
headers=headers,
environment=environment,
timeout=timeout,
max_retries=max_retries,
logging=logging,
)
self._async_token = async_token
self.httpx_client = AsyncHttpClient(
httpx_client=httpx_client,
base_headers=self.get_headers,
base_timeout=self.get_timeout,
base_max_retries=self.get_max_retries(),
async_base_headers=self.async_get_headers,
logging_config=self._logging,
)
Expand Down
3 changes: 1 addition & 2 deletions src/deepgram/core/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def _retry_timeout_from_retries(retries: int) -> float:


def _should_retry(response: httpx.Response) -> bool:
retryable_400s = [429, 408, 409]
return response.status_code >= 500 or response.status_code in retryable_400s
return response.status_code >= 500 or response.status_code in [429, 408, 409]


_SENSITIVE_HEADERS = frozenset(
Expand Down
Loading
Loading