Skip to main content

Deepgram Python SDK

Contributor Covenant

This is a pre-release SDK and is very likely to have breaking changes. Feel free to provide feedback via GitHub issues and suggest new features.

Official Python SDK for Deepgram's automated speech recognition APIs.

To access the API you will need a Deepgram account. Sign up for free at console.deepgram.com.

You can learn more about the full Deepgram API at developers.deepgram.com.

Getting Started

pip install deepgram-sdk
from deepgram import Deepgram

dg_client = Deepgram(YOUR_API_KEY)
# or, fully specify for an alternate endpoint
dg_client = Deepgram({
    'api_key': YOUR_API_KEY,
    'api_url': YOUR_API_URL
})

Usage

Basic transcription can be done like so:

Batch processing

from deepgram import Deepgram
import asyncio, json

DEEPGRAM_API_KEY = 'YOUR_API_KEY'
PATH_TO_FILE = 'some/file.wav'

async def main():
    # Initializes the Deepgram SDK
    dg_client = Deepgram(DEEPGRAM_API_KEY)
    # Open the audio file
    with open(PATH_TO_FILE, 'rb') as audio:
        # ...or replace mimetype as appropriate
        source = {'buffer': audio, 'mimetype': 'audio/wav'}
        response = await dg_client.transcription.prerecorded(source, {'punctuate': True})
        print(json.dumps(response, indent=4))

asyncio.run(main())

"Fake" streaming processing:

from deepgram import Deepgram
import asyncio, json

DEEPGRAM_API_KEY = 'YOUR_API_KEY'
PATH_TO_FILE = 'some/file.wav'

async def main():
    # Initializes the Deepgram SDK
    dg_client = Deepgram(DEEPGRAM_API_KEY)
    # Creates a websocket connection to Deepgram
    try:
        socket = await dg_client.transcription.live({'punctuate': True})
    except Exception as e:
        print(f'Could not open socket: {e}')
        return
    # Handle sending audio to the socket
    async def process_audio(connection):
        # Open the file
        with open(PATH_TO_FILE, 'rb') as audio:
            # Chunk up the audio to send
            CHUNK_SIZE_BYTES = 8192
            CHUNK_RATE_SEC = 0.001
            chunk = audio.read(CHUNK_SIZE_BYTES)
            while chunk:
                connection.send(chunk)
                await asyncio.sleep(CHUNK_RATE_SEC)
                chunk = audio.read(CHUNK_SIZE_BYTES)
        # Indicate that we've finished sending data
        await connection.finish()

    # Listen for the connection to close
    socket.register_handler(socket.event.CLOSE, lambda c: print(f'Connection closed with code {c}.'))
    # Print incoming transcription objects
    socket.register_handler(socket.event.TRANSCRIPT_RECEIVED, print)

    # Send the audio to the socket
    await process_audio(socket)

asyncio.run(main())

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:

Further Reading

Check out the Developer Documentation at https://developers.deepgram.com/

Metadata

Release files for deepgram-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deepgram-sdk 0.2.0
File Size Uploaded Provenance Actions
deepgram-sdk-0.2.0.tar.gz 11.8 kB Without provenance Details for deepgram-sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deepgram-sdk 0.2.0
File Interpreter ABI Platform Actions
deepgram_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for deepgram_sdk-0.2.0-py3-none-any.whl

Total release size: 24.4 kB

Release files / deepgram-sdk-0.2.0.tar.gz

Download URL deepgram-sdk-0.2.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
01a131472992d95990d1dc385e848db081f2f37145e663adc2d98fb425262b5d
BLAKE2b-256 checksum
How to use checksums
2ddc9436d6628732213ae2386f5312b7196fb64bdb3750a5492559ca93a1d3cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

Release files / deepgram_sdk-0.2.0-py3-none-any.whl

Download URL deepgram_sdk-0.2.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0dbaa13225a4d4a73d19c17c1ce35363a846a312941c3bb6280d03a3fa816a0c
BLAKE2b-256 checksum
How to use checksums
259ea9808ef5343787fa059cd4f0b62f8278909babf2e66a177c2d7580c0f5c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

Security for deepgram-sdk 0.2.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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page