deepgram-sdk 7.6.0


pip install deepgram-sdk

  Latest version

Released: Jul 22, 2026

Project Links

Meta
Requires Python: >=3.10,<4.0

Classifiers

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • MacOS
  • Microsoft :: Windows
  • OS Independent
  • POSIX
  • POSIX :: Linux

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: 3.15

Topic
  • Software Development :: Libraries :: Python Modules

Typing
  • Typed

Deepgram Python SDK

Built with Fern PyPI version Python 3.10+ MIT License

The official Python SDK for Deepgram's automated speech recognition, text-to-speech, and language understanding APIs. Power your applications with world-class speech and Language AI models.

Documentation

Comprehensive API documentation and guides are available at developers.deepgram.com.

Migrating From Earlier Versions

Installation

Install the Deepgram Python SDK using pip:

pip install deepgram-sdk

Reference

  • API Reference - Complete reference for all SDK methods, parameters, and WebSocket connections

Usage

Quick Start

The Deepgram SDK provides both synchronous and asynchronous clients for all major use cases:

Real-time Speech Recognition (Listen v2)

Our newest and most advanced speech recognition model with contextual turn detection (Reference):

from deepgram import DeepgramClient
from deepgram.core.events import EventType

client = DeepgramClient()

with client.listen.v2.connect(
    model="flux-general-en",
    encoding="linear16",
    sample_rate=16000
) as connection:
    def on_message(message):
        print(f"Received {message.type} event")

    connection.on(EventType.OPEN, lambda _: print("Connection opened"))
    connection.on(EventType.MESSAGE, on_message)
    connection.on(EventType.CLOSE, lambda _: print("Connection closed"))
    connection.on(EventType.ERROR, lambda error: print(f"Error: {error}"))

    # Start listening and send audio data
    connection.start_listening()

File Transcription

Transcribe pre-recorded audio files (API Reference):

from deepgram import DeepgramClient

client = DeepgramClient()

with open("audio.wav", "rb") as audio_file:
    response = client.listen.v1.media.transcribe_file(
        request=audio_file.read(),
        model="nova-3"
    )
    print(response.results.channels[0].alternatives[0].transcript)

Text-to-Speech

Generate natural-sounding speech from text (API Reference):

from deepgram import DeepgramClient

client = DeepgramClient()

response = client.speak.v1.audio.generate(
    text="Hello, this is a sample text to speech conversion."
)

# Save the audio file
with open("output.mp3", "wb") as audio_file:
    audio_file.write(response.stream.getvalue())

Text Analysis

Analyze text for sentiment, topics, and intents (API Reference):

from deepgram import DeepgramClient

client = DeepgramClient()

response = client.read.v1.text.analyze(
    request={"text": "Hello, world!"},
    language="en",
    sentiment=True,
    summarize=True,
    topics=True,
    intents=True
)

Voice Agent (Conversational AI)

Build interactive voice agents (Reference):

from deepgram import DeepgramClient
from deepgram.agent.v1.types import (
    AgentV1Settings, AgentV1SettingsAgent,
    AgentV1SettingsAgentListen, AgentV1SettingsAgentListenProvider_V1,
    AgentV1SettingsAudio, AgentV1SettingsAudioInput,
)
from deepgram.types.think_settings_v1 import ThinkSettingsV1
from deepgram.types.think_settings_v1provider import ThinkSettingsV1Provider_OpenAi
from deepgram.types.speak_settings_v1 import SpeakSettingsV1
from deepgram.types.speak_settings_v1provider import SpeakSettingsV1Provider_Deepgram

client = DeepgramClient()

with client.agent.v1.connect() as agent:
    settings = AgentV1Settings(
        audio=AgentV1SettingsAudio(
            input=AgentV1SettingsAudioInput(encoding="linear16", sample_rate=24000)
        ),
        agent=AgentV1SettingsAgent(
            listen=AgentV1SettingsAgentListen(
                provider=AgentV1SettingsAgentListenProvider_V1(
                    type="deepgram", model="nova-3"
                )
            ),
            think=ThinkSettingsV1(
                provider=ThinkSettingsV1Provider_OpenAi(
                    type="open_ai", model="gpt-4o-mini"
                ),
                prompt="You are a helpful AI assistant.",
            ),
            speak=SpeakSettingsV1(
                provider=SpeakSettingsV1Provider_Deepgram(
                    type="deepgram", model="aura-2-asteria-en"
                )
            ),
        ),
    )

    agent.send_settings(settings)
    agent.start_listening()

Complete SDK Reference

For comprehensive documentation of all available methods, parameters, and options:

  • API Reference - Complete reference for all SDK methods including:

    • Listen (Speech-to-Text): File transcription, URL transcription, and media processing
    • Speak (Text-to-Speech): Audio generation and voice synthesis
    • Read (Text Intelligence): Text analysis, sentiment, summarization, and topic detection
    • Manage: Project management, API keys, and usage analytics
    • Auth: Token generation and authentication management
    • WebSocket connections: Listen v1/v2, Speak v1, and Agent v1 real-time streaming

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 provides full async/await support for non-blocking operations:

import asyncio
from deepgram import AsyncDeepgramClient

async def main():
    client = AsyncDeepgramClient()

    # Async file transcription
    with open("audio.wav", "rb") as audio_file:
        response = await client.listen.v1.media.transcribe_file(
            request=audio_file.read(),
            model="nova-3"
        )

    # Async WebSocket connection
    async with client.listen.v2.connect(
        model="flux-general-en",
        encoding="linear16",
        sample_rate=16000
    ) as connection:
        async def on_message(message):
            print(f"Received {message.type} event")

        connection.on(EventType.MESSAGE, on_message)
        await connection.start_listening()

asyncio.run(main())

Exception Handling

The SDK provides detailed error information for debugging and error handling:

from deepgram import DeepgramClient
from deepgram.core.api_error import ApiError

client = DeepgramClient()

try:
    response = client.listen.v1.media.transcribe_file(
        request=audio_data,
        model="nova-3"
    )
except ApiError as e:
    print(f"Status Code: {e.status_code}")
    print(f"Error Details: {e.body}")
    print(f"Request ID: {e.headers.get('x-dg-request-id', 'N/A')}")
except Exception as e:
    print(f"Unexpected error: {e}")

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)
    )
)

Custom Transports

Replace the built-in websockets transport with your own implementation for WebSocket-based APIs (Listen, Speak, Agent). This enables alternative protocols (HTTP/2, SSE), test doubles, or proxied connections.

Any class that implements the right methods can be used as a transport — no inheritance required. Pass your class (or a factory callable) as transport_factory when creating a client.

Sync transports

Implement send(), recv(), __iter__(), and close(), then pass the class to DeepgramClient:

from deepgram import DeepgramClient
from deepgram.core.events import EventType

class MyTransport:
    def __init__(self, url: str, headers: dict):
        ...  # establish your connection

    def send(self, data): ...   # send str or bytes
    def recv(self): ...         # return next message
    def __iter__(self): ...     # yield messages until closed
    def close(self): ...        # tear down connection

client = DeepgramClient(api_key="...", transport_factory=MyTransport)

with client.listen.v1.connect(model="nova-3") as connection:
    connection.on(EventType.MESSAGE, on_message)
    connection.start_listening()

Async transports

Implement async def send(), async def recv(), async def __aiter__(), and async def close(), then use AsyncDeepgramClient:

from deepgram import AsyncDeepgramClient

client = AsyncDeepgramClient(api_key="...", transport_factory=MyAsyncTransport)

async with client.listen.v1.connect(model="nova-3") as connection:
    connection.on(EventType.MESSAGE, on_message)
    await connection.start_listening()

See src/deepgram/transport_interface.py for the full protocol definitions (SyncTransport and AsyncTransport).

SageMaker transport

The deepgram-sagemaker package (source) is a ready-made async transport for running Deepgram models on AWS SageMaker endpoints. It uses HTTP/2 bidirectional streaming under the hood, but exposes the same SDK interface — just install the package and swap in a transport_factory:

pip install deepgram-sagemaker  # requires Python 3.12+
from deepgram import AsyncDeepgramClient
from deepgram_sagemaker import SageMakerTransportFactory

factory = SageMakerTransportFactory(
    endpoint_name="my-deepgram-endpoint",
    region="us-west-2",
)

# SageMaker uses AWS credentials (not Deepgram API keys)
client = AsyncDeepgramClient(api_key="unused", transport_factory=factory)

async with client.listen.v1.connect(model="nova-3") as connection:
    connection.on(EventType.MESSAGE, on_message)
    await connection.start_listening()

Note: The SageMaker transport is async-only and requires AsyncDeepgramClient.

See examples/27-transcription-live-sagemaker.py for a complete working example.

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}
)

Contributing

We welcome contributions to improve this SDK! However, please note that this library is primarily generated from our API specifications.

Development Setup

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
    
  2. Install dependencies:

    poetry install
    
  3. Install example dependencies:

    poetry run pip install -r examples/requirements.txt
    
  4. Run tests:

    poetry run pytest -rP .
    
  5. Run examples:

    python -u examples/07-transcription-live-websocket.py
    

Contribution Guidelines

See our CONTRIBUTING guide.

Requirements

  • Python 3.10+
  • See pyproject.toml for full dependency list

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.

7.6.0 Jul 22, 2026
7.5.0 Jul 15, 2026
7.4.0 Jun 26, 2026
7.3.1 Jun 03, 2026
7.3.0 Jun 01, 2026
7.2.0 May 19, 2026
7.1.1 May 12, 2026
7.1.0 May 06, 2026
7.0.0 Apr 27, 2026
6.1.1 Mar 27, 2026
6.1.0 Mar 26, 2026
6.0.1 Feb 24, 2026
6.0.0 Feb 23, 2026
6.0.0rc2 Feb 18, 2026
6.0.0rc1 Feb 16, 2026
6.0.0b2 Jan 08, 2026
6.0.0a4 Dec 19, 2025
5.3.4 Jun 26, 2026
5.3.3 Feb 24, 2026
5.3.2 Jan 29, 2026
5.3.1 Jan 08, 2026
5.3.0 Nov 03, 2025
5.2.0 Oct 21, 2025
5.1.0 Oct 16, 2025
5.0.0 Oct 02, 2025
4.8.1 Aug 02, 2025
4.8.0 Jul 25, 2025
4.7.0 Jul 21, 2025
4.6.0 Jul 11, 2025
4.5.0 Jun 25, 2025
4.3.1 Jun 13, 2025
4.3.0 Jun 10, 2025
4.2.0 Jun 09, 2025
4.1.1 Jun 06, 2025
4.1.0 May 09, 2025
4.0.0 May 05, 2025
3.11.0 Apr 14, 2025
3.10.1 Mar 03, 2025
3.10.0 Feb 11, 2025
3.9.0 Feb 03, 2025
3.8.0 Jan 07, 2025
3.7.7 Nov 20, 2024
3.7.6 Nov 04, 2024
3.7.5 Oct 21, 2024
3.7.4 Oct 18, 2024
3.7.3 Sep 30, 2024
3.7.2 Sep 27, 2024
3.7.1 Sep 26, 2024
3.7.0 Sep 24, 2024
3.6.0 Sep 18, 2024
3.5.2 Sep 11, 2024
3.5.1 Aug 24, 2024
3.5.0 Aug 14, 2024
3.4.0 Jul 15, 2024
3.3.2 Jul 09, 2024
3.3.1 Jun 13, 2024
3.3.0 Jun 12, 2024
3.2.7 Apr 24, 2024
3.2.6 Apr 17, 2024
3.2.5 Apr 08, 2024
3.2.4 Apr 05, 2024
3.2.3 Mar 27, 2024
3.2.2 Mar 20, 2024
3.2.1 Mar 13, 2024
3.2.0 Mar 11, 2024
3.1.10 Mar 11, 2024
3.1.9 Mar 08, 2024
3.1.8 Mar 07, 2024
3.1.7 Mar 01, 2024
3.1.6 Feb 29, 2024
3.1.5 Feb 27, 2024
3.1.4 Feb 14, 2024
3.1.3 Feb 06, 2024
3.1.2 Feb 01, 2024
3.1.1 Jan 29, 2024
3.1.0 Jan 22, 2024
3.0.3 Jan 10, 2024
3.0.2 Jan 04, 2024
3.0.1 Dec 28, 2023
3.0.0 Dec 21, 2023
3.0.0rc3 Dec 20, 2023
3.0.0rc2 Dec 15, 2023
3.0.0rc1 Dec 14, 2023
3.0.0b2 Dec 12, 2023
3.0.0b1 Dec 08, 2023
3.0.0a5 Dec 01, 2023
3.0.0a4 Nov 29, 2023
2.12.0 Nov 07, 2023
2.11.0 Aug 01, 2023
2.10.0 Jul 27, 2023
2.9.0 Jul 20, 2023
2.8.0 Jun 23, 2023
2.5.0 May 18, 2023
2.4.0 Apr 12, 2023
2.3.0 Jan 30, 2023
2.2.0 Dec 08, 2022
2.1.0 Nov 18, 2022
2.0.0 Nov 11, 2022
1.1.0 Oct 30, 2022
1.0.0 Oct 07, 2022
0.6.1 Sep 29, 2022
0.6.0 Sep 27, 2022
0.5.0 Sep 20, 2022
0.4.0 Aug 17, 2022
0.3.0 Jul 20, 2022
0.2.5 Mar 08, 2022
0.2.4 Jan 31, 2022
0.2.3 Jan 31, 2022
0.2.2 Jan 27, 2022
0.2.1 Oct 05, 2021
0.2.0 Sep 28, 2021
0.1.12 Aug 10, 2021
0.1.11 Jul 30, 2021
0.1.10 Jul 26, 2021
0.1.9 Jul 21, 2021
0.1.8 Jul 19, 2021
0.1.7 Jul 15, 2021
0.1.6 Jul 15, 2021
0.1.5 Jul 15, 2021
0.1.4 Jul 13, 2021
0.1.3 Jul 13, 2021
0.1.2 Jul 12, 2021
0.1.1 Jul 08, 2021
0.1.0 Jul 08, 2021

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
httpx (>=0.21.2)
pydantic (>=1.9.2)
pydantic-core (<3.0.0,>=2.18.2)
typing_extensions (>=4.0.0)
websockets (>=12.0)