generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathmain.py
110 lines (94 loc) · 3.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT
import os
import sys
import logging
from deepgram.utils import verboselogs
from dotenv import load_dotenv
from deepgram import DeepgramClient, DeepgramClientOptions, KeyOptions
load_dotenv()
def main():
try:
# example of setting up a client config. logging values: WARNING, VERBOSE, DEBUG, SPAM
config = DeepgramClientOptions(
verbose=verboselogs.SPAM,
)
deepgram: DeepgramClient = DeepgramClient("", config)
# otherwise, use default config
# deepgram: DeepgramClient = DeepgramClient()
# get projects
projectResp = deepgram.manage.v("1").get_projects()
if projectResp is None:
print(f"ListProjects failed.")
sys.exit(1)
myId = None
myName = None
for project in projectResp.projects:
myId = project.project_id
myName = project.name
print(f"ListProjects() - ID: {myId}, Name: {myName}")
break
# list keys
listResp = deepgram.manage.v("1").get_keys(myId)
if listResp is None:
print("No keys found")
else:
for key in listResp.api_keys:
print(
f"GetKeys() - ID: {key.api_key.api_key_id}, Member: {key.member.email}, Comment: {key.api_key.comment}, Scope: {key.api_key.scopes}"
)
# create key
options: KeyOptions = KeyOptions(
comment="MyTestKey",
scopes=["member:write", "project:read"],
time_to_live_in_seconds=3600,
)
myKeyId = None
createResp = deepgram.manage.v("1").create_key(myId, options)
if createResp is None:
print(f"CreateKey failed.")
sys.exit(1)
else:
myKeyId = createResp.api_key_id
print(
f"CreateKey() - ID: {myKeyId}, Comment: {createResp.comment} Scope: {createResp.scopes}"
)
# list keys
listResp = deepgram.manage.v("1").get_keys(myId)
if listResp is None:
print("No keys found")
else:
for key in listResp.api_keys:
print(
f"GetKeys() - ID: {key.api_key.api_key_id}, Member: {key.member.email}, Comment: {key.api_key.comment}, Scope: {key.api_key.scopes}"
)
# get key
getResp = deepgram.manage.v("1").get_key(myId, myKeyId)
if getResp is None:
print(f"GetKey failed.")
sys.exit(1)
else:
print(
f"GetKey() - ID: {key.api_key.api_key_id}, Member: {key.member.email}, Comment: {key.api_key.comment}, Scope: {key.api_key.scopes}"
)
# delete key
deleteResp = deepgram.manage.v("1").delete_key(myId, myKeyId)
if deleteResp is None:
print(f"DeleteKey failed.")
sys.exit(1)
else:
print(f"DeleteKey() - Msg: {deleteResp.message}")
# list keys
listResp = deepgram.manage.v("1").get_keys(myId)
if listResp is None:
print("No keys found")
else:
for key in listResp.api_keys:
print(
f"GetKeys() - ID: {key.api_key.api_key_id}, Member: {key.member.email}, Comment: {key.api_key.comment}, Scope: {key.api_key.scopes}"
)
except Exception as e:
print(f"Exception: {e}")
if __name__ == "__main__":
main()