Skip to content

Commit 53f9982

Browse files
committed
docs: add docstrings
1 parent 39d63d3 commit 53f9982

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

videodb/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ def get_invoices(self) -> List[dict]:
148148
return self.get(path=f"{ApiPath.billing}/{ApiPath.invoices}")
149149

150150
def create_event(self, event_prompt: str, label: str):
151+
"""Create an rtstream event.
152+
153+
:param str event_prompt: Prompt for the event
154+
:param str label: Label for the event
155+
:return: Event ID
156+
:rtype: str
157+
"""
151158
event_data = self.post(
152159
f"{ApiPath.rtstream}/{ApiPath.event}",
153160
data={"event_prompt": event_prompt, "label": label},
@@ -156,6 +163,11 @@ def create_event(self, event_prompt: str, label: str):
156163
return event_data.get("event_id")
157164

158165
def list_events(self):
166+
"""List all rtstream events.
167+
168+
:return: List of events
169+
:rtype: list[dict]
170+
"""
159171
event_data = self.get(f"{ApiPath.rtstream}/{ApiPath.event}")
160172
return event_data.get("events", [])
161173

videodb/collection.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ def delete_image(self, image_id: str) -> None:
168168
def connect_rtstream(
169169
self, url: str, name: str, sample_rate: int = None
170170
) -> RTStream:
171+
"""Connect to an rtstream.
172+
173+
:param str url: URL of the rtstream
174+
:param str name: Name of the rtstream
175+
:param int sample_rate: Sample rate of the rtstream default is 1fps
176+
:return: :class:`RTStream <RTStream>` object
177+
"""
171178
rtstream_data = self._connection.post(
172179
path=f"{ApiPath.rtstream}",
173180
data={
@@ -180,19 +187,31 @@ def connect_rtstream(
180187
return RTStream(self._connection, **rtstream_data)
181188

182189
def get_rtstream(self, id: str) -> RTStream:
190+
"""Get an rtstream by its ID.
191+
192+
:param str id: ID of the rtstream
193+
:return: :class:`RTStream <RTStream>` object
194+
:rtype: :class:`videodb.rtstream.RTStream`
195+
"""
183196
rtstream_data = self._connection.get(
184197
path=f"{ApiPath.rtstream}/{id}",
185198
)
186199
return RTStream(self._connection, **rtstream_data)
187200

188201
def list_rtstreams(self) -> List[RTStream]:
202+
"""List all rtstreams in the collection.
203+
204+
:return: List of :class:`RTStream <RTStream>` objects
205+
:rtype: List[:class:`videodb.rtstream.RTStream`]
206+
"""
189207
rtstreams_data = self._connection.get(
190208
path=f"{ApiPath.rtstream}",
191209
)
192210
return [
193211
RTStream(self._connection, **rtstream)
194212
for rtstream in rtstreams_data.get("results")
195213
]
214+
196215
def generate_image(
197216
self,
198217
prompt: str,

videodb/rtstream.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66

77
class RTStreamSceneIndex:
8+
"""RTStreamSceneIndex class to interact with the rtstream scene index
9+
10+
:ivar str rtstream_index_id: Unique identifier for the rtstream scene index
11+
:ivar str rtstream_id: ID of the rtstream this scene index belongs to
12+
:ivar str extraction_type: Type of extraction
13+
:ivar dict extraction_config: Configuration for extraction
14+
:ivar str prompt: Prompt for scene extraction
15+
:ivar str name: Name of the scene index
16+
:ivar str status: Status of the scene index
17+
"""
18+
819
def __init__(
920
self, _connection, rtstream_index_id: str, rtstream_id, **kwargs
1021
) -> None:
@@ -21,6 +32,7 @@ def __repr__(self) -> str:
2132
return (
2233
f"RTStreamSceneIndex("
2334
f"rtstream_index_id={self.rtstream_index_id}, "
35+
f"rtstream_id={self.rtstream_id}, "
2436
f"extraction_type={self.extraction_type}, "
2537
f"extraction_config={self.extraction_config}, "
2638
f"prompt={self.prompt}, "
@@ -29,6 +41,15 @@ def __repr__(self) -> str:
2941
)
3042

3143
def get_scenes(self, start: int = None, end: int = None, page=1, page_size=100):
44+
"""Get rtstream scene index scenes.
45+
46+
:param int start: Start time of the scenes
47+
:param int end: End time of the scenes
48+
:param int page: Page number
49+
:param int page_size: Number of scenes per page
50+
:return: List of scenes
51+
:rtype: List[dict]
52+
"""
3253
params = {"page": page, "page_size": page_size}
3354
if start and end:
3455
params["start"] = start
@@ -46,20 +67,37 @@ def get_scenes(self, start: int = None, end: int = None, page=1, page_size=100):
4667
}
4768

4869
def start(self):
70+
"""Start the scene index.
71+
72+
:return: None
73+
:rtype: None
74+
"""
4975
self._connection.patch(
5076
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{ApiPath.scene}/{self.rtstream_index_id}/{ApiPath.status}",
5177
data={"action": "start"},
5278
)
5379
self.status = "connected"
5480

5581
def stop(self):
82+
"""Stop the scene index.
83+
84+
:return: None
85+
:rtype: None
86+
"""
5687
self._connection.patch(
5788
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{ApiPath.scene}/{self.rtstream_index_id}/{ApiPath.status}",
5889
data={"action": "stop"},
5990
)
6091
self.status = "stopped"
6192

6293
def create_alert(self, event_id, callback_url) -> str:
94+
"""Create an event alert.
95+
96+
:param str event_id: ID of the event
97+
:param str callback_url: URL to receive the alert callback
98+
:return: Alert ID
99+
:rtype: str
100+
"""
63101
alert_data = self._connection.post(
64102
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}",
65103
data={
@@ -70,25 +108,52 @@ def create_alert(self, event_id, callback_url) -> str:
70108
return alert_data.get("alert_id", None)
71109

72110
def list_alerts(self):
111+
"""List all alerts for the rtstream scene index.
112+
113+
:return: List of alerts
114+
:rtype: List[dict]
115+
"""
73116
alert_data = self._connection.get(
74117
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}"
75118
)
76119
return alert_data.get("alerts", [])
77120

78121
def enable_alert(self, alert_id):
122+
"""Enable an alert.
123+
124+
:param str alert_id: ID of the alert
125+
:return: None
126+
:rtype: None
127+
"""
79128
self._connection.patch(
80129
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}/{alert_id}/{ApiPath.status}",
81130
data={"action": "enable"},
82131
)
83132

84133
def disable_alert(self, alert_id):
134+
"""Disable an alert.
135+
136+
:param str alert_id: ID of the alert
137+
:return: None
138+
:rtype: None
139+
"""
85140
self._connection.patch(
86141
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}/{alert_id}/{ApiPath.status}",
87142
data={"action": "disable"},
88143
)
89144

90145

91146
class RTStream:
147+
"""RTStream class to interact with the RTStream
148+
149+
:ivar str id: Unique identifier for the rtstream
150+
:ivar str name: Name of the rtstream
151+
:ivar str collection_id: ID of the collection this rtstream belongs to
152+
:ivar str created_at: Timestamp of the rtstream creation
153+
:ivar int sample_rate: Sample rate of the rtstream
154+
:ivar str status: Status of the rtstream
155+
"""
156+
92157
def __init__(self, _connection, id: str, **kwargs) -> None:
93158
self._connection = _connection
94159
self.id = id
@@ -110,20 +175,37 @@ def __repr__(self) -> str:
110175
)
111176

112177
def start(self):
178+
"""Connect to the rtstream.
179+
180+
:return: None
181+
:rtype: None
182+
"""
113183
self._connection.patch(
114184
f"{ApiPath.rtstream}/{self.id}/{ApiPath.status}",
115185
data={"action": "start"},
116186
)
117187
self.status = "connected"
118188

119189
def stop(self):
190+
"""Disconnect from the rtstream.
191+
192+
:return: None
193+
:rtype: None
194+
"""
120195
self._connection.patch(
121196
f"{ApiPath.rtstream}/{self.id}/{ApiPath.status}",
122197
data={"action": "stop"},
123198
)
124199
self.status = "stopped"
125200

126201
def generate_stream(self, start, end):
202+
"""Generate a stream from the rtstream.
203+
204+
:param int start: Start time of the stream
205+
:param int end: End time of the stream
206+
:return: Stream URL
207+
:rtype: str
208+
"""
127209
stream_data = self._connection.get(
128210
f"{ApiPath.rtstream}/{self.id}/{ApiPath.stream}",
129211
params={"start": start, "end": end},
@@ -139,6 +221,17 @@ def index_scenes(
139221
model_config={},
140222
name=None,
141223
):
224+
"""Index scenes from the rtstream.
225+
226+
:param str extraction_type: Type of extraction
227+
:param dict extraction_config: Configuration for extraction
228+
:param str prompt: Prompt for scene extraction
229+
:param str model_name: Name of the model
230+
:param dict model_config: Configuration for the model
231+
:param str name: Name of the scene index
232+
:return: Scene index, :class:`RTStreamSceneIndex <RTStreamSceneIndex>` object
233+
:rtype: :class:`videodb.rtstream.RTStreamSceneIndex`
234+
"""
142235
index_data = self._connection.post(
143236
f"{ApiPath.rtstream}/{self.id}/{ApiPath.index}/{ApiPath.scene}",
144237
data={
@@ -164,6 +257,11 @@ def index_scenes(
164257
)
165258

166259
def list_scene_indexes(self):
260+
"""List all scene indexes for the rtstream.
261+
262+
:return: List of :class:`RTStreamSceneIndex <RTStreamSceneIndex>` objects
263+
:rtype: List[:class:`videodb.rtstream.RTStreamSceneIndex`]
264+
"""
167265
index_data = self._connection.get(
168266
f"{ApiPath.rtstream}/{self.id}/{ApiPath.index}/{ApiPath.scene}"
169267
)
@@ -182,6 +280,12 @@ def list_scene_indexes(self):
182280
]
183281

184282
def get_scene_index(self, index_id: str) -> RTStreamSceneIndex:
283+
"""Get a scene index by its ID.
284+
285+
:param str index_id: ID of the scene index
286+
:return: Scene index, :class:`RTStreamSceneIndex <RTStreamSceneIndex>` object
287+
:rtype: :class:`videodb.rtstream.RTStreamSceneIndex`
288+
"""
185289
index_data = self._connection.get(
186290
f"{ApiPath.rtstream}/{self.id}/{ApiPath.index}/{index_id}"
187291
)

0 commit comments

Comments
 (0)