Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestructureSpeak to Resolve Naming Convention, Update Listen to Match #426

Merged
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
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ ensure-deps: #### Ensure that all required dependency utilities are downloaded o

GO_MODULES=$(shell find . -path "*/go.mod" | xargs -I _ dirname _)

# pystatic: #### Performs Python static analysis
# pylint --rcfile .pylintrc deepgram

PYTHON_FILES=.
lint_files: PYTHON_FILES=deepgram/ examples/
lint_diff: PYTHON_FILES=$(shell git diff --name-only --diff-filter=d main | grep -E '\.py$$')
Expand All @@ -56,7 +53,7 @@ lint_files lint_diff: #### Performs Python formatting
black blackformat format: lint_files

pylint: lint_files #### Performs Python linting
pylint --rcfile .pylintrc deepgram
pylint --disable=W0622 --disable=W0404 --disable=W0611 --rcfile .pylintrc deepgram

lint: pylint #### Performs Golang programming lint

Expand Down
57 changes: 47 additions & 10 deletions deepgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,27 @@
UrlSource,
Sentiment,
)
from .client import (
OpenResponse,
MetadataResponse,
CloseResponse,
UnhandledResponse,
ErrorResponse,
)

# live
from .client import LiveTranscriptionEvents
from .client import LiveClient, AsyncLiveClient
from .client import LiveOptions
from .client import (
OpenResponse,
# OpenResponse,
LiveResultResponse,
MetadataResponse,
# MetadataResponse,
SpeechStartedResponse,
UtteranceEndResponse,
CloseResponse,
UnhandledResponse,
ErrorResponse,
# CloseResponse,
# UnhandledResponse,
# ErrorResponse,
)

# prerecorded
Expand Down Expand Up @@ -82,11 +89,41 @@
)

# speak
from .client import SpeakClient, AsyncSpeakClient
from .client import SpeakStreamClient, AsyncSpeakStreamClient
from .client import SpeakOptions, SpeakStreamSource, SpeakSource
from .client import SpeakResponse
from .client import SpeakStreamEvents
from .client import (
SpeakOptions,
# FileSource,
SpeakWebSocketSource,
SpeakSource,
)
from .client import SpeakWebSocketEvents

## speak REST
from .client import (
SpeakClient, # backward compat
SpeakRESTClient,
AsyncSpeakRESTClient,
)

from .client import (
SpeakResponse, # backward compat
SpeakRESTResponse,
)

## speak WebSocket
from .client import (
SpeakWebSocketClient,
AsyncSpeakWebSocketClient,
)
from .client import (
SpeakWebSocketResponse,
# OpenResponse,
# MetadataResponse,
FlushedResponse,
# CloseResponse,
# UnhandledResponse,
WarningResponse,
# ErrorResponse,
)

# manage
from .client import ManageClient, AsyncManageClient
Expand Down
124 changes: 75 additions & 49 deletions deepgram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from typing import Optional
from importlib import import_module
import os

import logging
import deprecation # type: ignore

from . import __version__
from .utils import verboselogs

# common
Expand All @@ -19,9 +21,16 @@
UrlSource,
Sentiment,
)
from .clients import (
OpenResponse,
MetadataResponse,
CloseResponse,
UnhandledResponse,
ErrorResponse,
)

# listen client
from .clients import Listen, Read
from .clients import Listen, Read, Speak

# live
from .clients import LiveClient, AsyncLiveClient
Expand All @@ -32,14 +41,14 @@

# live client responses
from .clients import (
OpenResponse,
# OpenResponse,
LiveResultResponse,
MetadataResponse,
# MetadataResponse,
SpeechStartedResponse,
UtteranceEndResponse,
CloseResponse,
ErrorResponse,
UnhandledResponse,
# CloseResponse,
# ErrorResponse,
# UnhandledResponse,
)

# prerecorded
Expand Down Expand Up @@ -76,15 +85,42 @@
SyncAnalyzeResponse,
)

# speak client classes/input
from .clients import SpeakClient, AsyncSpeakClient
from .clients import SpeakStreamClient, AsyncSpeakStreamClient
from .clients import SpeakOptions
from .clients import SpeakStreamSource, SpeakSource
from .clients import SpeakStreamEvents
# speak
from .clients import (
SpeakOptions,
# FileSource,
SpeakWebSocketSource,
SpeakSource,
)
from .clients import SpeakWebSocketEvents

## speak REST
from .clients import (
SpeakClient, # backward compat
SpeakRESTClient,
AsyncSpeakRESTClient,
)

from .clients import (
SpeakResponse, # backward compat
SpeakRESTResponse,
)

# speak client responses
from .clients import SpeakResponse
## speak WebSocket
from .clients import (
SpeakWebSocketClient,
AsyncSpeakWebSocketClient,
)
from .clients import (
SpeakWebSocketResponse,
# OpenResponse,
# MetadataResponse,
FlushedResponse,
# CloseResponse,
# UnhandledResponse,
WarningResponse,
# ErrorResponse,
)

# manage client classes/input
from .clients import ManageClient, AsyncManageClient
Expand Down Expand Up @@ -228,29 +264,22 @@ def speak(self):
"""
Returns a SpeakClient instance for interacting with Deepgram's speak services.
"""
return self.Version(self._config, "speak")
return Speak(self._config)

@property
@deprecation.deprecated(
deprecated_in="3.4.0",
removed_in="4.0.0",
current_version=__version__,
details="deepgram.asyncspeak is deprecated. Use deepgram.speak.asyncrest instead.",
)
def asyncspeak(self):
"""
Returns an AsyncSpeakClient instance for interacting with Deepgram's speak services.
DEPRECATED: deepgram.asyncspeak is deprecated. Use deepgram.speak.asyncrest instead.
"""
return self.Version(self._config, "asyncspeak")

@property
def speakstream(self):
"""
Returns a SpeakStreamClient instance for interacting with Deepgram's speak services.
"""
return self.Version(self._config, "speak-stream")

@property
def asyncspeakstream(self):
"""
Returns an AsyncSpeakStreamClient instance for interacting with Deepgram's speak services.
"""
return self.Version(self._config, "asyncspeak-stream")
@property
def manage(self):
"""
Returns a ManageClient instance for managing Deepgram resources.
Expand All @@ -264,11 +293,16 @@ def asyncmanage(self):
"""
return self.Version(self._config, "asyncmanage")

# for backwards compatibility
@property
@deprecation.deprecated(
deprecated_in="3.4.0",
removed_in="4.0.0",
current_version=__version__,
details="deepgram.onprem is deprecated. Use deepgram.speak.selfhosted instead.",
)
def onprem(self):
"""
Returns an SelfHostedClient instance for interacting with Deepgram's on-premises API.
DEPRECATED: deepgram.onprem is deprecated. Use deepgram.speak.selfhosted instead.
"""
return self.Version(self._config, "selfhosted")

Expand All @@ -279,11 +313,16 @@ def selfhosted(self):
"""
return self.Version(self._config, "selfhosted")

# for backwards compatibility
@property
@deprecation.deprecated(
deprecated_in="3.4.0",
removed_in="4.0.0",
current_version=__version__,
details="deepgram.asynconprem is deprecated. Use deepgram.speak.asyncselfhosted instead.",
)
def asynconprem(self):
"""
Returns an AsyncSelfHostedClient instance for interacting with Deepgram's on-premises API.
DEPRECATED: deepgram.asynconprem is deprecated. Use deepgram.speak.asyncselfhosted instead.
"""
return self.Version(self._config, "asyncselfhosted")

Expand Down Expand Up @@ -348,22 +387,8 @@ def v(self, version: str = ""):
parent = "manage"
filename = "async_client"
classname = "AsyncManageClient"
case "speak":
parent = "speak"
filename = "client"
classname = "SpeakClient"
case "asyncspeak":
parent = "speak"
filename = "async_client"
classname = "AsyncSpeakClient"
case "speak-stream":
parent = "speak"
filename = "client_stream"
classname = "SpeakStreamClient"
case "asyncspeak-stream":
parent = "speak"
filename = "async_client_stream"
classname = "AsyncSpeakStreamClient"
return AsyncSpeakRESTClient(self._config)
case "selfhosted":
parent = "selfhosted"
filename = "client"
Expand Down Expand Up @@ -400,4 +425,5 @@ def v(self, version: str = ""):
self._logger.notice("Version.v succeeded")
self._logger.debug("Version.v LEAVE")
return my_class_instance

# pylint: enable-msg=too-many-statements
Loading
Loading