Skip to content

Commit c8eccec

Browse files
committed
docs: add docstrings
1 parent c9cfd09 commit c8eccec

File tree

9 files changed

+303
-11
lines changed

9 files changed

+303
-11
lines changed

videodb/audio.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ def __repr__(self) -> str:
2121
)
2222

2323
def delete(self) -> None:
24+
"""Delete the audio.
25+
26+
:raises InvalidRequestError: If the delete fails
27+
:return: None if the delete is successful
28+
:rtype: None
29+
"""
2430
self._connection.delete(f"{ApiPath.audio}/{self.id}")

videodb/client.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,29 @@
2424

2525

2626
class Connection(HttpClient):
27+
"""Connection class to interact with the VideoDB"""
28+
2729
def __init__(self, api_key: str, base_url: str) -> None:
30+
"""Initializes a new instance of the Connection class with specified API credentials.
31+
32+
:param api_key: API key for authentication
33+
:param str base_url: (optional) Base URL of the VideoDB API
34+
:raise ValueError: If the API key is not provided
35+
:return: connection object
36+
:rtype: str
37+
"""
2838
self.api_key = api_key
2939
self.base_url = base_url
3040
self.collection_id = "default"
3141
super().__init__(api_key=api_key, base_url=base_url, version=__version__)
3242

3343
def get_collection(self, collection_id: Optional[str] = "default") -> Collection:
44+
"""Get a collection object by its ID.
45+
46+
:param collection_id: ID of the collection
47+
:return: :class:`Collection <Collection>` object
48+
:rtype: :class:`videodb.collection.Collection`
49+
"""
3450
collection_data = self.get(path=f"{ApiPath.collection}/{collection_id}")
3551
self.collection_id = collection_data.get("id", "default")
3652
return Collection(
@@ -41,6 +57,11 @@ def get_collection(self, collection_id: Optional[str] = "default") -> Collection
4157
)
4258

4359
def get_collections(self) -> List[Collection]:
60+
"""Get a list of all collections.
61+
62+
:return: List of :class:`Collection <Collection>` objects
63+
:rtype: list[:class:`videodb.collection.Collection`]
64+
"""
4465
collections_data = self.get(path=ApiPath.collection)
4566
return [
4667
Collection(
@@ -53,6 +74,13 @@ def get_collections(self) -> List[Collection]:
5374
]
5475

5576
def create_collection(self, name: str, description: str) -> Collection:
77+
"""Create a new collection.
78+
79+
:param name: Name of the collection
80+
:param description: Description of the collection
81+
:return: :class:`Collection <Collection>` object
82+
:rtype: :class:`videodb.collection.Collection`
83+
"""
5684
collection_data = self.post(
5785
path=ApiPath.collection,
5886
data={
@@ -69,6 +97,14 @@ def create_collection(self, name: str, description: str) -> Collection:
6997
)
7098

7199
def update_collection(self, id: str, name: str, description: str) -> Collection:
100+
"""Update an existing collection.
101+
102+
:param str id: ID of the collection
103+
:param name: Name of the collection
104+
:param description: Description of the collection
105+
:return: :class:`Collection <Collection>` object
106+
:rtype: :class:`videodb.collection.Collection`
107+
"""
72108
collection_data = self.patch(
73109
path=f"{ApiPath.collection}/{id}",
74110
data={
@@ -85,9 +121,19 @@ def update_collection(self, id: str, name: str, description: str) -> Collection:
85121
)
86122

87123
def check_usage(self) -> dict:
124+
"""Check the usage.
125+
126+
:return: Usage data
127+
:rtype: dict
128+
"""
88129
return self.get(path=f"{ApiPath.billing}/{ApiPath.usage}")
89130

90131
def get_invoices(self) -> List[dict]:
132+
"""Get a list of all invoices.
133+
134+
:return: List of invoices
135+
:rtype: list of dict
136+
"""
91137
return self.get(path=f"{ApiPath.billing}/{ApiPath.invoices}")
92138

93139
def upload(
@@ -99,6 +145,17 @@ def upload(
99145
description: Optional[str] = None,
100146
callback_url: Optional[str] = None,
101147
) -> Union[Video, Audio, Image, None]:
148+
"""Upload a file.
149+
150+
:param file_path: Path to the file to upload
151+
:param url: URL of the file to upload
152+
:param MediaType media_type:(optional):class:`MediaType <MediaType>` object
153+
:param name:(optional) Name of the file
154+
:param description:(optional) Description of the file
155+
:param callback_url:(optional) URL to receive the callback
156+
:return: :class:`Video <Video>`, or :class:`Audio <Audio>`, or :class:`Image <Image>` object
157+
:rtype: Union[ :class:`videodb.video.Video`, :class:`videodb.audio.Audio`, :class:`videodb.image.Image`]
158+
"""
102159
upload_data = upload(
103160
self,
104161
file_path,

videodb/collection.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323

2424
class Collection:
25+
"""Collection class to interact with the Collection"""
26+
2527
def __init__(self, _connection, id: str, name: str = None, description: str = None):
2628
self._connection = _connection
2729
self.id = id
@@ -37,20 +39,31 @@ def __repr__(self) -> str:
3739
)
3840

3941
def get_videos(self) -> List[Video]:
42+
"""Get all the videos in the collection.
43+
44+
:return: List of :class:`Video <Video>` objects
45+
:rtype: List[:class:`videodb.video.Video`]
46+
"""
4047
videos_data = self._connection.get(
4148
path=f"{ApiPath.video}",
4249
params={"collection_id": self.id},
4350
)
4451
return [Video(self._connection, **video) for video in videos_data.get("videos")]
4552

4653
def get_video(self, video_id: str) -> Video:
54+
"""Get a video by its ID.
55+
56+
:param str video_id: ID of the video
57+
:return: :class:`Video <Video>` object
58+
:rtype: :class:`videodb.video.Video`
59+
"""
4760
video_data = self._connection.get(
4861
path=f"{ApiPath.video}/{video_id}", params={"collection_id": self.id}
4962
)
5063
return Video(self._connection, **video_data)
5164

5265
def delete_video(self, video_id: str) -> None:
53-
"""Delete the video
66+
"""Delete the video.
5467
5568
:param str video_id: The id of the video to be deleted
5669
:raises InvalidRequestError: If the delete fails
@@ -62,37 +75,73 @@ def delete_video(self, video_id: str) -> None:
6275
)
6376

6477
def get_audios(self) -> List[Audio]:
78+
"""Get all the audios in the collection.
79+
80+
:return: List of :class:`Audio <Audio>` objects
81+
:rtype: List[:class:`videodb.audio.Audio`]
82+
"""
6583
audios_data = self._connection.get(
6684
path=f"{ApiPath.audio}",
6785
params={"collection_id": self.id},
6886
)
6987
return [Audio(self._connection, **audio) for audio in audios_data.get("audios")]
7088

7189
def get_audio(self, audio_id: str) -> Audio:
90+
"""Get an audio by its ID.
91+
92+
:param str audio_id: ID of the audio
93+
:return: :class:`Audio <Audio>` object
94+
:rtype: :class:`videodb.audio.Audio`
95+
"""
7296
audio_data = self._connection.get(
7397
path=f"{ApiPath.audio}/{audio_id}", params={"collection_id": self.id}
7498
)
7599
return Audio(self._connection, **audio_data)
76100

77101
def delete_audio(self, audio_id: str) -> None:
102+
"""Delete the audio.
103+
104+
:param str audio_id: The id of the audio to be deleted
105+
:raises InvalidRequestError: If the delete fails
106+
:return: None if the delete is successful
107+
:rtype: None
108+
"""
78109
return self._connection.delete(
79110
path=f"{ApiPath.audio}/{audio_id}", params={"collection_id": self.id}
80111
)
81112

82113
def get_images(self) -> List[Image]:
114+
"""Get all the images in the collection.
115+
116+
:return: List of :class:`Image <Image>` objects
117+
:rtype: List[:class:`videodb.image.Image`]
118+
"""
83119
images_data = self._connection.get(
84120
path=f"{ApiPath.image}",
85121
params={"collection_id": self.id},
86122
)
87123
return [Image(self._connection, **image) for image in images_data.get("images")]
88124

89125
def get_image(self, image_id: str) -> Image:
126+
"""Get an image by its ID.
127+
128+
:param str image_id: ID of the image
129+
:return: :class:`Image <Image>` object
130+
:rtype: :class:`videodb.image.Image`
131+
"""
90132
image_data = self._connection.get(
91133
path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
92134
)
93135
return Image(self._connection, **image_data)
94136

95137
def delete_image(self, image_id: str) -> None:
138+
"""Delete the image.
139+
140+
:param str image_id: The id of the image to be deleted
141+
:raises InvalidRequestError: If the delete fails
142+
:return: None if the delete is successful
143+
:rtype: None
144+
"""
96145
return self._connection.delete(
97146
path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
98147
)
@@ -106,6 +155,18 @@ def search(
106155
score_threshold: Optional[float] = None,
107156
dynamic_score_percentage: Optional[float] = None,
108157
) -> SearchResult:
158+
"""Search for a query in the collection.
159+
160+
:param str query: Query to search for
161+
:param search_type:(optional) Type of search to perform :class:`SearchType <SearchType>` object
162+
:param index_type:(optional) Type of index to search :class:`IndexType <IndexType>` object
163+
:param int result_threshold:(optional) Number of results to return
164+
:param float score_threshold:(optional) Threshold score for the search
165+
:param float dynamic_score_percentage:(optional) Percentage of dynamic score to consider
166+
:raise SearchError: If the search fails
167+
:return: :class:`SearchResult <SearchResult>` object
168+
:rtype: :class:`videodb.search.SearchResult`
169+
"""
109170
search = SearchFactory(self._connection).get_search(search_type)
110171
return search.search_inside_collection(
111172
collection_id=self.id,
@@ -126,6 +187,17 @@ def upload(
126187
description: Optional[str] = None,
127188
callback_url: Optional[str] = None,
128189
) -> Union[Video, Audio, Image, None]:
190+
"""Upload a file to the collection.
191+
192+
:param str file_path: Path to the file to be uploaded
193+
:param str url: URL of the file to be uploaded
194+
:param MediaType media_type:(optional):class:`MediaType <MediaType>` object
195+
:param name:(optional) Name of the file
196+
:param description:(optional) Description of the file
197+
:param callback_url:(optional) URL to receive the callback
198+
:return: :class:`Video <Video>`, or :class:`Audio <Audio>`, or :class:`Image <Image>` object
199+
Union[ :class:`videodb.video.Video`, :class:`videodb.audio.Audio`, :class:`videodb.image.Image`]
200+
"""
129201
upload_data = upload(
130202
self._connection,
131203
file_path,

videodb/image.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def __repr__(self) -> str:
2121
)
2222

2323
def delete(self) -> None:
24+
"""Delete the image.
25+
26+
:raises InvalidRequestError: If the delete fails
27+
:return: None if the delete is successful
28+
:rtype: None
29+
"""
2430
self._connection.delete(f"{ApiPath.image}/{self.id}")
2531

2632

@@ -63,6 +69,13 @@ def to_json(self):
6369
}
6470

6571
def describe(self, prompt: str = None, model_name=None):
72+
"""Describe the frame.
73+
74+
:param str prompt: (optional) The prompt to use for the description
75+
:param str model_name: (optional) The model to use for the description
76+
:return: The description of the frame
77+
:rtype: str
78+
"""
6679
description_data = self._connection.post(
6780
path=f"{ApiPath.video}/{self.video_id}/{ApiPath.frame}/{self.id}/{ApiPath.describe}",
6881
data={"prompt": prompt, "model_name": model_name},

videodb/scene.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ def to_json(self):
4646
}
4747

4848
def describe(self, prompt: str = None, model_name=None) -> None:
49+
"""Describe the scene.
50+
51+
:param str prompt: (optional) The prompt to use for the description
52+
:param str model_name: (optional) The model to use for the description
53+
:return: The description of the scene
54+
:rtype: str
55+
"""
4956
if self._connection is None:
5057
raise ValueError("Connection is required to describe a scene")
5158
description_data = self._connection.post(
@@ -81,6 +88,12 @@ def __repr__(self) -> str:
8188
)
8289

8390
def delete(self) -> None:
91+
"""Delete the scene collection.
92+
93+
:raises InvalidRequestError: If the delete fails
94+
:return: None if the delete is successful
95+
:rtype: None
96+
"""
8497
self._connection.delete(
8598
path=f"{ApiPath.video}/{self.video_id}/{ApiPath.scenes}/{self.id}"
8699
)

videodb/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_shots(self) -> List[Shot]:
5353
return self.shots
5454

5555
def compile(self) -> str:
56-
"""Compile the search result shots into a stream url
56+
"""Compile the search result shots into a stream url.
5757
5858
:raises SearchError: If no shots are found in the search results
5959
:return: The stream url
@@ -81,7 +81,7 @@ def compile(self) -> str:
8181
raise SearchError("No shots found in search results to compile")
8282

8383
def play(self) -> str:
84-
"""Generate a stream url for the shot and open it in the default browser
84+
"""Generate a stream url for the shot and open it in the default browser.
8585
8686
:return: The stream url
8787
:rtype: str

videodb/shot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __getitem__(self, key):
5151
return self.__dict__[key]
5252

5353
def generate_stream(self) -> str:
54-
"""Generate a stream url for the shot
54+
"""Generate a stream url for the shot.
5555
5656
:return: The stream url
5757
:rtype: str
@@ -72,7 +72,7 @@ def generate_stream(self) -> str:
7272
return self.stream_url
7373

7474
def play(self) -> str:
75-
"""Generate a stream url for the shot and open it in the default browser/ notebook
75+
"""Generate a stream url for the shot and open it in the default browser/ notebook.
7676
7777
:return: The stream url
7878
:rtype: str

0 commit comments

Comments
 (0)