Skip to content

Commit

Permalink
Merge pull request #189 from dvonthenen/fix-setuptools-packaging
Browse files Browse the repository at this point in the history
Fix SetupTools Packaging
  • Loading branch information
davidvonthenen authored Nov 28, 2023
2 parents 965100d + a2f9eaa commit 3951b78
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 82 deletions.
2 changes: 1 addition & 1 deletion deepgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

# version
__version__ = '0.0.0'
__version__ = '3.0.0'

# entry point for the deepgram python sdk
from .client import DeepgramClient, DeepgramApiKeyError
Expand Down
7 changes: 3 additions & 4 deletions deepgram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +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

import re
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode
from typing import Optional

from .options import DeepgramClientOptions
from .errors import DeepgramApiKeyError

from .clients.listen import ListenClient
from .clients.manage.client import ManageClient # FUTURE VERSIONINING:, ManageClientV1
from .clients.onprem.client import OnPremClient # FUTURE VERSIONINING: , OnPremClientV1

from .options import DeepgramClientOptions
from .errors import DeepgramApiKeyError

class DeepgramClient:
"""
Represents a client for interacting with the Deepgram API.
Expand Down
1 change: 0 additions & 1 deletion deepgram/clients/abstract_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import httpx
import json
from typing import Dict, Any, Optional

from ..options import DeepgramClientOptions
from .errors import DeepgramError, DeepgramApiError, DeepgramUnknownApiError
Expand Down
34 changes: 33 additions & 1 deletion deepgram/clients/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ..options import DeepgramClientOptions
from .prerecorded.client import PreRecordedClient # FUTURE VERSIONINING:, PreRecordedClientV1
from .live.client import LiveClient, LegacyLiveClient # FUTURE VERSIONINING:, LiveClientV1
from typing import Dict, Any, Optional

class ListenClient:
def __init__(self, config: DeepgramClientOptions):
Expand All @@ -32,3 +31,36 @@ def legacylive(self):
# @property
# def live_v1(self):
# return LiveClientV1(self.config)

# INTERNAL CLASSES
class Version:
def __init__(self, parent : str, version: int = 0):
self.parent = parent
self.version = version

@property
def latest(self):
match self.parent:
case "live":
return LiveClient(self.config)
case "legacylive":
return LegacyLiveClient(self.config)
case _:
raise Exception("Invalid parent")

@property
def v(self):
if self.version == 0:
raise Exception("Invalid version")

className = ""
match self.parent:
case "manage":
className = "ManageClient"
case "onprem":
className = "OnPremClient"
case _:
raise Exception("Invalid parent")

myClass = __import__(f".{self.parent}.v{self.version}.client.{className}")
return myClass
6 changes: 3 additions & 3 deletions deepgram/clients/live/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# 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 LiveClientV1
from .v1_legacy_client import LegacyLiveClientV1
from .v1_options import LiveOptionsV1
from .v1.client import LiveClient as LiveClientV1
from .v1.legacy_client import LegacyLiveClient as LegacyLiveClientV1
from .v1.options import LiveOptions as LiveOptionsV1

'''
The client.py points to the current supported version in the SDK.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Copyright 2023 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 ...options import DeepgramClientOptions
from .v1_options import LiveOptionsV1
from .enums import LiveTranscriptionEvents
from .v1_response import LiveResultResponse, MetadataResponse, ErrorResponse
from .helpers import convert_to_websocket_url, append_query_params
from .errors import DeepgramError, DeepgramWebsocketError

import json
from websockets.sync.client import connect
import threading
import time

from ....options import DeepgramClientOptions
from ..enums import LiveTranscriptionEvents
from ..helpers import convert_to_websocket_url, append_query_params
from ..errors import DeepgramError, DeepgramWebsocketError

from .response import LiveResultResponse, MetadataResponse, ErrorResponse
from .options import LiveOptions

PING_INTERVAL = 5

class LiveClientV1:
class LiveClient:
"""
Client for interacting with Deepgram's live transcription services over WebSockets.
Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, config: DeepgramClientOptions):
self._event_handlers = { event: [] for event in LiveTranscriptionEvents }
self.websocket_url = convert_to_websocket_url(self.config.url, self.endpoint)

def __call__(self, options: LiveOptionsV1 = None):
def __call__(self, options: LiveOptions = None):
self.options = options
return self

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Copyright 2023 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 ...options import DeepgramClientOptions
from .v1_options import LiveOptionsV1
from .enums import LiveTranscriptionEvents
from .helpers import convert_to_websocket_url, append_query_params
from .errors import DeepgramError

import asyncio
import json
import websockets

class LegacyLiveClientV1:
from ....options import DeepgramClientOptions
from ..enums import LiveTranscriptionEvents
from ..helpers import convert_to_websocket_url, append_query_params
from ..errors import DeepgramError

from .options import LiveOptions

class LegacyLiveClient:
"""
Client for interacting with Deepgram's live transcription services over WebSockets.
Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(self, config: DeepgramClientOptions):
self._event_handlers = { event: [] for event in LiveTranscriptionEvents }
self.websocket_url = convert_to_websocket_url(self.config.url, self.endpoint)

async def __call__(self, options: LiveOptionsV1 = None):
async def __call__(self, options: LiveOptions = None):
self.options = options
url_with_params = append_query_params(self.websocket_url, self.options)
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from typing import Union, List, TypedDict
from typing import List, TypedDict

class LiveOptionsV1(TypedDict, total=False):
class LiveOptions(TypedDict, total=False):
callback: str
channels: int
diarize: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from datetime import datetime
from typing import TypedDict, List, Optional, Dict
from typing import List, Optional, Dict

# Result Message

Expand Down
4 changes: 2 additions & 2 deletions deepgram/clients/manage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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_client import ManageClientV1
from .v1_response import ProjectOptionsV1, KeyOptionsV1, ScopeOptionsV1, InviteOptionsV1, UsageRequestOptionsV1, UsageSummaryOptionsV1, UsageFieldsOptionsV1
from .v1.client import ManageClient as ManageClientV1
from .v1.response import ProjectOptions as ProjectOptionsV1, KeyOptions as KeyOptionsV1, ScopeOptions as ScopeOptionsV1, InviteOptions as InviteOptionsV1, UsageRequestOptions as UsageRequestOptionsV1, UsageSummaryOptions as UsageSummaryOptionsV1, UsageFieldsOptions as UsageFieldsOptionsV1

'''
The client.py points to the current supported version in the SDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# 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_response import Project, ProjectsResponse, Message, ProjectOptionsV1, KeysResponse, KeyResponse, KeyOptionsV1, Key, MembersResponse, ScopesResponse, ScopeOptionsV1, InvitesResponse, InviteOptionsV1, UsageRequestsResponse, UsageRequestOptionsV1, UsageRequest, UsageSummaryOptionsV1, UsageSummaryResponse, UsageFieldsResponse, UsageFieldsOptionsV1, BalancesResponse, Balance
from ....options import DeepgramClientOptions
from ...abstract_client import AbstractRestfulClient

from ...options import DeepgramClientOptions
from ..abstract_client import AbstractRestfulClient
from .response import Project, ProjectsResponse, Message, KeysResponse, KeyResponse, Key, MembersResponse, ScopesResponse, InvitesResponse, UsageRequestsResponse, UsageRequest, UsageSummaryResponse, UsageFieldsResponse, BalancesResponse, Balance
from .response import ProjectOptions, KeyOptions, ScopeOptions, InviteOptions, UsageRequestOptions, UsageSummaryOptions, UsageFieldsOptions

class ManageClientV1(AbstractRestfulClient):
class ManageClient(AbstractRestfulClient):
"""
A client for managing Deepgram projects and associated resources via the Deepgram API.
Expand Down Expand Up @@ -47,12 +48,12 @@ async def get_project(self, project_id: str):
url = f"{self.config.url}/{self.endpoint}/{project_id}"
return Project.from_json(await self.get(url))

async def update_project_option(self, project_id: str, options: ProjectOptionsV1):
async def update_project_option(self, project_id: str, options: ProjectOptions):
url = f"{self.config.url}/{self.endpoint}/{project_id}"
return Message.from_json(await self.patch(url, json=options))
async def update_project(self, project_id: str, name=""):
url = f"{self.config.url}/{self.endpoint}/{project_id}"
options: ProjectOptionsV1 = {
options: ProjectOptions = {
"name": name,
}
return Message.from_json(await self.patch(url, json=options))
Expand All @@ -73,7 +74,7 @@ async def get_key(self, project_id: str, key_id: str):
url = f"{self.config.url}/{self.endpoint}/{project_id}/keys/{key_id}"
return KeyResponse.from_json(await self.get(url))

async def create_key(self, project_id: str, options: KeyOptionsV1):
async def create_key(self, project_id: str, options: KeyOptions):
url = f"{self.config.url}/{self.endpoint}/{project_id}/keys"
return Key.from_json(await self.post(url, json=options))

Expand All @@ -95,7 +96,7 @@ async def get_member_scopes(self, project_id: str, member_id: str):
url = f"{self.config.url}/{self.endpoint}/{project_id}/members/{member_id}/scopes"
return ScopesResponse.from_json(await self.get(url))

async def update_member_scope(self, project_id: str, member_id: str, options: ScopeOptionsV1):
async def update_member_scope(self, project_id: str, member_id: str, options: ScopeOptions):
url = f"{self.config.url}/{self.endpoint}/{project_id}/members/{member_id}/scopes"
return Message.from_json(await self.put(url, json=options))

Expand All @@ -106,12 +107,12 @@ async def get_invites(self, project_id: str):
url = f"{self.config.url}/{self.endpoint}/{project_id}/invites"
return InvitesResponse.from_json(await self.get(url))

async def send_invite_options(self, project_id: str, options: InviteOptionsV1):
async def send_invite_options(self, project_id: str, options: InviteOptions):
url = f"{self.config.url}/{self.endpoint}/{project_id}/invites"
return Message.from_json(await self.post(url, json=options))
async def send_invite(self, project_id: str, email: str, scope="member"):
url = f"{self.config.url}/{self.endpoint}/{project_id}/invites"
options: InviteOptionsV1 = {
options: InviteOptions = {
"email": email,
"scope": scope,
}
Expand All @@ -126,19 +127,19 @@ async def leave_project(self, project_id: str):
return Message.from_json(await self.delete(url))

# usage
async def get_usage_requests(self, project_id: str, options: UsageRequestOptionsV1):
async def get_usage_requests(self, project_id: str, options: UsageRequestOptions):
url = f"{self.config.url}/{self.endpoint}/{project_id}/requests"
return UsageRequestsResponse.from_json(await self.get(url, options))

async def get_usage_request(self, project_id: str, request_id: str):
url = f"{self.config.url}/{self.endpoint}/{project_id}/requests/{request_id}"
return UsageRequest.from_json(await self.get(url))

async def get_usage_summary(self, project_id: str, options: UsageSummaryOptionsV1):
async def get_usage_summary(self, project_id: str, options: UsageSummaryOptions):
url = f"{self.config.url}/{self.endpoint}/{project_id}/usage"
return UsageSummaryResponse.from_json(await self.get(url, options))

async def get_usage_fields(self, project_id: str, options: UsageFieldsOptionsV1):
async def get_usage_fields(self, project_id: str, options: UsageFieldsOptions):
url = f"{self.config.url}/{self.endpoint}/{project_id}/usage/fields"
return UsageFieldsResponse.from_json(await self.get(url, options))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from datetime import datetime
from typing import TypedDict, List, Optional, Dict
from typing import TypedDict, List, Optional

# Result Message

Expand Down Expand Up @@ -41,7 +41,7 @@ def __getitem__(self, key):
_dict["projects"] = [Project.from_dict(project) for project in _dict["projects"]]
return _dict[key]

class ProjectOptionsV1(TypedDict, total=False):
class ProjectOptions(TypedDict, total=False):
name: Optional[str]

# Members
Expand Down Expand Up @@ -107,7 +107,7 @@ def __getitem__(self, key):
_dict["api_keys"] = [KeyResponse.from_dict(key) for key in _dict["api_keys"]]
return _dict[key]

class KeyOptionsV1(TypedDict):
class KeyOptions(TypedDict):
comment: Optional[str]
scopes: Optional[List[str]]
tags: Optional[List[str]]
Expand All @@ -124,7 +124,7 @@ def __getitem__(self, key):
_dict = self.to_dict()
return _dict[key]

class ScopeOptionsV1(TypedDict):
class ScopeOptions(TypedDict):
scope: str

# Invites
Expand All @@ -150,7 +150,7 @@ def __getitem__(self, key):
_dict["invites"] = [Invite.from_dict(invite) for invite in _dict["invites"]]
return _dict[key]

class InviteOptionsV1:
class InviteOptions:
email: Optional[str]
scope: Optional[str]

Expand Down Expand Up @@ -244,13 +244,13 @@ def __getitem__(self, key):
_dict["requests"] = [UsageRequest.from_dict(request) for request in _dict["requests"]]
return _dict[key]

class UsageRequestOptionsV1(TypedDict):
class UsageRequestOptions(TypedDict):
start: Optional[str]
end: Optional[str]
limit: Optional[int]
status: Optional[str]

class UsageSummaryOptionsV1(TypedDict):
class UsageSummaryOptions(TypedDict):
start: Optional[str]
end: Optional[str]
accessor: Optional[str]
Expand Down Expand Up @@ -339,7 +339,7 @@ def __getitem__(self, key):
_dict["models"] = [UsageModel.from_dict(model) for model in _dict["models"]]
return _dict[key]

class UsageFieldsOptionsV1(TypedDict):
class UsageFieldsOptions(TypedDict):
start: Optional[str]
end: Optional[str]

Expand Down
2 changes: 1 addition & 1 deletion deepgram/clients/onprem/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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 OnPremClientV1
from .v1.client import OnPremClient as OnPremClientV1

'''
The client.py points to the current supported version in the SDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT

from ..abstract_client import AbstractRestfulClient
from ...abstract_client import AbstractRestfulClient

class OnPremClientV1(AbstractRestfulClient):
class OnPremClient(AbstractRestfulClient):
"""
Client for interacting with Deepgram's on-premises API.
Expand Down
6 changes: 2 additions & 4 deletions deepgram/clients/prerecorded/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +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 .source import UrlSource, FileSource

from .v1_client import PreRecordedClientV1
from .v1_options import PrerecordedOptionsV1
from .v1.client import PreRecordedClient as PreRecordedClientV1
from .v1.options import PrerecordedOptions as PrerecordedOptionsV1
from .source import PrerecordedSource, FileSource, UrlSource

'''
Expand Down
Loading

0 comments on commit 3951b78

Please sign in to comment.