1
1
# Dolby.io REST APIs Client for Python
2
2
3
- Python wrapper for the dolby.io REST [ Communications ] ( https://docs.dolby.io/communications-apis/reference/authentication-api ) , [ Streaming ] ( https://docs.dolby.io/streaming-apis/reference ) and [ Media] ( https://docs.dolby.io/media-processing/reference/media-enhance-overview ) APIs.
3
+ Python wrapper for the [ Dolby Millicast ] ( https://docs.dolby.io/streaming-apis/reference ) and [ Media] ( https://docs.dolby.io/media-processing/reference/media-enhance-overview ) APIs.
4
4
5
5
## Install this project
6
6
@@ -16,148 +16,19 @@ Upgrade your package to the latest version:
16
16
python3 -m pip install --upgrade dolbyio-rest-apis
17
17
```
18
18
19
- ## Logging
20
-
21
- You can change the log level by using the Python [ logging] ( https://docs.python.org/3/library/logging.html ) library.
22
-
23
- ``` python
24
- import logging
25
-
26
- logging.basicConfig(level = ' DEBUG' )
27
- ```
28
-
29
- ## Authentication
30
-
31
- In order to make API calls for most operations of the ** Communications APIs** and ** Media APIs** , you must get an access token using this API:
32
-
33
- ``` python
34
- import asyncio
35
- from dolbyio_rest_apis import authentication
36
-
37
- APP_KEY = ' YOUR_APP_KEY'
38
- APP_SECRET = ' YOUR_APP_SECRET'
39
-
40
- loop = asyncio.get_event_loop()
41
-
42
- task = authentication.get_api_token(APP_KEY , APP_SECRET )
43
- at = loop.run_until_complete(task)
44
-
45
- print (f ' API Token: { at.access_token} ' )
46
- ```
47
-
48
- To request a particular scope for this access token:
49
-
50
- ``` python
51
- task = authentication.get_api_token(APP_KEY , APP_SECRET , scope = [' comms:*' ])
52
- at = loop.run_until_complete(task)
53
-
54
- print (f ' API Token: { at.access_token} ' )
55
- print (f ' Scope: { at.scope} ' )
56
- ```
57
-
58
- ## Communications Examples
59
-
60
- ### Get a client access token
61
-
62
- To get an access token that will be used by the client SDK for an end user to open a session against dolby.io, use the following code:
63
-
64
- ``` python
65
- import asyncio
66
- from dolbyio_rest_apis import authentication as auth
67
- from dolbyio_rest_apis.communications import authentication
68
-
69
- APP_KEY = ' YOUR_APP_KEY'
70
- APP_SECRET = ' YOUR_APP_SECRET'
71
-
72
- loop = asyncio.get_event_loop()
73
-
74
- # Request an API Token
75
- task = auth.get_api_token(APP_KEY , APP_SECRET , scope = [' comms:client_access_token:create' ])
76
- api_token = loop.run_until_complete(task)
77
-
78
- print (f ' API Token: { api_token.access_token} ' )
79
-
80
- # Request the Client Access Token
81
- task = authentication.get_client_access_token_v2(api_token.access_token, [' *' ])
82
- cat = loop.run_until_complete(task)
83
-
84
- print (f ' Client Access Token: { cat.access_token} ' )
85
- ```
86
-
87
- Because most of the APIs are asynchronous, you can write an async function like that:
88
-
89
- ``` python
90
- from dolbyio_rest_apis import authentication as auth
91
- from dolbyio_rest_apis.communications import authentication
92
-
93
- APP_KEY = ' YOUR_APP_KEY'
94
- APP_SECRET = ' YOUR_APP_SECRET'
95
-
96
- async def get_client_access_token ():
97
- # Request an API Token
98
- api_token = await auth.get_api_token(APP_KEY , APP_SECRET , scope = [' comms:client_access_token:create' ])
99
-
100
- # Request the Client Access Token
101
- cat = await authentication.get_client_access_token_v2(api_token.access_token, [' *' ])
102
- print (f ' Client Access Token: { cat.access_token} ' )
103
-
104
- return cat.access_token
105
-
106
- ```
107
-
108
- ### Create a conference
109
-
110
- To create a Dolby Voice conference, you first must retrieve an API Access Token, then use the following code to create the conference.
111
-
112
- ``` python
113
- import asyncio
114
- from dolbyio_rest_apis import authentication
115
- from dolbyio_rest_apis.communications import conference
116
- from dolbyio_rest_apis.communications.models import Participant, Permission, VideoCodec
117
-
118
- APP_KEY = ' YOUR_APP_KEY'
119
- APP_SECRET = ' YOUR_APP_SECRET'
120
-
121
- owner_id = ' ' # Identifier of the owner of the conference
122
- alias = ' ' # Conference alias
123
-
124
- participants = [
125
- Participant(' hostA' , [Permission.JOIN , Permission.SEND_AUDIO , Permission.SEND_VIDEO ], notify = True ),
126
- Participant(' listener1' , [Permission.JOIN ], notify = False ),
127
- ]
128
-
129
- loop = asyncio.get_event_loop()
130
-
131
- # Request an API token
132
- task = authentication.get_api_token(APP_KEY , APP_SECRET , scope = [' comms:conf:create' ])
133
- at = loop.run_until_complete(task)
134
-
135
- # Create the conference
136
- task = conference.create_conference(
137
- at.access_token,
138
- owner_id,
139
- alias,
140
- video_codec = VideoCodec.VP8 ,
141
- participants = participants
142
- )
143
- conf = loop.run_until_complete(task)
144
-
145
- print (f ' Conference created: { conf.id} ' )
146
- ```
147
-
148
19
## Real-time Streaming Examples
149
20
150
21
### Create a publish token
151
22
152
23
``` python
153
24
import asyncio
154
25
from dolbyio_rest_apis.streaming import publish_token
155
- from dolbyio_rest_apis.streaming.models.publish_token import CreatePublishToken, CreateUpdatePublishTokenStream
26
+ from dolbyio_rest_apis.streaming.models.publish_token import CreatePublishToken, TokenStreamName
156
27
157
28
API_SECRET = ' ' # Retrieve your API Secret from the dashboard
158
29
159
30
create_token = CreatePublishToken(' my_token' )
160
- create_token.streams.append(CreateUpdatePublishTokenStream (' feed1' , False ))
31
+ create_token.streams.append(TokenStreamName (' feed1' , False ))
161
32
162
33
loop = asyncio.get_event_loop()
163
34
@@ -172,12 +43,13 @@ print(token)
172
43
``` python
173
44
import asyncio
174
45
from dolbyio_rest_apis.streaming import subscribe_token
175
- from dolbyio_rest_apis.streaming.models.subscribe_token import CreateSubscribeToken, CreateUpdateSubscribeTokenStream
46
+ from dolbyio_rest_apis.streaming.models.publish_token import TokenStreamName
47
+ from dolbyio_rest_apis.streaming.models.subscribe_token import CreateSubscribeToken
176
48
177
49
API_SECRET = ' ' # Retrieve your API Secret from the dashboard
178
50
179
51
create_token = CreateSubscribeToken(' my_token' )
180
- create_token.streams.append(CreateUpdateSubscribeTokenStream (' feed1' , False ))
52
+ create_token.streams.append(TokenStreamName (' feed1' , False ))
181
53
182
54
loop = asyncio.get_event_loop()
183
55
@@ -197,7 +69,7 @@ Get the App Key and Secret from the Dolby.io dashboard and use the following cod
197
69
198
70
``` python
199
71
import asyncio
200
- from dolbyio_rest_apis import authentication
72
+ from dolbyio_rest_apis.media import authentication
201
73
202
74
APP_KEY = ' YOUR_APP_KEY'
203
75
APP_SECRET = ' YOUR_APP_SECRET'
@@ -320,3 +192,13 @@ task = io.download_file(
320
192
)
321
193
loop.run_until_complete(task)
322
194
```
195
+
196
+ ## Logging
197
+
198
+ You can change the log level by using the Python [ logging] ( https://docs.python.org/3/library/logging.html ) library.
199
+
200
+ ``` python
201
+ import logging
202
+
203
+ logging.basicConfig(level = ' DEBUG' )
204
+ ```
0 commit comments