@@ -8,7 +8,7 @@ Official Python SDK for [Deepgram](https://www.deepgram.com/). Power your apps w
8
8
- [ Documentation] ( #documentation )
9
9
- [ Migrating from earlier versions] ( #migrating-from-earlier-versions )
10
10
- [ V2 to V3] ( #v2-to-v3 )
11
- - [ V3.* \ to V4] ( #v3-to-v4 )
11
+ - [ V3.\ * \ to V4] ( #v3-to-v4 )
12
12
- [ Requirements] ( #requirements )
13
13
- [ Installation] ( #installation )
14
14
- [ Initialization] ( #initialization )
@@ -129,8 +129,6 @@ response = deepgram.listen.rest.v("1").transcribe_url(
129
129
130
130
[ See our API reference for more info] ( https://developers.deepgram.com/reference/speech-to-text-api/listen ) .
131
131
132
- [ See the Example for more info] ( ./examples/speech-to-text/rest/sync/url/main.py ) .
133
-
134
132
### Local Files (Synchronous)
135
133
136
134
Transcribe audio from a file.
@@ -146,8 +144,6 @@ response = deepgram.listen.rest.v("1").transcribe_file(
146
144
147
145
[ See our API reference for more info] ( https://developers.deepgram.com/reference/speech-to-text-api/listen ) .
148
146
149
- [ See the Example for more info] ( ./examples/speech-to-text/rest/sync/file/main.py ) .
150
-
151
147
## Pre-Recorded (Asynchronous / Callbacks)
152
148
153
149
### Remote Files (Asynchronous)
@@ -166,8 +162,6 @@ response = deepgram.listen.rest.v("1").transcribe_url_async(
166
162
167
163
[ See our API reference for more info] ( https://developers.deepgram.com/reference/speech-to-text-api/listen ) .
168
164
169
- [ See the Example for more info] ( ./examples/speech-to-text/rest/async/url/main.py ) .
170
-
171
165
### Local Files (Asynchronous)
172
166
173
167
Transcribe audio from a file.
@@ -184,8 +178,6 @@ response = deepgram.listen.rest.v("1").transcribe_file_async(
184
178
185
179
[ See our API reference for more info] ( https://developers.deepgram.com/reference/speech-to-text-api/listen ) .
186
180
187
- [ See the Example for more info] ( ./examples/speech-to-text/rest/async/file/main.py ) .
188
-
189
181
## Streaming Audio
190
182
191
183
Transcribe streaming audio.
@@ -213,8 +205,6 @@ connection.finish()
213
205
214
206
[ See our API reference for more info] ( https://developers.deepgram.com/reference/streaming-api ) .
215
207
216
- [ See the Examples for more info] ( ./examples/speech-to-text/websocket/ ) .
217
-
218
208
## Transcribing to Captions
219
209
220
210
Transcribe audio to captions.
@@ -287,8 +277,6 @@ For a complete implementation, you would need to:
287
277
288
278
[ See our API reference for more info] ( https://developers.deepgram.com/reference/voice-agent-api/agent ) .
289
279
290
- [ See the Examples for more info] ( ./examples/agent/ ) .
291
-
292
280
## Text to Speech REST
293
281
294
282
Convert text into speech using the REST API.
@@ -309,8 +297,6 @@ response = deepgram.speak.rest.v("1").save(
309
297
310
298
[ See our API reference for more info] ( https://developers.deepgram.com/reference/text-to-speech-api/speak ) .
311
299
312
- [ See the Example for more info] ( ./examples/text-to-speech/rest/ ) .
313
-
314
300
## Text to Speech Streaming
315
301
316
302
Convert streaming text into speech using a Websocket.
@@ -346,8 +332,6 @@ connection.finish()
346
332
347
333
[ See our API reference for more info] ( https://developers.deepgram.com/reference/text-to-speech-api/speak ) .
348
334
349
- [ See the Examples for more info] ( ./examples/text-to-speech/websocket/ ) .
350
-
351
335
## Text Intelligence
352
336
353
337
Analyze text.
@@ -372,28 +356,126 @@ response = deepgram.read.rest.v("1").process(
372
356
373
357
## Authentication
374
358
375
- ### Get Token Details
359
+ The Deepgram Python SDK supports multiple authentication methods to provide flexibility and enhanced security for your applications.
360
+
361
+ ### Authentication Methods
376
362
377
- Retrieves the details of the current authentication token.
363
+ #### API Key Authentication (Traditional)
364
+
365
+ The traditional method using your Deepgram API key:
378
366
379
367
``` python
380
- response = deepgram.manage.rest.v(" 1" ).get_token_details()
368
+ from deepgram import DeepgramClient
369
+
370
+ # Direct API key
371
+ client = DeepgramClient(api_key = " YOUR_API_KEY" )
372
+
373
+ # Or using environment variable DEEPGRAM_API_KEY
374
+ client = DeepgramClient() # Auto-detects from environment
375
+ ```
376
+
377
+ #### Bearer Token Authentication (OAuth 2.0)
378
+
379
+ Use short-lived access tokens for enhanced security:
380
+
381
+ ``` python
382
+ from deepgram import DeepgramClient
383
+
384
+ # Direct access token
385
+ client = DeepgramClient(access_token = " YOUR_ACCESS_TOKEN" )
386
+
387
+ # Or using environment variable DEEPGRAM_ACCESS_TOKEN
388
+ client = DeepgramClient() # Auto-detects from environment
381
389
```
382
390
383
- [ See our API reference for more info] ( https://developers.deepgram.com/reference/authentication ) .
391
+ ### Authentication Priority
392
+
393
+ When multiple credentials are provided, the SDK follows this priority order:
394
+
395
+ 1 . ** Explicit ` access_token ` parameter** (highest priority)
396
+ 2 . ** Explicit ` api_key ` parameter**
397
+ 3 . ** ` DEEPGRAM_ACCESS_TOKEN ` environment variable**
398
+ 4 . ** ` DEEPGRAM_API_KEY ` environment variable** (lowest priority)
399
+
400
+ ### Environment Variables
401
+
402
+ Set your credentials using environment variables:
403
+
404
+ ``` bash
405
+ # For API key authentication
406
+ export DEEPGRAM_API_KEY=" your-deepgram-api-key"
407
+
408
+ # For bearer token authentication
409
+ export DEEPGRAM_ACCESS_TOKEN=" your-access-token"
410
+ ```
384
411
385
- ### Grant Token
412
+ ### Dynamic Authentication Switching
386
413
387
- Creates a temporary token with a 30-second TTL.
414
+ Switch between authentication methods at runtime:
388
415
389
416
``` python
390
- response = deepgram.auth.v(" 1" ).grant_token()
417
+ from deepgram import DeepgramClient, DeepgramClientOptions
418
+
419
+ # Start with API key
420
+ config = DeepgramClientOptions(api_key = " your-api-key" )
421
+ client = DeepgramClient(config = config)
391
422
423
+ # Switch to access token
424
+ client._config.set_access_token(" your-access-token" )
425
+
426
+ # Switch back to API key
427
+ client._config.set_apikey(" your-api-key" )
392
428
```
393
429
394
- [ See our API reference for more info] ( https://developers.deepgram.com/reference/token-based-auth-api/grant-token ) .
430
+ ### Complete Bearer Token Workflow
431
+
432
+ Here's a practical example of using API keys to obtain access tokens:
433
+
434
+ ``` python
435
+ from deepgram import DeepgramClient
436
+
437
+ # Step 1: Create client with API key
438
+ api_client = DeepgramClient(api_key = " your-api-key" )
439
+
440
+ # Step 2: Get a short-lived access token (30-second TTL)
441
+ response = api_client.auth.v(" 1" ).grant_token()
442
+ access_token = response.access_token
443
+
444
+ # Step 3: Create new client with Bearer token
445
+ bearer_client = DeepgramClient(access_token = access_token)
446
+
447
+ # Step 4: Use the Bearer client for API calls
448
+ transcription = bearer_client.listen.rest.v(" 1" ).transcribe_url(
449
+ {" url" : " https://dpgr.am/spacewalk.wav" }
450
+ )
451
+ ```
452
+
453
+ ### Benefits of Bearer Token Authentication
454
+
455
+ - ** Enhanced Security** : Short-lived tokens (30-second expiration) minimize risk
456
+ - ** OAuth 2.0 Compliance** : Standard bearer token format
457
+ - ** Scope Limitation** : Tokens can be scoped to specific permissions
458
+ - ** Audit Trail** : Better tracking of token usage vs API keys
459
+
460
+ ### Authentication Management
461
+
462
+ #### Get Token Details
463
+
464
+ Retrieves the details of the current authentication token:
465
+
466
+ ``` python
467
+ response = deepgram.manage.rest.v(" 1" ).get_token_details()
468
+ ```
469
+
470
+ #### Grant Token
395
471
396
- [ See The Examples for more info] ( ./examples/auth/ )
472
+ Creates a temporary token with a 30-second TTL:
473
+
474
+ ``` python
475
+ response = deepgram.auth.v(" 1" ).grant_token()
476
+ ```
477
+
478
+ [ See our API reference for more info] ( https://developers.deepgram.com/reference/token-based-auth-api/grant-token ) .
397
479
398
480
## Projects
399
481
@@ -407,8 +489,6 @@ response = deepgram.manage.v("1").get_projects()
407
489
408
490
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/projects/list ) .
409
491
410
- [ See The Example for more info] ( ./examples/manage/projects/main.py ) .
411
-
412
492
### Get Project
413
493
414
494
Retrieves a specific project based on the provided project_id.
@@ -419,8 +499,6 @@ response = deepgram.manage.v("1").get_project(myProjectId)
419
499
420
500
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/projects/get ) .
421
501
422
- [ See The Example for more info] ( ./examples/manage/projects/main.py ) .
423
-
424
502
### Update Project
425
503
426
504
Update a project.
@@ -431,8 +509,6 @@ response = deepgram.manage.v("1").update_project(myProjectId, options)
431
509
432
510
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/projects/update ) .
433
511
434
- [ See The Example for more info] ( ./examples/manage/projects/main.py ) .
435
-
436
512
### Delete Project
437
513
438
514
Delete a project.
@@ -443,8 +519,6 @@ response = deepgram.manage.v("1").delete_project(myProjectId)
443
519
444
520
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/projects/delete ) .
445
521
446
- [ See The Example for more info] ( ./examples/manage/projects/main.py ) .
447
-
448
522
## Keys
449
523
450
524
### List Keys
@@ -457,8 +531,6 @@ response = deepgram.manage.v("1").get_keys(myProjectId)
457
531
458
532
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/keys/list )
459
533
460
- [ See The Example for more info] ( ./examples/manage/keys/main.py ) .
461
-
462
534
### Get Key
463
535
464
536
Retrieves a specific key associated with the provided project_id.
@@ -469,8 +541,6 @@ response = deepgram.manage.v("1").get_key(myProjectId, myKeyId)
469
541
470
542
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/keys/get )
471
543
472
- [ See The Example for more info] ( ./examples/manage/keys/main.py ) .
473
-
474
544
### Create Key
475
545
476
546
Creates an API key with the provided scopes.
@@ -481,8 +551,6 @@ Creates an API key with the provided scopes.
481
551
482
552
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/keys/create )
483
553
484
- [ See The Example for more info] ( ./examples/manage/keys/main.py ) .
485
-
486
554
### Delete Key
487
555
488
556
Deletes a specific key associated with the provided project_id.
@@ -493,8 +561,6 @@ response = deepgram.manage.v("1").delete_key(myProjectId, myKeyId)
493
561
494
562
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/keys/delete )
495
563
496
- [ See The Example for more info] ( ./examples/manage/keys/main.py ) .
497
-
498
564
## Members
499
565
500
566
### Get Members
@@ -507,8 +573,6 @@ response = deepgram.manage.v("1").get_members(myProjectId)
507
573
508
574
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/members/list ) .
509
575
510
- [ See The Example for more info] ( ./examples/manage/members/main.py ) .
511
-
512
576
### Remove Member
513
577
514
578
Removes member account for specified member_id.
@@ -519,8 +583,6 @@ response = deepgram.manage.v("1").remove_member(myProjectId, MemberId)
519
583
520
584
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/members/delete ) .
521
585
522
- [ See The Example for more info] ( ./examples/manage/members/main.py ) .
523
-
524
586
## Scopes
525
587
526
588
### Get Member Scopes
@@ -533,8 +595,6 @@ response = deepgram.manage.v("1").get_member_scopes(myProjectId, memberId)
533
595
534
596
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/scopes/list ) .
535
597
536
- [ See The Example for more info] ( ./examples/manage/scopes/main.py ) .
537
-
538
598
### Update Scope
539
599
540
600
Updates the scope for the specified member in the specified project.
@@ -545,8 +605,6 @@ response = deepgram.manage.v("1").update_member_scope(myProjectId, memberId, opt
545
605
546
606
[ See our API reference for more info] ( https://developers.deepgram.com/reference/management-api/scopes/update ) .
547
607
548
- [ See The Example for more info] ( ./examples/manage/scopes/main.py ) .
549
-
550
608
## Invitations
551
609
552
610
### List Invites
0 commit comments