diff --git a/deepgram/__init__.py b/deepgram/__init__.py index 4976afcf..b2c8f82a 100644 --- a/deepgram/__init__.py +++ b/deepgram/__init__.py @@ -24,7 +24,14 @@ from .client import Deepgram, DeepgramClient from .client import DeepgramClientOptions, ClientOptionsFromEnv -from .client import DeepgramApiKeyError, DeepgramModuleError +from .client import ( + DeepgramError, + DeepgramTypeError, + DeepgramModuleError, + DeepgramApiError, + DeepgramUnknownApiError, +) +from .errors import DeepgramApiKeyError # listen/read client from .client import Listen, Read @@ -173,7 +180,7 @@ ) # utilities -from .audio import Microphone +from .audio import Microphone, DeepgramMicrophoneError from .audio import ( LOGGING, CHANNELS, diff --git a/deepgram/audio/__init__.py b/deepgram/audio/__init__.py index 80c52ca9..acde088c 100644 --- a/deepgram/audio/__init__.py +++ b/deepgram/audio/__init__.py @@ -4,3 +4,4 @@ from .microphone import Microphone from .microphone import LOGGING, CHANNELS, RATE, CHUNK +from .microphone import DeepgramMicrophoneError diff --git a/deepgram/audio/microphone/__init__.py b/deepgram/audio/microphone/__init__.py index 27aeb430..d5ead2f1 100644 --- a/deepgram/audio/microphone/__init__.py +++ b/deepgram/audio/microphone/__init__.py @@ -4,3 +4,4 @@ from .microphone import Microphone from .constants import LOGGING, CHANNELS, RATE, CHUNK +from .errors import DeepgramMicrophoneError diff --git a/deepgram/client.py b/deepgram/client.py index 39cc1361..a94dfc53 100644 --- a/deepgram/client.py +++ b/deepgram/client.py @@ -28,6 +28,13 @@ UnhandledResponse, ErrorResponse, ) +from .clients import ( + DeepgramError, + DeepgramTypeError, + DeepgramModuleError, + DeepgramApiError, + DeepgramUnknownApiError, +) # listen client from .clients import Listen, Read, Speak @@ -178,7 +185,7 @@ # client errors and options from .options import DeepgramClientOptions, ClientOptionsFromEnv -from .errors import DeepgramApiKeyError, DeepgramModuleError +from .errors import DeepgramApiKeyError # pylint: enable=unused-import diff --git a/deepgram/clients/__init__.py b/deepgram/clients/__init__.py index 1b3012f2..b5ebc1f0 100644 --- a/deepgram/clients/__init__.py +++ b/deepgram/clients/__init__.py @@ -18,6 +18,8 @@ UnhandledResponse, ErrorResponse, ) +from .common import DeepgramError, DeepgramTypeError +from .errors import DeepgramModuleError, DeepgramApiError, DeepgramUnknownApiError from .listen_router import Listen from .read_router import Read diff --git a/deepgram/clients/abstract_async_client.py b/deepgram/clients/abstract_async_client.py index 1ff53ba9..37506ead 100644 --- a/deepgram/clients/abstract_async_client.py +++ b/deepgram/clients/abstract_async_client.py @@ -10,7 +10,8 @@ from .helpers import append_query_params from ..options import DeepgramClientOptions -from .errors import DeepgramError, DeepgramApiError, DeepgramUnknownApiError +from .errors import DeepgramApiError, DeepgramUnknownApiError +from .common.v1.errors import DeepgramError class AbstractAsyncRestClient: diff --git a/deepgram/clients/abstract_sync_client.py b/deepgram/clients/abstract_sync_client.py index bff6e27c..9ccf92b5 100644 --- a/deepgram/clients/abstract_sync_client.py +++ b/deepgram/clients/abstract_sync_client.py @@ -10,7 +10,8 @@ from .helpers import append_query_params from ..options import DeepgramClientOptions -from .errors import DeepgramError, DeepgramApiError, DeepgramUnknownApiError +from .errors import DeepgramApiError, DeepgramUnknownApiError +from .common.v1.errors import DeepgramError class AbstractSyncRestClient: diff --git a/deepgram/clients/analyze/__init__.py b/deepgram/clients/analyze/__init__.py index c782482b..599daaaf 100644 --- a/deepgram/clients/analyze/__init__.py +++ b/deepgram/clients/analyze/__init__.py @@ -7,5 +7,3 @@ from .client import AnalyzeOptions from .client import UrlSource, FileSource, AnalyzeStreamSource, AnalyzeSource from .client import AsyncAnalyzeResponse, AnalyzeResponse, SyncAnalyzeResponse - -from ...options import DeepgramClientOptions, ClientOptionsFromEnv diff --git a/deepgram/clients/analyze/v1/__init__.py b/deepgram/clients/analyze/v1/__init__.py index fbb8e58c..0ffaf939 100644 --- a/deepgram/clients/analyze/v1/__init__.py +++ b/deepgram/clients/analyze/v1/__init__.py @@ -11,5 +11,4 @@ AnalyzeStreamSource, AnalyzeSource, ) -from ....options import DeepgramClientOptions, ClientOptionsFromEnv from .response import AsyncAnalyzeResponse, AnalyzeResponse, Sentiment diff --git a/deepgram/clients/analyze/v1/async_client.py b/deepgram/clients/analyze/v1/async_client.py index 5391984b..a2970f8a 100644 --- a/deepgram/clients/analyze/v1/async_client.py +++ b/deepgram/clients/analyze/v1/async_client.py @@ -10,7 +10,7 @@ from ....utils import verboselogs from ....options import DeepgramClientOptions from ...abstract_async_client import AbstractAsyncRestClient -from ..errors import DeepgramError, DeepgramTypeError +from ...common.v1.errors import DeepgramError, DeepgramTypeError from .helpers import is_buffer_source, is_readstream_source, is_url_source from .options import ( diff --git a/deepgram/clients/analyze/v1/client.py b/deepgram/clients/analyze/v1/client.py index a2ef5d94..341c10f6 100644 --- a/deepgram/clients/analyze/v1/client.py +++ b/deepgram/clients/analyze/v1/client.py @@ -10,7 +10,7 @@ from ....utils import verboselogs from ....options import DeepgramClientOptions from ...abstract_sync_client import AbstractSyncRestClient -from ..errors import DeepgramError, DeepgramTypeError +from ...common.v1.errors import DeepgramError, DeepgramTypeError from .helpers import is_buffer_source, is_readstream_source, is_url_source from .options import ( diff --git a/deepgram/clients/common/__init__.py b/deepgram/clients/common/__init__.py index ef39395d..e3cb868e 100644 --- a/deepgram/clients/common/__init__.py +++ b/deepgram/clients/common/__init__.py @@ -2,6 +2,8 @@ # 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 import DeepgramError, DeepgramTypeError + from .v1 import ( TextSource as TextSourceLatest, BufferSource as BufferSourceLatest, @@ -16,6 +18,5 @@ BufferSource = BufferSourceLatest StreamSource = StreamSourceLatest - Sentiment = SentimentLatest FileSource = FileSourceLatest diff --git a/deepgram/clients/common/v1/__init__.py b/deepgram/clients/common/v1/__init__.py index 4f283bb0..b4bd0b30 100644 --- a/deepgram/clients/common/v1/__init__.py +++ b/deepgram/clients/common/v1/__init__.py @@ -4,6 +4,8 @@ from .enums import Sentiment +from .errors import DeepgramError, DeepgramTypeError + from .options import ( TextSource, BufferSource, diff --git a/deepgram/clients/analyze/errors.py b/deepgram/clients/common/v1/errors.py similarity index 100% rename from deepgram/clients/analyze/errors.py rename to deepgram/clients/common/v1/errors.py diff --git a/deepgram/clients/errors.py b/deepgram/clients/errors.py index cf7d7eb6..291e0c1e 100644 --- a/deepgram/clients/errors.py +++ b/deepgram/clients/errors.py @@ -3,23 +3,6 @@ # SPDX-License-Identifier: MIT -class DeepgramError(Exception): - """ - Exception raised for unknown errors related to the Deepgram API. - - Attributes: - message (str): The error message describing the exception. - """ - - def __init__(self, message: str): - super().__init__(message) - self.name = "DeepgramError" - self.message = message - - def __str__(self): - return f"{self.name}: {self.message}" - - class DeepgramModuleError(Exception): """ Base class for exceptions raised for a missing Deepgram module. diff --git a/deepgram/clients/listen/__init__.py b/deepgram/clients/listen/__init__.py index e7ed3952..980199ae 100644 --- a/deepgram/clients/listen/__init__.py +++ b/deepgram/clients/listen/__init__.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: MIT from .enums import LiveTranscriptionEvents -from ...options import DeepgramClientOptions, ClientOptionsFromEnv # backward compat from .client import ( diff --git a/deepgram/clients/listen/client.py b/deepgram/clients/listen/client.py index ae769005..0914d0cc 100644 --- a/deepgram/clients/listen/client.py +++ b/deepgram/clients/listen/client.py @@ -2,9 +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 ...options import DeepgramClientOptions, ClientOptionsFromEnv - # rest from .v1 import ( ListenRESTClient as ListenRESTClientLatest, diff --git a/deepgram/clients/listen/errors.py b/deepgram/clients/listen/errors.py deleted file mode 100644 index b61f7441..00000000 --- a/deepgram/clients/listen/errors.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. -# Use of this source code is governed by a MIT license that can be found in the LICENSE file. -# SPDX-License-Identifier: MIT - - -class DeepgramError(Exception): - """ - Exception raised for unknown errors related to the Deepgram API. - - Attributes: - message (str): The error message describing the exception. - """ - - def __init__(self, message: str): - super().__init__(message) - self.name = "DeepgramError" - self.message = message - - def __str__(self): - return f"{self.name}: {self.message}" - - -class DeepgramTypeError(Exception): - """ - Exception raised for unknown errors related to unknown Types for Transcription. - - Attributes: - message (str): The error message describing the exception. - """ - - def __init__(self, message: str): - super().__init__(message) - self.name = "DeepgramTypeError" - self.message = message - - def __str__(self): - return f"{self.name}: {self.message}" - - -class DeepgramWebsocketError(Exception): - """ - Exception raised for known errors related to Websocket library. - - Attributes: - message (str): The error message describing the exception. - """ - - def __init__(self, message: str): - super().__init__(message) - self.name = "DeepgramWebsocketError" - self.message = message - - def __str__(self): - return f"{self.name}: {self.message}" diff --git a/deepgram/clients/listen/v1/__init__.py b/deepgram/clients/listen/v1/__init__.py index cdacfe44..290a5086 100644 --- a/deepgram/clients/listen/v1/__init__.py +++ b/deepgram/clients/listen/v1/__init__.py @@ -2,8 +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 ....options import DeepgramClientOptions, ClientOptionsFromEnv - # backward compat from .rest import ( ListenRESTClient as PreRecordedClient, diff --git a/deepgram/clients/listen/v1/rest/__init__.py b/deepgram/clients/listen/v1/rest/__init__.py index 9fdba320..2b7989a2 100644 --- a/deepgram/clients/listen/v1/rest/__init__.py +++ b/deepgram/clients/listen/v1/rest/__init__.py @@ -19,5 +19,3 @@ SyncPrerecordedResponse, Sentiment, ) - -from .....options import DeepgramClientOptions, ClientOptionsFromEnv diff --git a/deepgram/clients/listen/v1/rest/async_client.py b/deepgram/clients/listen/v1/rest/async_client.py index 18b9a42a..f528c9a4 100644 --- a/deepgram/clients/listen/v1/rest/async_client.py +++ b/deepgram/clients/listen/v1/rest/async_client.py @@ -10,7 +10,7 @@ from .....utils import verboselogs from .....options import DeepgramClientOptions from ....abstract_async_client import AbstractAsyncRestClient -from ...errors import DeepgramError, DeepgramTypeError +from ....common.v1.errors import DeepgramError, DeepgramTypeError from .helpers import is_buffer_source, is_readstream_source, is_url_source from .options import ( diff --git a/deepgram/clients/listen/v1/rest/client.py b/deepgram/clients/listen/v1/rest/client.py index 12553f4d..fdb50b34 100644 --- a/deepgram/clients/listen/v1/rest/client.py +++ b/deepgram/clients/listen/v1/rest/client.py @@ -10,7 +10,7 @@ from .....utils import verboselogs from .....options import DeepgramClientOptions from ....abstract_sync_client import AbstractSyncRestClient -from ...errors import DeepgramError, DeepgramTypeError +from ....common.v1.errors import DeepgramError, DeepgramTypeError from .helpers import is_buffer_source, is_readstream_source, is_url_source from .options import ( diff --git a/deepgram/clients/listen/v1/websocket/__init__.py b/deepgram/clients/listen/v1/websocket/__init__.py index 4ddc1590..e1b4c515 100644 --- a/deepgram/clients/listen/v1/websocket/__init__.py +++ b/deepgram/clients/listen/v1/websocket/__init__.py @@ -5,7 +5,6 @@ from .client import ListenWebSocketClient from .async_client import AsyncListenWebSocketClient from .options import LiveOptions, ListenWebSocketOptions -from .....options import DeepgramClientOptions, ClientOptionsFromEnv from .response import ( OpenResponse, LiveResultResponse, diff --git a/deepgram/clients/listen/v1/websocket/async_client.py b/deepgram/clients/listen/v1/websocket/async_client.py index 87603e7a..4a0aa331 100644 --- a/deepgram/clients/listen/v1/websocket/async_client.py +++ b/deepgram/clients/listen/v1/websocket/async_client.py @@ -15,7 +15,7 @@ from .....options import DeepgramClientOptions from ...enums import LiveTranscriptionEvents from ..helpers import convert_to_websocket_url, append_query_params -from ...errors import DeepgramError +from ....common.v1.errors import DeepgramError from .response import ( OpenResponse, diff --git a/deepgram/clients/listen/v1/websocket/client.py b/deepgram/clients/listen/v1/websocket/client.py index 8f074800..f2e10e2e 100644 --- a/deepgram/clients/listen/v1/websocket/client.py +++ b/deepgram/clients/listen/v1/websocket/client.py @@ -15,7 +15,7 @@ from .....options import DeepgramClientOptions from ...enums import LiveTranscriptionEvents from ..helpers import convert_to_websocket_url, append_query_params -from ...errors import DeepgramError +from ....common.v1.errors import DeepgramError from .response import ( OpenResponse, diff --git a/deepgram/clients/live/__init__.py b/deepgram/clients/live/__init__.py index 7c40e7f6..40a6c934 100644 --- a/deepgram/clients/live/__init__.py +++ b/deepgram/clients/live/__init__.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: MIT from .v1 import LiveTranscriptionEvents -from .v1 import DeepgramError, DeepgramTypeError, DeepgramWebsocketError from .v1 import LiveClient from .v1 import AsyncLiveClient diff --git a/deepgram/clients/live/v1/__init__.py b/deepgram/clients/live/v1/__init__.py index 8c63f963..91538538 100644 --- a/deepgram/clients/live/v1/__init__.py +++ b/deepgram/clients/live/v1/__init__.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: MIT from .enums import LiveTranscriptionEvents -from .errors import DeepgramError, DeepgramTypeError, DeepgramWebsocketError from .client import LiveClient from .client import AsyncLiveClient diff --git a/deepgram/clients/live/v1/errors.py b/deepgram/clients/live/v1/errors.py deleted file mode 100644 index b156a3fe..00000000 --- a/deepgram/clients/live/v1/errors.py +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved. -# Use of this source code is governed by a MIT license that can be found in the LICENSE file. -# SPDX-License-Identifier: MIT - -from ...listen.errors import DeepgramError, DeepgramTypeError, DeepgramWebsocketError diff --git a/deepgram/clients/manage/__init__.py b/deepgram/clients/manage/__init__.py index d51a9eca..e4489eec 100644 --- a/deepgram/clients/manage/__init__.py +++ b/deepgram/clients/manage/__init__.py @@ -32,4 +32,3 @@ ModelResponse, ModelsResponse, ) -from ...options import DeepgramClientOptions, ClientOptionsFromEnv diff --git a/deepgram/clients/prerecorded/__init__.py b/deepgram/clients/prerecorded/__init__.py index 0c28ab56..9156a65c 100644 --- a/deepgram/clients/prerecorded/__init__.py +++ b/deepgram/clients/prerecorded/__init__.py @@ -2,8 +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 ...options import DeepgramClientOptions, ClientOptionsFromEnv - from .v1 import PreRecordedClient from .v1 import AsyncPreRecordedClient from .v1 import PrerecordedOptions diff --git a/deepgram/clients/prerecorded/v1/__init__.py b/deepgram/clients/prerecorded/v1/__init__.py index 6aafeb12..03095cc9 100644 --- a/deepgram/clients/prerecorded/v1/__init__.py +++ b/deepgram/clients/prerecorded/v1/__init__.py @@ -2,8 +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 ....options import DeepgramClientOptions, ClientOptionsFromEnv - from .client import PreRecordedClient from .client import AsyncPreRecordedClient from .client import PrerecordedOptions diff --git a/deepgram/clients/selfhosted/__init__.py b/deepgram/clients/selfhosted/__init__.py index 93cf7d47..ced8a6f4 100644 --- a/deepgram/clients/selfhosted/__init__.py +++ b/deepgram/clients/selfhosted/__init__.py @@ -4,4 +4,3 @@ from .client import SelfHostedClient, OnPremClient from .client import AsyncSelfHostedClient, AsyncOnPremClient -from ...options import DeepgramClientOptions, ClientOptionsFromEnv diff --git a/deepgram/clients/selfhosted/v1/__init__.py b/deepgram/clients/selfhosted/v1/__init__.py index 4c46a0ad..8604f754 100644 --- a/deepgram/clients/selfhosted/v1/__init__.py +++ b/deepgram/clients/selfhosted/v1/__init__.py @@ -4,4 +4,3 @@ from .client import SelfHostedClient from .async_client import AsyncSelfHostedClient -from ....options import DeepgramClientOptions, ClientOptionsFromEnv diff --git a/deepgram/clients/speak/__init__.py b/deepgram/clients/speak/__init__.py index 07d8f42e..0d74a99e 100644 --- a/deepgram/clients/speak/__init__.py +++ b/deepgram/clients/speak/__init__.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: MIT from .enums import SpeakWebSocketEvents -from ...options import DeepgramClientOptions, ClientOptionsFromEnv from .client import ( SpeakClient, # backward compat diff --git a/deepgram/clients/speak/errors.py b/deepgram/clients/speak/errors.py deleted file mode 100644 index a39020a1..00000000 --- a/deepgram/clients/speak/errors.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. -# Use of this source code is governed by a MIT license that can be found in the LICENSE file. -# SPDX-License-Identifier: MIT - - -class DeepgramError(Exception): - """ - Exception raised for unknown errors related to the Deepgram API. - - Attributes: - message (str): The error message describing the exception. - """ - - def __init__(self, message: str): - super().__init__(message) - self.name = "DeepgramError" - self.message = message - - def __str__(self): - return f"{self.name}: {self.message}" - - -class DeepgramTypeError(Exception): - """ - Exception raised for unknown errors related to unknown Types for TTS Synthesis. - - Attributes: - message (str): The error message describing the exception. - """ - - def __init__(self, message: str): - super().__init__(message) - self.name = "DeepgramTypeError" - self.message = message - - def __str__(self): - return f"{self.name}: {self.message}" diff --git a/deepgram/clients/speak/v1/__init__.py b/deepgram/clients/speak/v1/__init__.py index 97e63d7a..73ab29e6 100644 --- a/deepgram/clients/speak/v1/__init__.py +++ b/deepgram/clients/speak/v1/__init__.py @@ -15,7 +15,6 @@ # from .websocket import ( # SpeakWebSocketOptions, # ) -from ....options import DeepgramClientOptions, ClientOptionsFromEnv # rest from .rest import SpeakRESTClient, AsyncSpeakRESTClient diff --git a/deepgram/clients/speak/v1/rest/async_client.py b/deepgram/clients/speak/v1/rest/async_client.py index c4568ef8..be32b96b 100644 --- a/deepgram/clients/speak/v1/rest/async_client.py +++ b/deepgram/clients/speak/v1/rest/async_client.py @@ -15,7 +15,7 @@ from .....utils import verboselogs from .....options import DeepgramClientOptions from ....abstract_async_client import AbstractAsyncRestClient -from ...errors import DeepgramError, DeepgramTypeError +from ....common.v1.errors import DeepgramError, DeepgramTypeError from .helpers import is_text_source from .options import SpeakRESTOptions, FileSource diff --git a/deepgram/clients/speak/v1/rest/client.py b/deepgram/clients/speak/v1/rest/client.py index 03bc3db6..85ab694d 100644 --- a/deepgram/clients/speak/v1/rest/client.py +++ b/deepgram/clients/speak/v1/rest/client.py @@ -14,7 +14,7 @@ from .....utils import verboselogs from .....options import DeepgramClientOptions from ....abstract_sync_client import AbstractSyncRestClient -from ...errors import DeepgramError, DeepgramTypeError +from ....common.v1.errors import DeepgramError, DeepgramTypeError from .helpers import is_text_source from .options import SpeakRESTOptions, FileSource diff --git a/deepgram/errors.py b/deepgram/errors.py index dc2e49a8..85f2128f 100644 --- a/deepgram/errors.py +++ b/deepgram/errors.py @@ -14,16 +14,3 @@ class DeepgramApiKeyError(Exception): def __init__(self, message: str): super().__init__(message) self.name = "DeepgramApiKeyError" - - -class DeepgramModuleError(Exception): - """ - Base class for exceptions raised for a missing Deepgram module. - - Attributes: - message (str): The error message describing the exception. - """ - - def __init__(self, message: str): - super().__init__(message) - self.name = "DeepgramModuleError"