Skip to content

Commit bc48e91

Browse files
authored
Improve reference docs for Server APIs (#306)
1 parent 2567636 commit bc48e91

File tree

9 files changed

+449
-162
lines changed

9 files changed

+449
-162
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,6 @@ cython_debug/
162162
# vscode project settings
163163
.vscode
164164

165-
.DS_Store
165+
.DS_Store
166+
167+
docs

livekit-api/livekit/api/__init__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""LiveKit API SDK"""
15+
"""LiveKit Server APIs for Python
16+
17+
`pip install livekit-api`
18+
19+
Manage rooms, participants, egress, ingress, SIP, and Agent dispatch.
20+
21+
Primary entry point is `LiveKitAPI`.
22+
23+
See https://docs.livekit.io/reference/server/server-apis for more information.
24+
"""
1625

1726
# flake8: noqa
1827
# re-export packages from protocol
@@ -30,3 +39,17 @@
3039
from .access_token import VideoGrants, SIPGrants, AccessToken, TokenVerifier
3140
from .webhook import WebhookReceiver
3241
from .version import __version__
42+
43+
__all__ = [
44+
"LiveKitAPI",
45+
"room_service",
46+
"egress_service",
47+
"ingress_service",
48+
"sip_service",
49+
"agent_dispatch_service",
50+
"VideoGrants",
51+
"SIPGrants",
52+
"AccessToken",
53+
"TokenVerifier",
54+
"WebhookReceiver",
55+
]

livekit-api/livekit/api/agent_dispatch_service.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
import aiohttp
22
from typing import Optional
3-
from livekit.protocol import agent_dispatch as proto_agent_dispatch
3+
from livekit.protocol.agent_dispatch import (
4+
CreateAgentDispatchRequest,
5+
AgentDispatch,
6+
DeleteAgentDispatchRequest,
7+
ListAgentDispatchRequest,
8+
ListAgentDispatchResponse,
9+
)
410
from ._service import Service
511
from .access_token import VideoGrants
612

713
SVC = "AgentDispatchService"
14+
"""@private"""
815

916

1017
class AgentDispatchService(Service):
1118
"""Manage agent dispatches. Service APIs require roomAdmin permissions.
1219
13-
An easier way to construct this service is via LiveKitAPI.agent_dispatch.
20+
Recommended way to use this service is via `livekit.api.LiveKitAPI`:
21+
22+
```python
23+
from livekit import api
24+
lkapi = api.LiveKitAPI()
25+
agent_dispatch = lkapi.agent_dispatch
26+
```
1427
"""
1528

1629
def __init__(
1730
self, session: aiohttp.ClientSession, url: str, api_key: str, api_secret: str
1831
):
1932
super().__init__(session, url, api_key, api_secret)
2033

21-
async def create_dispatch(
22-
self, req: proto_agent_dispatch.CreateAgentDispatchRequest
23-
) -> proto_agent_dispatch.AgentDispatch:
34+
async def create_dispatch(self, req: CreateAgentDispatchRequest) -> AgentDispatch:
2435
"""Create an explicit dispatch for an agent to join a room.
2536
2637
To use explicit dispatch, your agent must be registered with an `agentName`.
@@ -36,12 +47,10 @@ async def create_dispatch(
3647
"CreateDispatch",
3748
req,
3849
self._auth_header(VideoGrants(room_admin=True, room=req.room)),
39-
proto_agent_dispatch.AgentDispatch,
50+
AgentDispatch,
4051
)
4152

42-
async def delete_dispatch(
43-
self, dispatch_id: str, room_name: str
44-
) -> proto_agent_dispatch.AgentDispatch:
53+
async def delete_dispatch(self, dispatch_id: str, room_name: str) -> AgentDispatch:
4554
"""Delete an explicit dispatch for an agent in a room.
4655
4756
Args:
@@ -54,17 +63,15 @@ async def delete_dispatch(
5463
return await self._client.request(
5564
SVC,
5665
"DeleteDispatch",
57-
proto_agent_dispatch.DeleteAgentDispatchRequest(
66+
DeleteAgentDispatchRequest(
5867
dispatch_id=dispatch_id,
5968
room=room_name,
6069
),
6170
self._auth_header(VideoGrants(room_admin=True, room=room_name)),
62-
proto_agent_dispatch.AgentDispatch,
71+
AgentDispatch,
6372
)
6473

65-
async def list_dispatch(
66-
self, room_name: str
67-
) -> list[proto_agent_dispatch.AgentDispatch]:
74+
async def list_dispatch(self, room_name: str) -> list[AgentDispatch]:
6875
"""List all agent dispatches in a room.
6976
7077
Args:
@@ -76,15 +83,15 @@ async def list_dispatch(
7683
res = await self._client.request(
7784
SVC,
7885
"ListDispatch",
79-
proto_agent_dispatch.ListAgentDispatchRequest(room=room_name),
86+
ListAgentDispatchRequest(room=room_name),
8087
self._auth_header(VideoGrants(room_admin=True, room=room_name)),
81-
proto_agent_dispatch.ListAgentDispatchResponse,
88+
ListAgentDispatchResponse,
8289
)
8390
return list(res.agent_dispatches)
8491

8592
async def get_dispatch(
8693
self, dispatch_id: str, room_name: str
87-
) -> Optional[proto_agent_dispatch.AgentDispatch]:
94+
) -> Optional[AgentDispatch]:
8895
"""Get an Agent dispatch by ID
8996
9097
Args:
@@ -97,11 +104,9 @@ async def get_dispatch(
97104
res = await self._client.request(
98105
SVC,
99106
"ListDispatch",
100-
proto_agent_dispatch.ListAgentDispatchRequest(
101-
dispatch_id=dispatch_id, room=room_name
102-
),
107+
ListAgentDispatchRequest(dispatch_id=dispatch_id, room=room_name),
103108
self._auth_header(VideoGrants(room_admin=True, room=room_name)),
104-
proto_agent_dispatch.ListAgentDispatchResponse,
109+
ListAgentDispatchResponse,
105110
)
106111
if len(res.agent_dispatches) > 0:
107112
return res.agent_dispatches[0]
Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,126 @@
11
import aiohttp
2-
from livekit.protocol import egress as proto_egress
2+
from livekit.protocol.egress import (
3+
RoomCompositeEgressRequest,
4+
WebEgressRequest,
5+
ParticipantEgressRequest,
6+
TrackCompositeEgressRequest,
7+
TrackEgressRequest,
8+
UpdateLayoutRequest,
9+
UpdateStreamRequest,
10+
ListEgressRequest,
11+
StopEgressRequest,
12+
EgressInfo,
13+
ListEgressResponse,
14+
)
315
from ._service import Service
416
from .access_token import VideoGrants
517

618
SVC = "Egress"
19+
"""@private"""
720

821

922
class EgressService(Service):
23+
"""Client for LiveKit Egress Service API
24+
25+
Recommended way to use this service is via `livekit.api.LiveKitAPI`:
26+
27+
```python
28+
from livekit import api
29+
lkapi = api.LiveKitAPI()
30+
egress = lkapi.egress
31+
```
32+
33+
Also see https://docs.livekit.io/home/egress/overview/
34+
"""
35+
1036
def __init__(
1137
self, session: aiohttp.ClientSession, url: str, api_key: str, api_secret: str
1238
):
1339
super().__init__(session, url, api_key, api_secret)
1440

1541
async def start_room_composite_egress(
16-
self, start: proto_egress.RoomCompositeEgressRequest
17-
) -> proto_egress.EgressInfo:
42+
self, start: RoomCompositeEgressRequest
43+
) -> EgressInfo:
1844
return await self._client.request(
1945
SVC,
2046
"StartRoomCompositeEgress",
2147
start,
2248
self._auth_header(VideoGrants(room_record=True)),
23-
proto_egress.EgressInfo,
49+
EgressInfo,
2450
)
2551

26-
async def start_web_egress(
27-
self, start: proto_egress.WebEgressRequest
28-
) -> proto_egress.EgressInfo:
52+
async def start_web_egress(self, start: WebEgressRequest) -> EgressInfo:
2953
return await self._client.request(
3054
SVC,
3155
"StartWebEgress",
3256
start,
3357
self._auth_header(VideoGrants(room_record=True)),
34-
proto_egress.EgressInfo,
58+
EgressInfo,
3559
)
3660

3761
async def start_participant_egress(
38-
self, start: proto_egress.ParticipantEgressRequest
39-
) -> proto_egress.EgressInfo:
62+
self, start: ParticipantEgressRequest
63+
) -> EgressInfo:
4064
return await self._client.request(
4165
SVC,
4266
"StartParticipantEgress",
4367
start,
4468
self._auth_header(VideoGrants(room_record=True)),
45-
proto_egress.EgressInfo,
69+
EgressInfo,
4670
)
4771

4872
async def start_track_composite_egress(
49-
self, start: proto_egress.TrackCompositeEgressRequest
50-
) -> proto_egress.EgressInfo:
73+
self, start: TrackCompositeEgressRequest
74+
) -> EgressInfo:
5175
return await self._client.request(
5276
SVC,
5377
"StartTrackCompositeEgress",
5478
start,
5579
self._auth_header(VideoGrants(room_record=True)),
56-
proto_egress.EgressInfo,
80+
EgressInfo,
5781
)
5882

59-
async def start_track_egress(
60-
self, start: proto_egress.TrackEgressRequest
61-
) -> proto_egress.EgressInfo:
83+
async def start_track_egress(self, start: TrackEgressRequest) -> EgressInfo:
6284
return await self._client.request(
6385
SVC,
6486
"StartTrackEgress",
6587
start,
6688
self._auth_header(VideoGrants(room_record=True)),
67-
proto_egress.EgressInfo,
89+
EgressInfo,
6890
)
6991

70-
async def update_layout(
71-
self, update: proto_egress.UpdateLayoutRequest
72-
) -> proto_egress.EgressInfo:
92+
async def update_layout(self, update: UpdateLayoutRequest) -> EgressInfo:
7393
return await self._client.request(
7494
SVC,
7595
"UpdateLayout",
7696
update,
7797
self._auth_header(VideoGrants(room_record=True)),
78-
proto_egress.EgressInfo,
98+
EgressInfo,
7999
)
80100

81-
async def update_stream(
82-
self, update: proto_egress.UpdateStreamRequest
83-
) -> proto_egress.EgressInfo:
101+
async def update_stream(self, update: UpdateStreamRequest) -> EgressInfo:
84102
return await self._client.request(
85103
SVC,
86104
"UpdateStream",
87105
update,
88106
self._auth_header(VideoGrants(room_record=True)),
89-
proto_egress.EgressInfo,
107+
EgressInfo,
90108
)
91109

92-
async def list_egress(
93-
self, list: proto_egress.ListEgressRequest
94-
) -> proto_egress.ListEgressResponse:
110+
async def list_egress(self, list: ListEgressRequest) -> ListEgressResponse:
95111
return await self._client.request(
96112
SVC,
97113
"ListEgress",
98114
list,
99115
self._auth_header(VideoGrants(room_record=True)),
100-
proto_egress.ListEgressResponse,
116+
ListEgressResponse,
101117
)
102118

103-
async def stop_egress(
104-
self, stop: proto_egress.StopEgressRequest
105-
) -> proto_egress.EgressInfo:
119+
async def stop_egress(self, stop: StopEgressRequest) -> EgressInfo:
106120
return await self._client.request(
107121
SVC,
108122
"StopEgress",
109123
stop,
110124
self._auth_header(VideoGrants(room_record=True)),
111-
proto_egress.EgressInfo,
125+
EgressInfo,
112126
)

0 commit comments

Comments
 (0)