diff --git a/README.md b/README.md index 33594618..aa8313a5 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,58 @@ Official Python SDK for [Deepgram](https://www.deepgram.com/). Power your apps with world-class speech and Language AI models. -- [Deepgram Python SDK](#deepgram-python-sdk) -- [Documentation](#documentation) -- [Getting an API Key](#getting-an-api-key) -- [Requirements](#requirements) -- [Installation](#installation) -- [Quickstarts](#quickstarts) - - [PreRecorded Audio Transcription Quickstart](#prerecorded-audio-transcription-quickstart) - - [Live Audio Transcription Quickstart](#live-audio-transcription-quickstart) - - [Self-Hosted](#self-hosted) -- [Examples](#examples) +- [Pre-Recorded (Synchronous)](#pre-recorded-synchronous) + - [Remote Files (Synchronous)](#remote-files-synchronous) + - [Local Files (Synchronous)](#local-files-synchronous) +- [Pre-Recorded (Asynchronous / Callbacks)](#pre-recorded-asynchronous--callbacks) + - [Remote Files (Asynchronous)](#remote-files-asynchronous) + - [Local Files (Asynchronous)](#local-files-asynchronous) +- [Streaming Audio](#streaming-audio) +- [Transcribing to Captions](#transcribing-to-captions) +- [Voice Agent](#voice-agent) +- [Text to Speech REST](#text-to-speech-rest) +- [Text to Speech Streaming](#text-to-speech-streaming) +- [Text Intelligence](#text-intelligence) +- [Authentication](#authentication) + - [Get Token Details](#get-token-details) + - [Grant Token](#grant-token) +- [Projects](#projects) + - [Get Projects](#get-projects) + - [Get Project](#get-project) + - [Update Project](#update-project) + - [Delete Project](#delete-project) +- [Keys](#keys) + - [List Keys](#list-keys) + - [Get Key](#get-key) + - [Create Key](#create-key) + - [Delete Key](#delete-key) +- [Members](#members) + - [Get Members](#get-members) + - [Remove Member](#remove-member) +- [Scopes](#scopes) + - [Get Member Scopes](#get-member-scopes) + - [Update Scope](#update-scope) +- [Invitations](#invitations) + - [List Invites](#list-invites) + - [Send Invite](#send-invite) + - [Delete Invite](#delete-invite) + - [Leave Project](#leave-project) +- [Usage](#usage) + - [Get All Requests](#get-all-requests) + - [Get Request](#get-request) + - [Summarize Usage](#summarize-usage) + - [Get Fields](#get-fields) +- [Billing](#billing) + - [Get All Balances](#get-all-balances) + - [Get Balance](#get-balance) +- [Models](#models) + - [Get All Project Models](#get-all-project-models) + - [Get Model](#get-model) +- [On-Prem APIs](#on-prem-apis) + - [List On-Prem credentials](#list-on-prem-credentials) + - [Get On-Prem credentials](#get-on-prem-credentials) + - [Create On-Prem credentials](#create-on-prem-credentials) + - [Delete On-Prem credentials](#delete-on-prem-credentials) - [Logging](#logging) - [Backwards Compatibility](#backwards-compatibility) - [Development and Contributing](#development-and-contributing) @@ -34,238 +76,656 @@ You can learn more about the Deepgram API at [developers.deepgram.com](https://d ## Installation -To install the latest version available (which will guarantee change over time): +To install the latest version available: ```sh pip install deepgram-sdk ``` -If you are going to write an application to consume this SDK, it's [highly recommended](https://discuss.python.org/t/how-to-pin-a-package-to-a-specific-major-version-or-lower/17077) and a [programming staple](https://www.easypost.com/dependency-pinning-guide) to pin to at **least** a major version of an SDK (ie `==2.*`) or **with due diligence**, to a minor and/or specific version (ie `==2.1.*` or `==2.12.0`, respectively). If you are unfamiliar with [semantic versioning or semver](https://semver.org/), it's a must-read. +## Initialization -In a `requirements.txt` file, pinning to a major (or minor) version, like if you want to stick to using the SDK `v2.12.0` release, that can be done like this: +All of the examples below will require `DeepgramClient`. -```sh -deepgram-sdk==2.* +```python +from deepgram import DeepgramClient + +# Initialize the client +deepgram = DeepgramClient("YOUR_API_KEY") # Replace with your API key ``` -Or using pip: +## Pre-Recorded (Synchronous) -```sh -pip install deepgram-sdk==2.* +### Remote Files (Synchronous) + +Transcribe audio from a URL. + +```python + +from deepgram import PrerecordedOptions + +response = deepgram.listen.rest.v("1").transcribe_url( + source={"url": "https://dpgr.am/spacewalk.wav"}, + options=PrerecordedOptions(model="nova-3") # Apply other options +) ``` -Pinning to a specific version can be done like this in a `requirements.txt` file: +[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen). -```sh -deepgram-sdk==2.12.0 +[See the Example for more info](./examples/speech-to-text/rest/sync/url/main.py). + +### Local Files (Synchronous) + +Transcribe audio from a file. + +```python +from deepgram import PrerecordedOptions + +response = deepgram.listen.rest.v("1").transcribe_file( + source=open("path/to/your/audio.wav", "rb"), + options=PrerecordedOptions(model="nova-3") # Apply other options +) ``` -Or using pip: +[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen). -```sh -pip install deepgram-sdk==2.12.0 +[See the Example for more info](./examples/speech-to-text/rest/sync/file/main.py). + +## Pre-Recorded (Asynchronous / Callbacks) + +### Remote Files (Asynchronous) + +Transcribe audio from a URL. + +```python +from deepgram import PrerecordedOptions + +response = deepgram.listen.rest.v("1").transcribe_url_async( + source={"url": "https://dpgr.am/spacewalk.wav"}, + callback_url="https://your-callback-url.com/webhook", + options=PrerecordedOptions(model="nova-3") # Apply other options +) ``` -We guarantee that major interfaces will not break in a given major semver (ie `2.*` release). However, all bets are off moving from a `2.*` to `3.*` major release. This follows standard semver best-practices. +[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen). + +[See the Example for more info](./examples/speech-to-text/rest/async/url/main.py). + +### Local Files (Asynchronous) + +Transcribe audio from a file. -## Quickstarts +```python +from deepgram import PrerecordedOptions + +response = deepgram.listen.rest.v("1").transcribe_file_async( + source=open("path/to/your/audio.wav", "rb"), + callback_url="https://your-callback-url.com/webhook", + options=PrerecordedOptions(model="nova-3") # Apply other options +) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen). -This SDK aims to reduce complexity and abtract/hide some internal Deepgram details that clients shouldn't need to know about. However you can still tweak options and settings if you need. +[See the Example for more info](./examples/speech-to-text/rest/async/file/main.py). -### PreRecorded Audio Transcription Quickstart +## Streaming Audio -You can find a [walkthrough](https://developers.deepgram.com/docs/python-sdk-pre-recorded-transcription) on our documentation site. Transcribing Pre-Recorded Audio can be done using the following sample code: +Transcribe streaming audio. ```python -AUDIO_URL = { - "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" -} +from deepgram import LiveOptions, LiveTranscriptionEvents -## STEP 1 Create a Deepgram client using the API key from environment variables -deepgram: DeepgramClient = DeepgramClient("", ClientOptionsFromEnv()) +# Create a websocket connection +connection = deepgram.listen.websocket.v("1") -## STEP 2 Call the transcribe_url method on the prerecorded class -options: PrerecordedOptions = PrerecordedOptions( - model="nova-3", - smart_format=True, +# Handle transcription events +@connection.on(LiveTranscriptionEvents.Transcript) +def handle_transcript(result): + print(result.channel.alternatives[0].transcript) + +# Start connection with streaming options +connection.start(LiveOptions(model="nova-3", language="en-US")) + +# Send audio data +connection.send(open("path/to/your/audio.wav", "rb").read()) + +# Close when done +connection.finish() +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/streaming-api). + +[See the Examples for more info](./examples/speech-to-text/websocket/). + +## Transcribing to Captions + +Transcribe audio to captions. + +### WebVTT + +```python +from deepgram_captions import DeepgramConverter, webvtt + +transcription = DeepgramConverter(dg_response) +captions = webvtt(transcription) +``` + +### SRT + +```python +from deepgram_captions import DeepgramConverter, srt + +transcription = DeepgramConverter(dg_response) +captions = srt(transcription) +``` + +[See our stand alone captions library for more information.](https://github.com/deepgram/deepgram-python-captions). + +## Voice Agent + +Configure a Voice Agent. + +```python +from deepgram import ( + SettingsOptions ) -response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options) -print(f"response: {response}\n\n") + +# Create websocket connection +connection = deepgram.agent.websocket.v("1") + +# Configure agent settings +options = SettingsOptions() +options.language = "en" +options.agent.think.provider.type = "open_ai" +options.agent.think.provider.model = "gpt-4o-mini" +options.agent.think.prompt = "You are a helpful AI assistant." +options.agent.listen.provider.type = "deepgram" +options.agent.listen.provider.model = "nova-3" +options.agent.speak.provider.type = "deepgram" +options.agent.speak.provider.model ="aura-2-thalia-en" + +options.greeting = "Hello, I'm your AI assistant." + +# Start the connection +connection.start(options) + +# Close the connection +connection.finish() ``` -### Live Audio Transcription Quickstart +This example demonstrates: + +- Setting up a WebSocket connection +- Configuring the agent with speech, language, and audio settings +- Handling various agent events (speech, transcripts, audio) +- Sending audio data and keeping the connection alive + +For a complete implementation, you would need to: + +1. Add your audio input source (e.g., microphone) +2. Implement audio playback for the agent's responses +3. Handle any function calls if your agent uses them +4. Add proper error handling and connection management + +[See our API reference for more info](https://developers.deepgram.com/reference/voice-agent-api/agent). + +[See the Examples for more info](./examples/agent/). + +## Text to Speech REST -You can find a [walkthrough](https://developers.deepgram.com/docs/python-sdk-streaming-transcription) on our documentation site. Transcribing Live Audio can be done using the following sample code: +Convert text into speech using the REST API. ```python -deepgram: DeepgramClient = DeepgramClient() +from deepgram import SpeakOptions -dg_connection = deepgram.listen.websocket.v("1") +# Configure speech options +options = SpeakOptions(model="aura-2-thalia-en") -def on_open(self, open, **kwargs): - print(f"\n\n{open}\n\n") +# Convert text to speech and save to file +response = deepgram.speak.rest.v("1").save( + "output.mp3", + {"text": "Hello world!"}, + options +) +``` -def on_message(self, result, **kwargs): - sentence = result.channel.alternatives[0].transcript - if len(sentence) == 0: - return - print(f"speaker: {sentence}") +[See our API reference for more info](https://developers.deepgram.com/reference/text-to-speech-api/speak). -def on_metadata(self, metadata, **kwargs): - print(f"\n\n{metadata}\n\n") +[See the Example for more info](./examples/text-to-speech/rest/). -def on_speech_started(self, speech_started, **kwargs): - print(f"\n\n{speech_started}\n\n") +## Text to Speech Streaming -def on_utterance_end(self, utterance_end, **kwargs): - print(f"\n\n{utterance_end}\n\n") +Convert streaming text into speech using a Websocket. -def on_error(self, error, **kwargs): - print(f"\n\n{error}\n\n") +```python +from deepgram import ( + SpeakWSOptions, + SpeakWebSocketEvents +) -def on_close(self, close, **kwargs): - print(f"\n\n{close}\n\n") +# Create websocket connection +connection = deepgram.speak.websocket.v("1") -dg_connection.on(LiveTranscriptionEvents.Open, on_open) -dg_connection.on(LiveTranscriptionEvents.Transcript, on_message) -dg_connection.on(LiveTranscriptionEvents.Metadata, on_metadata) -dg_connection.on(LiveTranscriptionEvents.SpeechStarted, on_speech_started) -dg_connection.on(LiveTranscriptionEvents.UtteranceEnd, on_utterance_end) -dg_connection.on(LiveTranscriptionEvents.Error, on_error) -dg_connection.on(LiveTranscriptionEvents.Close, on_close) +# Handle audio data +@connection.on(SpeakWebSocketEvents.AudioData) -options: LiveOptions = LiveOptions( - model="nova-3", - punctuate=True, - language="en-US", +# Configure streaming options +options = SpeakWSOptions( + model="aura-2-thalia-en", encoding="linear16", - channels=1, - sample_rate=16000, - ## To get UtteranceEnd, the following must be set: - interim_results=True, - utterance_end_ms="1000", - vad_events=True, + sample_rate=16000 +) + +# Start connection and send text +connection.start(options) +connection.send_text("Hello, this is a text to speech example.") +connection.flush() +connection.wait_for_complete() + +# Close when done +connection.finish() +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/text-to-speech-api/speak). + +[See the Examples for more info](./examples/text-to-speech/websocket/). + +## Text Intelligence + +Analyze text. + +```python +from deepgram import ReadOptions + +# Configure read options +options = ReadOptions( + model="nova-3", + language="en" ) -dg_connection.start(options) -## create microphone -microphone = Microphone(dg_connection.send) +# Process text for intelligence +response = deepgram.read.rest.v("1").process( + text="The quick brown fox jumps over the lazy dog.", + options=options +) +``` -## start microphone -microphone.start() +[See our API reference for more info](https://developers.deepgram.com/reference/text-intelligence-api/text-read). -## wait until finished -input("Press Enter to stop recording...\n\n") +## Authentication -## Wait for the microphone to close -microphone.finish() +### Get Token Details -## Indicate that we've finished -dg_connection.finish() +Retrieves the details of the current authentication token. -print("Finished") +```python +response = deepgram.manage.rest.v("1").get_token_details() ``` -### Self-Hosted +[See our API reference for more info](https://developers.deepgram.com/reference/authentication). -To use the SDKs with self-hosted, please see our self-hosted developer documentation for more information: +### Grant Token - +Creates a temporary token with a 30-second TTL. -## Examples +```python +response = deepgram.auth.v("1").grant_token() -There are examples for **every** API call in this SDK. You can find all of these examples in the [examples folder](https://github.com/deepgram/deepgram-python-sdk/tree/main/examples) at the root of this repo. +``` -Before running any of these examples, then you need to take a look at the README and install the following dependencies: +[See our API reference for more info](https://developers.deepgram.com/reference/token-based-auth-api/grant-token). -```bash -pip install -r examples/requirements-examples.txt +[See The Examples for more info](./examples/auth/) + +## Projects + +### Get Projects + +Returns all projects accessible by the API key. + +```python +response = deepgram.manage.v("1").get_projects() ``` -To run each example set the `DEEPGRAM_API_KEY` as an environment variable, then `cd` into each example folder and execute the example with: `python main.py` or `python3 main.py`. +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/list). -### Agent +[See The Example for more info](./examples/manage/projects/main.py). -- Simple - [examples/agent/simple](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/agent/simple/main.py) -- Async Simple - [examples/agent/async_simple](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/agent/async_simple/main.py) +### Get Project -### Text to Speech +Retrieves a specific project based on the provided project_id. -- Asynchronous - [examples/text-to-speech](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/text-to-speech/rest/file/async_hello_world/main.py) -- Synchronous - [examples/text-to-speech](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/text-to-speech/rest/file/hello_world/main.py) +```python +response = deepgram.manage.v("1").get_project(myProjectId) +``` -### Analyze Text +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/get). -- Intent Recognition - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/intent/main.py) -- Sentiment Analysis - [examples/sentiment/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/sentiment/main.py) -- Summarization - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/summary/main.py) -- Topic Detection - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/topic/main.py) +[See The Example for more info](./examples/manage/projects/main.py). -### PreRecorded Audio +### Update Project -- Transcription From an Audio File - [examples/prerecorded/file](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/rest/file/main.py) -- Transcription From an URL - [examples/prerecorded/url](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/rest/url/main.py) -- Intent Recognition - [examples/speech-to-text/rest/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/rest/intent/main.py) -- Sentiment Analysis - [examples/speech-to-text/rest/sentiment](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/rest/sentiment/main.py) -- Summarization - [examples/speech-to-text/rest/summary](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/rest/summary/main.py) -- Topic Detection - [examples/speech-to-text/rest/topic](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/rest/topic/main.py) +Update a project. -### Live Audio Transcription +```python +response = deepgram.manage.v("1").update_project(myProjectId, options) +``` -- From a Microphone - [examples/streaming/microphone](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/websocket/microphone/main.py) -- From an HTTP Endpoint - [examples/streaming/http](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/speech-to-text/rest/async_url/main.py) +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/update). -Management API exercise the full [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations for: +[See The Example for more info](./examples/manage/projects/main.py). -- Balances - [examples/manage/balances](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/balances/main.py) -- Invitations - [examples/manage/invitations](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/invitations/main.py) -- Keys - [examples/manage/keys](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/keys/main.py) -- Members - [examples/manage/members](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/members/main.py) -- Projects - [examples/manage/projects](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/projects/main.py) -- Scopes - [examples/manage/scopes](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/scopes/main.py) -- Usage - [examples/manage/usage](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/usage/main.py) +### Delete Project -## Logging +Delete a project. -This SDK provides logging as a means to troubleshoot and debug issues encountered. By default, this SDK will enable `Information` level messages and higher (ie `Warning`, `Error`, etc) when you initialize the library as follows: +```python +response = deepgram.manage.v("1").delete_project(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/delete). + +[See The Example for more info](./examples/manage/projects/main.py). + +## Keys + +### List Keys + +Retrieves all keys associated with the provided project_id. ```python -deepgram: DeepgramClient = DeepgramClient() +response = deepgram.manage.v("1").get_keys(myProjectId) ``` -To increase the logging output/verbosity for debug or troubleshooting purposes, you can set the `DEBUG` level but using this code: +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/list) + +[See The Example for more info](./examples/manage/keys/main.py). + +### Get Key + +Retrieves a specific key associated with the provided project_id. ```python -config: DeepgramClientOptions = DeepgramClientOptions( - verbose=logging.DEBUG, -) -deepgram: DeepgramClient = DeepgramClient("", config) +response = deepgram.manage.v("1").get_key(myProjectId, myKeyId) ``` -## Backwards Compatibility +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/get) -Older SDK versions will receive Priority 1 (P1) bug support only. Security issues, both in our code and dependencies, are promptly addressed. Significant bugs without clear workarounds are also given priority attention. +[See The Example for more info](./examples/manage/keys/main.py). -## Development and Contributing +### Create Key -Interested in contributing? We ❤️ pull requests! +Creates an API key with the provided scopes. -To make sure our community is safe for all, be sure to review and agree to our -[Code of Conduct](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CODE_OF_CONDUCT.md). Then see the -[Contribution](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CONTRIBUTING.md) guidelines for more information. +```python + response = deepgram.manage.v("1").create_key(myProjectId, options) +``` -### Prerequisites +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/create) -In order to develop new features for the SDK itself, you first need to uninstall any previous installation of the `deepgram-sdk` and then install/pip the dependencies contained in the `requirements.txt` then instruct python (via pip) to use the SDK by installing it locally. +[See The Example for more info](./examples/manage/keys/main.py). -From the root of the repo, that would entail: +### Delete Key -```bash -pip uninstall deepgram-sdk -pip install -r requirements.txt -pip install -e . +Deletes a specific key associated with the provided project_id. + +```python +response = deepgram.manage.v("1").delete_key(myProjectId, myKeyId) ``` +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/delete) + +[See The Example for more info](./examples/manage/keys/main.py). + +## Members + +### Get Members + +Retrieves account objects for all of the accounts in the specified project_id. + +```python +response = deepgram.manage.v("1").get_members(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/members/list). + +[See The Example for more info](./examples/manage/members/main.py). + +### Remove Member + +Removes member account for specified member_id. + +```python +response = deepgram.manage.v("1").remove_member(myProjectId, MemberId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/members/delete). + +[See The Example for more info](./examples/manage/members/main.py). + +## Scopes + +### Get Member Scopes + +Retrieves scopes of the specified member in the specified project. + +```python +response = deepgram.manage.v("1").get_member_scopes(myProjectId, memberId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/scopes/list). + +[See The Example for more info](./examples/manage/scopes/main.py). + +### Update Scope + +Updates the scope for the specified member in the specified project. + +```python +response = deepgram.manage.v("1").update_member_scope(myProjectId, memberId, options) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/scopes/update). + +[See The Example for more info](./examples/manage/scopes/main.py). + +## Invitations + +### List Invites + +Retrieves all invitations associated with the provided project_id. + +```python +response = deepgram.manage.v("1").get_invites(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/list). + +### Send Invite + +Sends an invitation to the provided email address. + +```python +response = deepgram.manage.v("1").send_invite(myProjectId, options) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/create). + +### Delete Invite + +Removes the specified invitation from the project. + +```python +response = deepgram.manage.v("1").delete_invite(myProjectId, email) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/delete). + +### Leave Project + +```python +response = deepgram.manage.v("1").leave_project(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/leave). + +## Usage + +### Get All Requests + +Retrieves all requests associated with the provided project_id based on the provided options. + +```python +response = deepgram.manage.v("1").get_usage_requests(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/list-requests). + +### Get Request + +Retrieves a specific request associated with the provided project_id + +```python +response = deepgram.manage.v("1").get_usage_request(myProjectId, RequestId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/get-request). + +### Get Fields + +Lists the features, models, tags, languages, and processing method used for requests in the specified project. + +```python +response = deepgram.manage.v("1").get_usage_fields(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/list-fields). + +### Summarize Usage + +`Deprecated` Retrieves the usage for a specific project. Use Get Project Usage Breakdown for a more comprehensive usage summary. + +```python +response = deepgram.manage.v("1").get_usage_summary(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/get). + +## Billing + +### Get All Balances + +Retrieves the list of balance info for the specified project. + +```python +response = deepgram.manage.v("1").get_balances(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/balances/list). + +### Get Balance + +Retrieves the balance info for the specified project and balance_id. + +```python +response = deepgram.manage.v("1").get_balance(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/balances/get). + +## Models + +### Get All Project Models + +Retrieves all models available for a given project. + +```python +response = deepgram.manage.v("1").get_project_models(myProjectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/list-models). + +### Get Model + +Retrieves details of a specific model. + +```python +response = deepgram.manage.v("1").get_project_model(myProjectId, ModelId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/get-model). + +## On-Prem APIs + +### List On-Prem credentials + +Lists sets of distribution credentials for the specified project. + +```python +response = deepgram.selfhosted.v("1").list_selfhosted_credentials(projectId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/list-credentials). + +### Get On-Prem credentials + +```python +response = deepgram.selfhosted.v("1").get_selfhosted_credentials(projectId, distributionCredentialsId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/get-credentials). + +### Create On-Prem credentials + +```python +response = deepgram.selfhosted.v("1").create_selfhosted_credentials(project_id, options) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/create-credentials). + +### Delete On-Prem credentials + +```python +response = deepgram.selfhosted.v("1").delete_selfhosted_credentials(projectId, distributionCredentialId) +``` + +[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/delete-credentials). + +## Pinning Versions + +To ensure your application remains stable and reliable, we recommend using version pinning in your project. This is a best practice in Python development that helps prevent unexpected changes. You can pin to a major version (like `==4.*`) for a good balance of stability and updates, or to a specific version (like `==4.1.0`) for maximum stability. We've included some helpful resources about [version pinning](https://discuss.python.org/t/how-to-pin-a-package-to-a-specific-major-version-or-lower/17077) and [dependency management](https://www.easypost.com/dependency-pinning-guide) if you'd like to learn more. For a deeper understanding of how version numbers work, check out[semantic versioning](https://semver.org/). + +In a `requirements.txt` file, you can pin to a specific version like this: + +```sh +deepgram-sdk==4.1.0 +``` + +Or using pip: + +```sh +pip install deepgram-sdk==4.1.0 +``` + +## Logging + +This SDK provides logging as a means to troubleshoot and debug issues encountered. By default, this SDK will enable `Information` level messages and higher (ie `Warning`, `Error`, etc) when you initialize the library as follows: + +```python +deepgram: DeepgramClient = DeepgramClient() +``` + +To increase the logging output/verbosity for debug or troubleshooting purposes, you can set the `DEBUG` level but using this code: + +```python +config: DeepgramClientOptions = DeepgramClientOptions( + verbose=logging.DEBUG, +) +deepgram: DeepgramClient = DeepgramClient("", config) +``` + +## Testing + ### Daily and Unit Tests If you are looking to use, run, contribute or modify to the daily/unit tests, then you need to install the following dependencies: @@ -274,7 +734,7 @@ If you are looking to use, run, contribute or modify to the daily/unit tests, th pip install -r requirements-dev.txt ``` -#### Daily Tests +### Daily Tests The daily tests invoke a series of checks against the actual/real API endpoint and save the results in the `tests/response_data` folder. This response data is updated nightly to reflect the latest response from the server. Running the daily tests does require a `DEEPGRAM_API_KEY` set in your environment variables. @@ -292,6 +752,30 @@ The unit tests invoke a series of checks against mock endpoints using the respon make unit-test ``` +## Backwards Compatibility + +We follow semantic versioning (semver) to ensure a smooth upgrade experience. Within a major version (like `4.*`), we will maintain backward compatibility so your code will continue to work without breaking changes. When we release a new major version (like moving from `3.*` to `4.*`), we may introduce breaking changes to improve the SDK. We'll always document these changes clearly in our release notes to help you upgrade smoothly. + +Older SDK versions will receive Priority 1 (P1) bug support only. Security issues, both in our code and dependencies, are promptly addressed. Significant bugs without clear workarounds are also given priority attention. + +## Development and Contributing + +Interested in contributing? We ❤️ pull requests! + +To make sure our community is safe for all, be sure to review and agree to our +[Code of Conduct](CODE_OF_CONDUCT.md). Then see the +[Contribution](CONTRIBUTING.md) guidelines for more information. + +In order to develop new features for the SDK itself, you first need to uninstall any previous installation of the `deepgram-sdk` and then install/pip the dependencies contained in the `requirements.txt` then instruct python (via pip) to use the SDK by installing it locally. + +From the root of the repo, that would entail: + +```bash +pip uninstall deepgram-sdk +pip install -r requirements.txt +pip install -e . +``` + ## Getting Help We love to hear from you so if you have questions, comments or find a bug in the diff --git a/examples/speech-to-text/rest/async_file/main.py b/examples/speech-to-text/rest/async/file/main.py similarity index 100% rename from examples/speech-to-text/rest/async_file/main.py rename to examples/speech-to-text/rest/async/file/main.py diff --git a/examples/speech-to-text/rest/async_file/preamble.wav b/examples/speech-to-text/rest/async/file/preamble.wav similarity index 100% rename from examples/speech-to-text/rest/async_file/preamble.wav rename to examples/speech-to-text/rest/async/file/preamble.wav diff --git a/examples/speech-to-text/rest/async_url/main.py b/examples/speech-to-text/rest/async/url/main.py similarity index 100% rename from examples/speech-to-text/rest/async_url/main.py rename to examples/speech-to-text/rest/async/url/main.py diff --git a/examples/speech-to-text/rest/file/main.py b/examples/speech-to-text/rest/sync/file/main.py similarity index 100% rename from examples/speech-to-text/rest/file/main.py rename to examples/speech-to-text/rest/sync/file/main.py diff --git a/examples/speech-to-text/rest/file/preamble.wav b/examples/speech-to-text/rest/sync/file/preamble.wav similarity index 100% rename from examples/speech-to-text/rest/file/preamble.wav rename to examples/speech-to-text/rest/sync/file/preamble.wav diff --git a/examples/speech-to-text/rest/sync/url/main.py b/examples/speech-to-text/rest/sync/url/main.py new file mode 100644 index 00000000..03d22420 --- /dev/null +++ b/examples/speech-to-text/rest/sync/url/main.py @@ -0,0 +1,61 @@ +# 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 + +import os +from dotenv import load_dotenv +import logging +from deepgram.utils import verboselogs +from datetime import datetime +import httpx + +from deepgram import ( + DeepgramClient, + DeepgramClientOptions, + PrerecordedOptions, + UrlSource, +) + +load_dotenv() + +# URL to the audio file to transcribe +AUDIO_URL = "https://dpgr.am/spacewalk.wav" # Replace with your audio URL + + +def main(): + try: + # STEP 1 Create a Deepgram client using the API key in the environment variables + config: DeepgramClientOptions = DeepgramClientOptions( + verbose=verboselogs.SPAM, + ) + deepgram: DeepgramClient = DeepgramClient("", config) + # OR use defaults + # deepgram: DeepgramClient = DeepgramClient() + + # STEP 2 Call the transcribe_url method on the rest class + payload: UrlSource = { + "url": AUDIO_URL, + } + + options: PrerecordedOptions = PrerecordedOptions( + model="nova-3", + smart_format=True, + ) + + before = datetime.now() + response = deepgram.listen.rest.v("1").transcribe_url( + payload, options, timeout=httpx.Timeout(300.0, connect=10.0) + ) + after = datetime.now() + + print(response.to_json(indent=4)) + print("") + difference = after - before + print(f"time: {difference.seconds}") + + except Exception as e: + print(f"Exception: {e}") + + +if __name__ == "__main__": + main() diff --git a/examples/speech-to-text/rest/url/main.py b/examples/speech-to-text/rest/url/main.py deleted file mode 100644 index e28b5594..00000000 --- a/examples/speech-to-text/rest/url/main.py +++ /dev/null @@ -1,47 +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 - -import os -from dotenv import load_dotenv -import logging -from deepgram.utils import verboselogs - -from deepgram import ( - DeepgramClient, - ClientOptionsFromEnv, - PrerecordedOptions, -) - -load_dotenv() - -AUDIO_URL = { - "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" -} - - -def main(): - try: - # STEP 1 Create a Deepgram client using the DEEPGRAM_API_KEY from your environment variables - deepgram: DeepgramClient = DeepgramClient() - - # STEP 2 Call the transcribe_url method on the rest class - options: PrerecordedOptions = PrerecordedOptions( - model="nova-3", - smart_format=True, - ) - response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options) - print(f"response: {response}\n\n") - # print(f"metadata: {response['metadata']}\n\n") - # print( - # f"transcript: {response.results.channels[0].alternatives[0]['transcript']}\n\n" - # ) - # for word in response.results.channels[0].alternatives[0].words: - # print(f"Word: {word.word}, Start: {word.start}, End: {word.end}") - - except Exception as e: - print(f"Exception: {e}") - - -if __name__ == "__main__": - main()