This release is a pre-release and may not be stable for production use.
Deepgram API Python Library
Power your apps with world-class speech and Language AI models
Table of Contents
- Documentation
- Installation
- Reference
- Usage
- Authentication
- Async Client
- Exception Handling
- Advanced Features
- Websockets
- Advanced
- Contributing
- Community Code of Conduct
- License
Documentation
API reference documentation is available here.
Installation
pip install deepgram-sdk
Reference
A full reference for this library is available here.
Usage
Instantiate and use the client with the following:
from deepgram import DeepgramClient
client = DeepgramClient(
api_key="YOUR_API_KEY",
)
client.listen.v1.media.transcribe_file()
Authentication
The Deepgram SDK supports two authentication methods:
Access Token Authentication
Use access tokens for temporary or scoped access (recommended for client-side applications):
from deepgram import DeepgramClient
# Explicit access token
client = DeepgramClient(access_token="YOUR_ACCESS_TOKEN")
# Or via environment variable DEEPGRAM_TOKEN
client = DeepgramClient()
# Generate access tokens using your API key
auth_client = DeepgramClient(api_key="YOUR_API_KEY")
token_response = auth_client.auth.v1.tokens.grant()
token_client = DeepgramClient(access_token=token_response.access_token)
API Key Authentication
Use your Deepgram API key for server-side applications:
from deepgram import DeepgramClient
# Explicit API key
client = DeepgramClient(api_key="YOUR_API_KEY")
# Or via environment variable DEEPGRAM_API_KEY
client = DeepgramClient()
Environment Variables
The SDK automatically discovers credentials from these environment variables:
DEEPGRAM_TOKEN- Your access token (takes precedence)DEEPGRAM_API_KEY- Your Deepgram API key
Precedence: Explicit parameters > Environment variables
Async Client
The SDK also exports an async client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use httpx.AsyncClient() instead of httpx.Client() (e.g. for the httpx_client parameter of this client).
import asyncio
from deepgram import AsyncDeepgramClient
client = AsyncDeepgramClient(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.listen.v1.media.transcribe_file()
asyncio.run(main())
Exception Handling
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.
from deepgram.core.api_error import ApiError
try:
client.listen.v1.media.transcribe_file(...)
except ApiError as e:
print(e.status_code)
print(e.body)
Advanced Features
Raw Response Access
Access raw HTTP response data including headers:
from deepgram import DeepgramClient
client = DeepgramClient()
response = client.listen.v1.media.with_raw_response.transcribe_file(
request=audio_data,
model="nova-3"
)
print(response.headers) # Access response headers
print(response.data) # Access the response object
Request Configuration
Configure timeouts, retries, and other request options:
from deepgram import DeepgramClient
# Global client configuration
client = DeepgramClient(timeout=30.0)
# Per-request configuration
response = client.listen.v1.media.transcribe_file(
request=audio_data,
model="nova-3",
request_options={
"timeout_in_seconds": 60,
"max_retries": 3
}
)
Custom HTTP Client
Use a custom httpx client for advanced networking features:
import httpx
from deepgram import DeepgramClient
client = DeepgramClient(
httpx_client=httpx.Client(
proxies="http://proxy.example.com",
timeout=httpx.Timeout(30.0)
)
)
Retry Configuration
The SDK automatically retries failed requests with exponential backoff:
# Automatic retries for 408, 429, and 5xx status codes
response = client.listen.v1.media.transcribe_file(
request=audio_data,
model="nova-3",
request_options={"max_retries": 3}
)
Websockets
The SDK supports both sync and async websocket connections for real-time, low-latency communication. Sockets can be created using the connect method, which returns a context manager.
You can either iterate through the returned SocketClient to process messages as they arrive, or attach handlers to respond to specific events.
# Connect to the websocket (Sync)
import threading
from deepgram import DeepgramClient
client = DeepgramClient(...)
with client.v1.connect() as socket:
# Iterate over the messages as they arrive
for message in socket
print(message)
# Or, attach handlers to specific events
socket.on(EventType.OPEN, lambda _: print("open"))
socket.on(EventType.MESSAGE, lambda message: print("received message", message))
socket.on(EventType.CLOSE, lambda _: print("close"))
socket.on(EventType.ERROR, lambda error: print("error", error))
# Start the listening loop in a background thread
listener_thread = threading.Thread(target=socket.start_listening, daemon=True)
listener_thread.start()
# Connect to the websocket (Async)
import asyncio
from deepgram import AsyncDeepgramClient
client = AsyncDeepgramClient(...)
async with client.v1.connect() as socket:
# Iterate over the messages as they arrive
async for message in socket
print(message)
# Or, attach handlers to specific events
socket.on(EventType.OPEN, lambda _: print("open"))
socket.on(EventType.MESSAGE, lambda message: print("received message", message))
socket.on(EventType.CLOSE, lambda _: print("close"))
socket.on(EventType.ERROR, lambda error: print("error", error))
# Start listening for events in an asyncio task
listen_task = asyncio.create_task(socket.start_listening())
Advanced
Access Raw Response Data
The SDK provides access to raw response data, including headers, through the .with_raw_response property.
The .with_raw_response property returns a "raw" client that can be used to access the .headers and .data attributes.
from deepgram import DeepgramClient
client = DeepgramClient(
...,
)
response = client.listen.v1.media.with_raw_response.transcribe_file(...)
print(response.headers) # access the response headers
print(response.data) # access the underlying object
Retries
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Use the max_retries request option to configure this behavior.
client.listen.v1.media.transcribe_file(..., request_options={
"max_retries": 1
})
Timeouts
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
from deepgram import DeepgramClient
client = DeepgramClient(
...,
timeout=20.0,
)
# Override timeout for a specific method
client.listen.v1.media.transcribe_file(..., request_options={
"timeout_in_seconds": 1
})
Custom Client
You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies
and transports.
import httpx
from deepgram import DeepgramClient
client = DeepgramClient(
...,
httpx_client=httpx.Client(
proxy="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
Community Code of Conduct
Please see our community code of conduct before contributing to this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for deepgram-sdk 6.0.0b2
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-6.0.0b2.tar.gz | 171.5 kB | With provenance | Details for deepgram_sdk-6.0.0b2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deepgram_sdk-6.0.0b2-py3-none-any.whl | Python 3 | none | any | Details for deepgram_sdk-6.0.0b2-py3-none-any.whl |
Total release size: 677.5 kB
Release files / deepgram_sdk-6.0.0b2.tar.gz
| Download URL | deepgram_sdk-6.0.0b2.tar.gz |
|---|---|
| Size | 171.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd9549e8c1614f9d330e9b6a22aaf29f7530a06f5410f557872252f253b9ddd7
|
|
BLAKE2b-256 checksum How to use checksums |
71caf494d0faf9ab74c4c75a084909d53c47a6fccc09bee9a5c12f521e9f10ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.
Transparency logRelease files / deepgram_sdk-6.0.0b2-py3-none-any.whl
| Download URL | deepgram_sdk-6.0.0b2-py3-none-any.whl |
|---|---|
| Size | 506.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf38a665753b7d18761475f73b0cab053188c3a4950a57d079244b25ecfdc393
|
|
BLAKE2b-256 checksum How to use checksums |
f2a3949bccc8016300608cdba5219a1ec0c44e066e935feeaa1d4eccc22afb09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.
Transparency logSecurity for deepgram-sdk 6.0.0b2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for deepgram_sdk-6.0.0b2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.
Transparency logA 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.