Skip to content

Commit

Permalink
Change OnPrem -> SelfHosted, But Preserve Backward Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvonthenen committed Jun 11, 2024
1 parent 3177017 commit d23724a
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 57 deletions.
4 changes: 3 additions & 1 deletion deepgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@
BalancesResponse,
)

# onprem
# selfhosted
from .client import (
OnPremClient,
AsyncOnPremClient,
SelfHostedClient,
AsyncSelfHostedClient,
)

# utilities
Expand Down
46 changes: 32 additions & 14 deletions deepgram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
from .clients import (
OnPremClient,
AsyncOnPremClient,
SelfHostedClient,
AsyncSelfHostedClient,
)

# client errors and options
Expand Down Expand Up @@ -172,10 +174,10 @@ class DeepgramClient:
listen: Returns a ListenClient instance for interacting with Deepgram's transcription services.
manage: (Preferred) Returns a Threaded ManageClient instance for managing Deepgram resources.
onprem: (Preferred) Returns an Threaded OnPremClient instance for interacting with Deepgram's on-premises API.
selfhosted: (Preferred) Returns an Threaded SelfHostedClient instance for interacting with Deepgram's on-premises API.
asyncmanage: Returns an (Async) ManageClient instance for managing Deepgram resources.
asynconprem: Returns an (Async) OnPremClient instance for interacting with Deepgram's on-premises API.
asyncselfhosted: Returns an (Async) SelfHostedClient instance for interacting with Deepgram's on-premises API.
"""

_config: DeepgramClientOptions
Expand Down Expand Up @@ -247,19 +249,35 @@ def asyncmanage(self):
"""
return self.Version(self._config, "asyncmanage")

# for backwards compatibility
@property
def onprem(self):
"""
Returns an OnPremClient instance for interacting with Deepgram's on-premises API.
Returns an SelfHostedClient instance for interacting with Deepgram's on-premises API.
"""
return self.Version(self._config, "onprem")
return self.Version(self._config, "selfhosted")

@property
def selfhosted(self):
"""
Returns an SelfHostedClient instance for interacting with Deepgram's on-premises API.
"""
return self.Version(self._config, "selfhosted")

# for backwards compatibility
@property
def asynconprem(self):
"""
Returns an AsyncOnPremClient instance for interacting with Deepgram's on-premises API.
Returns an AsyncSelfHostedClient instance for interacting with Deepgram's on-premises API.
"""
return self.Version(self._config, "asyncselfhosted")

@property
def asyncselfhosted(self):
"""
Returns an AsyncSelfHostedClient instance for interacting with Deepgram's on-premises API.
"""
return self.Version(self._config, "asynconprem")
return self.Version(self._config, "asyncselfhosted")

# INTERNAL CLASSES
class Version:
Expand All @@ -286,8 +304,8 @@ def __init__(self, config, parent: str):
# match self._parent:
# case "manage":
# return ManageClient(self._config)
# case "onprem":
# return OnPremClient(self._config)
# case "selfhosted":
# return SelfHostedClient(self._config)
# case _:
# raise DeepgramModuleError("Invalid parent")

Expand Down Expand Up @@ -322,14 +340,14 @@ def v(self, version: str = ""):
parent = "speak"
filename = "async_client"
classname = "AsyncSpeakClient"
case "onprem":
parent = "onprem"
case "selfhosted":
parent = "selfhosted"
filename = "client"
classname = "OnPremClient"
case "asynconprem":
parent = "onprem"
classname = "SelfHostedClient"
case "asyncselfhosted":
parent = "selfhosted"
filename = "async_client"
classname = "AsyncOnPremClient"
classname = "AsyncSelfHostedClient"
case _:
self._logger.error("parent unknown: %s", self._parent)
self._logger.debug("Version.v LEAVE")
Expand Down
9 changes: 7 additions & 2 deletions deepgram/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,10 @@
BalancesResponse,
)

# onprem
from .onprem import OnPremClient, AsyncOnPremClient
# selfhosted
from .selfhosted import (
OnPremClient,
AsyncOnPremClient,
SelfHostedClient,
AsyncSelfHostedClient,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from .v1.client import OnPremClient
from .v1.async_client import AsyncOnPremClient
from .client import SelfHostedClient, OnPremClient
from .client import AsyncSelfHostedClient, AsyncOnPremClient
from ...options import DeepgramClientOptions, ClientOptionsFromEnv
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from .v1.client import OnPremClient as OnPremClientLatest
from .v1.async_client import AsyncOnPremClient as AsyncOnPremClientLatest
from .v1.client import SelfHostedClient as SelfHostedClientLatest
from .v1.client import SelfHostedClient as OnPremClientLatest
from .v1.async_client import AsyncSelfHostedClient as AsyncSelfHostedClientLatest
from .v1.async_client import AsyncSelfHostedClient as AsyncOnPremClientLatest


# The client.py points to the current supported version in the SDK.
# Older versions are supported in the SDK for backwards compatibility.

SelfHostedClient = SelfHostedClientLatest
AsyncSelfHostedClient = AsyncSelfHostedClientLatest
OnPremClient = OnPremClientLatest
AsyncOnPremClient = AsyncOnPremClientLatest
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from .client import OnPremClient
from .async_client import AsyncOnPremClient
from .client import SelfHostedClient
from .async_client import AsyncSelfHostedClient
from ....options import DeepgramClientOptions, ClientOptionsFromEnv
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ...abstract_async_client import AbstractAsyncRestClient


class AsyncOnPremClient(AbstractAsyncRestClient):
class AsyncSelfHostedClient(AbstractAsyncRestClient):
"""
Client for interacting with Deepgram's on-premises API.
Expand All @@ -36,75 +36,105 @@ def __init__(self, config: DeepgramClientOptions):

async def list_onprem_credentials(
self, project_id: str, timeout: Optional[httpx.Timeout] = None
):
return self.list_selfhosted_credentials(project_id, timeout)

async def list_selfhosted_credentials(
self, project_id: str, timeout: Optional[httpx.Timeout] = None
):
"""
List all on-premises distribution credentials for a project.
"""
self._logger.debug("OnPremClient.list_onprem_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/onprem/distribution/credentials"
self._logger.debug("SelfHostedClient.list_selfhosted_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/selfhosted/distribution/credentials"
self._logger.info("url: %s", url)
self._logger.info("project_id: %s", project_id)
res = await self.get(url, timeout=timeout)
self._logger.verbose("result: %s", res)
self._logger.notice("list_onprem_credentials succeeded")
self._logger.debug("OnPremClient.list_onprem_credentials LEAVE")
self._logger.notice("list_selfhosted_credentials succeeded")
self._logger.debug("SelfHostedClient.list_selfhosted_credentials LEAVE")
return res

async def get_onprem_credentials(
self,
project_id: str,
distribution_credentials_id: str,
timeout: Optional[httpx.Timeout] = None,
):
return self.get_selfhosted_credentials(
project_id, distribution_credentials_id, timeout
)

async def get_selfhosted_credentials(
self,
project_id: str,
distribution_credentials_id: str,
timeout: Optional[httpx.Timeout] = None,
):
"""
Get a specific on-premises distribution credential for a project.
"""
self._logger.debug("OnPremClient.get_onprem_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/onprem/distribution/credentials/{distribution_credentials_id}"
self._logger.debug("SelfHostedClient.get_selfhosted_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/selfhosted/distribution/credentials/{distribution_credentials_id}"
self._logger.info("url: %s", url)
self._logger.info("project_id: %s", project_id)
self._logger.info(
"distribution_credentials_id: %s", distribution_credentials_id
)
res = await self.get(url, timeout=timeout)
self._logger.verbose("result: %s", res)
self._logger.notice("get_onprem_credentials succeeded")
self._logger.debug("OnPremClient.get_onprem_credentials LEAVE")
self._logger.notice("get_selfhosted_credentials succeeded")
self._logger.debug("SelfHostedClient.get_selfhosted_credentials LEAVE")
return res

async def create_onprem_credentials(
self, project_id: str, options, timeout: Optional[httpx.Timeout] = None
):
return self.create_onprem_credentials(project_id, options, timeout)

async def create_selfhosted_credentials(
self, project_id: str, options, timeout: Optional[httpx.Timeout] = None
):
"""
Create a new on-premises distribution credential for a project.
"""
self._logger.debug("OnPremClient.create_onprem_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/onprem/distribution/credentials/"
self._logger.debug("SelfHostedClient.create_selfhosted_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/selfhosted/distribution/credentials/"
self._logger.info("url: %s", url)
self._logger.info("project_id: %s", project_id)
self._logger.info("options: %s", options)
res = await self.post(url, json=options, timeout=timeout)
self._logger.verbose("result: %s", res)
self._logger.notice("create_onprem_credentials succeeded")
self._logger.debug("OnPremClient.create_onprem_credentials LEAVE")
self._logger.notice("create_selfhosted_credentials succeeded")
self._logger.debug("SelfHostedClient.create_selfhosted_credentials LEAVE")
return res

async def delete_onprem_credentials(
self,
project_id: str,
distribution_credentials_id: str,
timeout: Optional[httpx.Timeout] = None,
):
return self.delete_selfhosted_credentials(
project_id, distribution_credentials_id, timeout
)

async def delete_selfhosted_credentials(
self,
project_id: str,
distribution_credentials_id: str,
timeout: Optional[httpx.Timeout] = None,
):
"""
Delete an on-premises distribution credential for a project.
"""
self._logger.debug("OnPremClient.delete_onprem_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/onprem/distribution/credentials/{distribution_credentials_id}"
self._logger.debug("SelfHostedClient.delete_selfhosted_credentials ENTER")
url = f"{self._config.url}/{self._endpoint}/{project_id}/selfhosted/distribution/credentials/{distribution_credentials_id}"
self._logger.info("url: %s", url)
self._logger.info("project_id: %s", project_id)
self._logger.info("distrbution_credentials_id: %s", distribution_credentials_id)
res = await self.delete(url, timeout=timeout)
self._logger.verbose("result: %s", res)
self._logger.notice("delete_onprem_credentials succeeded")
self._logger.debug("OnPremClient.delete_onprem_credentials LEAVE")
self._logger.notice("delete_selfhosted_credentials succeeded")
self._logger.debug("SelfHostedClient.delete_selfhosted_credentials LEAVE")
return res
Loading

0 comments on commit d23724a

Please sign in to comment.