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

adds python-v3 files #156

Merged
merged 8 commits into from
Nov 14, 2023
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.egg-info
*/__pycache__/
**/__pycache__/
dist/
.venv
venv/
venv.bak/
build/
build/
.env
89 changes: 21 additions & 68 deletions deepgram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,30 @@
from typing import Union
import re
from ._types import Options
from .keys import Keys
from .transcription import Transcription
from .projects import Projects
from .usage import Usage
from .billing import Billing
from .members import Members
from .scopes import Scopes
from .invitations import Invitations
from .extra import Extra
from .errors import DeepgramSetupError, DeepgramApiError
from deepgram.deepgram_client import DeepgramClient
from .types.deepgram_client_options import DeepgramClientOptions


def api_key_is_valid(api_key: str) -> bool:
pattern = r"^[a-f0-9]{40}$"
return re.match(pattern, api_key) is not None
def create_client(api_key: str, config_options: DeepgramClientOptions = None) -> DeepgramClient:
"""
Create a DeepgramClient instance with the provided API key and optional configuration options.

This function initializes and returns a DeepgramClient instance, which can be used to interact with the Deepgram API. You can provide an API key for authentication and customize the client's configuration by passing a DeepgramClientOptions object.

class Deepgram:
def __init__(self, options: Union[str, Options]) -> None:
if not isinstance(options, (str, dict)):
raise DeepgramSetupError("`options` must be a dictionary or an API key string")
Args:
api_key (str): The Deepgram API key used for authentication.
config_options (DeepgramClientOptions, optional): An optional configuration object specifying client options. If not provided, the default settings will be used.

# Convert to dictionary if the api key was passed as a string
if isinstance(options, str):
options: Options = {"api_key": options}
Returns:
DeepgramClient: An instance of the DeepgramClient class for making requests to the Deepgram API.

if "api_key" not in options:
raise DeepgramSetupError("API key is required")
if not api_key_is_valid(options["api_key"]):
raise DeepgramSetupError("Invalid API key")
Example usage:
To create a DeepgramClient instance with a custom configuration:

if "api_url" in options and options.get("api_url", None) is None:
raise DeepgramSetupError("API URL must be valid or omitted")
>>> api_key = "your_api_key"
>>> custom_options = DeepgramClientOptions(global_options={"url": "custom_url", "headers": {"Custom-Header": "value"}})
>>> client = create_client(api_key, config_options=custom_options)

self.options = options
Example usage with default settings:

@property
def keys(self) -> Keys:
return Keys(self.options)

@property
def transcription(self) -> Transcription:
return Transcription(self.options)

@property
def projects(self) -> Projects:
return Projects(self.options)

@property
def usage(self) -> Usage:
return Usage(self.options)

@property
def billing(self) -> Billing:
return Billing(self.options)

@property
def members(self) -> Members:
return Members(self.options)

@property
def scopes(self) -> Scopes:
return Scopes(self.options)

@property
def invitations(self) -> Invitations:
return Invitations(self.options)

@property
def extra(self) -> Extra:
return Extra(self.options)


__all__ = [Deepgram, DeepgramSetupError, DeepgramApiError]
>>> api_key = "your_api_key"
>>> client = create_client(api_key)
"""
return DeepgramClient(api_key, config_options)
1 change: 0 additions & 1 deletion deepgram/_constants.py

This file was deleted.

12 changes: 0 additions & 12 deletions deepgram/_enums.py

This file was deleted.

Loading