Skip to content

Commit

Permalink
Merge pull request #412 from dvonthenen/self-hosted
Browse files Browse the repository at this point in the history
Change `OnPrem` -> `SelfHosted`, But Preserve Backward Compatibility
  • Loading branch information
davidvonthenen authored Jun 12, 2024
2 parents 3177017 + 05d8ff7 commit c3b8dc5
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 59 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,14 @@
# 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.async_client import AsyncSelfHostedClient as AsyncSelfHostedClientLatest


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

OnPremClient = OnPremClientLatest
AsyncOnPremClient = AsyncOnPremClientLatest
SelfHostedClient = SelfHostedClientLatest
AsyncSelfHostedClient = AsyncSelfHostedClientLatest
OnPremClient = SelfHostedClientLatest
AsyncOnPremClient = AsyncSelfHostedClientLatest
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 Down Expand Up @@ -40,14 +40,22 @@ async def list_onprem_credentials(
"""
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"
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("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(
Expand All @@ -59,17 +67,30 @@ async def get_onprem_credentials(
"""
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}"
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("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(
Expand All @@ -78,15 +99,23 @@ async def create_onprem_credentials(
"""
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/"
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("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(
Expand All @@ -98,13 +127,26 @@ async def delete_onprem_credentials(
"""
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}"
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("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 c3b8dc5

Please sign in to comment.