Deepgram Python SDK
Official Python SDK for Deepgram. Power your apps with world-class speech and Language AI models.
This SDK only supports hosted usage of api.deepgram.com.
- Deepgram Python SDK
- Documentation
- Getting an API Key
- Requirements
- Installation
- Quickstarts
- Examples
- Development and Contributing
- Getting Help
Documentation
You can learn more about the Deepgram API at developers.deepgram.com.
Getting an API Key
🔑 To access the Deepgram API you will need a free Deepgram API Key.
Requirements
Python (version ^3.10)
NOTE: Althought many older versions should work.
Installation
pip install deepgram-sdk
Quickstarts
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.
PreRecorded Audio Transcription Quickstart
You can find a walkthrough on our documentation site. Transcribing Pre-Recorded Audio can be done using the following sample code:
AUDIO_URL = {
"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"
}
# STEP 1 Create a Deepgram client using the API key from environment variables
deepgram = DeepgramClient()
# STEP 2 Call the transcribe_url method on the prerecorded class
options = PrerecordedOptions(
model="nova",
smart_format=True,
summarize="v2",
)
url_response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options)
print(url_response)
Live Audio Transcription Quickstart
You can find a walkthrough on our documentation site. Transcribing Live Audio can be done using the following sample code:
deepgram = DeepgramClient()
# Create a websocket connection to Deepgram
options = LiveOptions(
punctuate=True,
language="en-US",
encoding="linear16",
channels=1,
sample_rate=16000,
)
def on_message(result=None):
if result is None:
return
sentence = result.channel.alternatives[0].transcript
if len(sentence) == 0:
return
print(f"speaker: {sentence}")
def on_metadata(metadata=None):
if metadata is None:
return
print(f"\n{metadata}\n")
def on_error(error=None):
if error is None:
return
print(f"\n{error}\n")
dg_connection = deepgram.listen.live.v("1")
dg_connection.start(options)
dg_connection.on(LiveTranscriptionEvents.Transcript, on_message)
dg_connection.on(LiveTranscriptionEvents.Metadata, on_metadata)
dg_connection.on(LiveTranscriptionEvents.Error, on_error)
# create microphone
microphone = Microphone(dg_connection.send)
# start microphone
microphone.start()
# wait until finished
input("Press Enter to stop recording...\n\n")
# Wait for the microphone to close
microphone.finish()
# Indicate that we've finished
dg_connection.finish()
print("Finished")
Examples
There are examples for every API call in this SDK. You can find all of these examples in the examples folder at the root of this repo.
These examples provide:
-
PreRecorded Audio Transcription:
- From an Audio File - examples/prerecorded/file
- From an URL - examples/prerecorded/url
-
Live Audio Transcription:
- From a Microphone - examples/streaming/microphone
- From an HTTP Endpoint - examples/streaming/http
-
Management API exercise the full CRUD operations for:
- Balances - examples/manage/balances
- Invitations - examples/manage/invitations
- Keys - examples/manage/keys
- Members - examples/manage/members
- Projects - examples/manage/projects
- Scopes - examples/manage/scopes
- Usage - examples/manage/usage
To run each example set the DEEPGRAM_API_KEY as an environment variable, then cd into each example folder and execute the example: go run main.py.
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. Then see the Contribution guidelines for more information.
Getting Help
We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:
Metadata
Release files for deepgram-sdk 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deepgram-sdk-3.0.0.tar.gz | 28.2 kB | Without provenance | Details for deepgram-sdk-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deepgram_sdk-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for deepgram_sdk-3.0.0-py3-none-any.whl |
Total release size: 77.5 kB
Release files / deepgram-sdk-3.0.0.tar.gz
| Download URL | deepgram-sdk-3.0.0.tar.gz |
|---|---|
| Size | 28.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c65570cd61acf05fddeba0a9cca7473cb097e29e93753d89918e14f8ed87db35
|
|
BLAKE2b-256 checksum How to use checksums |
a2d1a5080b20631461cc18d3e0749bbc602ec6870f28286837372e53d8c1fce2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / deepgram_sdk-3.0.0-py3-none-any.whl
| Download URL | deepgram_sdk-3.0.0-py3-none-any.whl |
|---|---|
| Size | 49.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0218d64487c82ac9950361ff9c532911559b25ca17be529c443b86454f07c40
|
|
BLAKE2b-256 checksum How to use checksums |
7305e3052fbe3b6508588690c49ec9d699ce0f43f87c8012c2bcfd1aaf18a993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for deepgram-sdk 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.