Threaded and Async IO Task Support
Threaded and Async IO Task Support
Our Python SDK supports the Threaded and Async IO Task API models, allowing developers to build efficient, non-blocking applications.
Threaded API
The SDK also supports a Threading API via its classes/functions, allowing concurrent task execution. This is particularly useful for CPU and IO-bound operations when performing background operations without blocking the main (or other) thread(s). Utilizing Python’s threading module, you can create and manage multiple threads, ensuring your application remains efficient and responsive.
These Threaded components will work with asynchronous code that utilizes the async/await classes and functions. Even if your code uses Async IO classes/functions, you can still use these Threaded API classes/functions.
The best use cases for using Threaded are:
- Heavily Parallelized Applications, such as backend applications behind an API (ie a REST API service)
- CPU-bound Operations, such as ML applications
- IO-bound Operations, such as ML applications or Backup solutions
Pushing a lot of audio data (ie IO operations) over the internet, like performing live transcription of real-time audio, qualifies for using the Threaded API over Async IO Task. In other words, for the overwhleming majority of cases, you should be using this Threaded API over Async IO Tasks for real-time transcription.
Async IO Task API
Async IO Tasks can handle multiple tasks concurrently, making it ideal for high-level structured network code or when handling multiple I/O-bound tasks simultaneously. This is ideal for web-based applications that interact with a web browser. This functionality leverages Python's asyncio library, enabling you to write asynchronous code using async and await keywords, ensuring smoother and more responsive applications.
The best use cases for using Async IO Tasks are:
- Web-based Browser Applications
- Non-Real-Time based Applications, see the previous item
- Over simplifying this, since an Async IO "Thread" or Task is run exclusively from other threads/tasks (ie other tasks are suspended), operations on other threads no longer are "real-time". Please see asyncio documentation.
- Willing to trade off performance for ease of programming
Accessing the API Types
Threaded API Classes
You can find the Threaded API classes through the convenience dot notation
accessors below or by directly creating the [Client]
contained brackets:
- Real-Time/Live Transcription:
deepgram.listen.websocket.v("1")
orLiveClient
- Text-to-Speech:
deepgram.speak.rest.v("1")
orSpeakClient
- Pre-Recorded Transcription:
deepgram.listen.rest.v("1")
orPreRecordedClient
- Text Intelligence:
deepgram.read.analyze.v("1")
orAnalyzeClient
- Management:
deepgram.manage.v("1")
orManageClient
Async IO Task Classes
You can find the Async IO Task API (async/await) classes through the convenience dot notation
accessors below or by directly creating the [Client]
contained brackets:
- Real-Time/Live Transcription:
deepgram.listen.asyncwebsocket.v("1")
orAsyncLiveClient
- Text-to-Speech:
deepgram.asyncspeak.v("1")
orAsyncSpeakClient
- Pre-Recorded Transcription:
deepgram.listen.asyncrest.v("1")
orAsyncPreRecordedClient
- Text Intelligence:
deepgram.read.asyncanalyze.v("1")
orAsyncAnalyzeClient
- Management:
deepgram.asyncmanage.v("1")
orAsyncManageClient
Examples
The GitHub repo contains examples for the Threaded and Async IO Task APIs for the 5 majority category of APIs:
Updated 5 months ago