Skip to content

Commit 65dd67f

Browse files
Merge pull request #15 from Labelbox/ac/python-api-ref
Edit docstrings
2 parents fcd71b4 + a207542 commit 65dd67f

File tree

6 files changed

+65
-44
lines changed

6 files changed

+65
-44
lines changed

labelbox/client.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Client:
3232

3333
def __init__(self, api_key=None,
3434
endpoint='https://api.labelbox.com/graphql'):
35-
""" Create and initialize a Labelbox Client.
35+
""" Creates and initializes a Labelbox Client.
3636
3737
Args:
3838
api_key (str): API key. If None, the key is obtained from
@@ -63,19 +63,20 @@ def execute(self, query, params=None, timeout=10.0):
6363
in appropriate labelbox.exceptions.LabelboxError subtypes.
6464
6565
Args:
66-
query (str): the query to execute.
67-
params (dict): query parameters referenced within the query.
66+
query (str): The query to execute.
67+
params (dict): Query parameters referenced within the query.
6868
timeout (float): Max allowed time for query execution,
6969
in seconds.
70-
Return:
70+
Returns:
7171
dict, parsed JSON response.
7272
Raises:
7373
labelbox.exceptions.AuthenticationError: If authentication
7474
failed.
7575
labelbox.exceptions.InvalidQueryError: If `query` is not
7676
syntactically or semantically valid (checked server-side).
7777
labelbox.exceptions.ApiLimitError: If the server API limit was
78-
exceeded. Check Labelbox documentation to see API limits.
78+
exceeded. See "How to import data" in the online documentation
79+
to see API limits.
7980
labelbox.exceptions.TimeoutError: If response was not received
8081
in `timeout` seconds.
8182
labelbox.exceptions.NetworkError: If an unknown error occurred
@@ -172,12 +173,13 @@ def check_errors(keywords, *path):
172173

173174
def upload_data(self, data):
174175
""" Uploads the given data (bytes) to Labelbox.
176+
175177
Args:
176-
data (bytes): the data to upload.
177-
Return:
178+
data (bytes): The data to upload.
179+
Returns:
178180
str, the URL of uploaded data.
179181
Raises:
180-
labelbox.exceptions.LabelboxError: if upload failes.
182+
labelbox.exceptions.LabelboxError: If upload failed.
181183
"""
182184
request_data = {
183185
"operations": json.dumps({
@@ -213,7 +215,7 @@ def _get_single(self, db_object_type, uid):
213215
Args:
214216
db_object_type (type): DbObject subclass.
215217
uid (str): Unique ID of the row.
216-
Return:
218+
Returns:
217219
Object of `db_object_type`.
218220
Raises:
219221
labelbox.exceptions.ResourceNotFoundError: If there is no object
@@ -230,9 +232,10 @@ def _get_single(self, db_object_type, uid):
230232

231233
def get_project(self, project_id):
232234
""" Gets a single Project with the given ID.
235+
233236
Args:
234237
project_id (str): Unique ID of the Project.
235-
Return:
238+
Returns:
236239
The sought Project.
237240
Raises:
238241
labelbox.exceptions.ResourceNotFoundError: If there is no
@@ -242,9 +245,10 @@ def get_project(self, project_id):
242245

243246
def get_dataset(self, dataset_id):
244247
""" Gets a single Dataset with the given ID.
248+
245249
Args:
246250
dataset_id (str): Unique ID of the Dataset.
247-
Return:
251+
Returns:
248252
The sought Dataset.
249253
Raises:
250254
labelbox.exceptions.ResourceNotFoundError: If there is no
@@ -267,7 +271,7 @@ def _get_all(self, db_object_type, where):
267271
db_object_type (type): DbObject subclass.
268272
where (Comparison, LogicalOperation or None): The `where` clause
269273
for filtering.
270-
Return:
274+
Returns:
271275
An iterable of `db_object_type` instances.
272276
"""
273277
not_deleted = db_object_type.deleted == False
@@ -284,7 +288,7 @@ def get_projects(self, where=None):
284288
Args:
285289
where (Comparison, LogicalOperation or None): The `where` clause
286290
for filtering.
287-
Return:
291+
Returns:
288292
An iterable of Projects (typically a PaginatedCollection).
289293
"""
290294
return self._get_all(Project, where)
@@ -295,7 +299,7 @@ def get_datasets(self, where=None):
295299
Args:
296300
where (Comparison, LogicalOperation or None): The `where` clause
297301
for filtering.
298-
Return:
302+
Returns:
299303
An iterable of Datasets (typically a PaginatedCollection).
300304
"""
301305
return self._get_all(Dataset, where)
@@ -306,23 +310,23 @@ def get_labeling_frontends(self, where=None):
306310
Args:
307311
where (Comparison, LogicalOperation or None): The `where` clause
308312
for filtering.
309-
Return:
313+
Returns:
310314
An iterable of LabelingFrontends (typically a PaginatedCollection).
311315
"""
312316
return self._get_all(LabelingFrontend, where)
313317

314318
def _create(self, db_object_type, data):
315-
""" Creates a object on the server. Attribute values are
319+
""" Creates an object on the server. Attribute values are
316320
passed as keyword arguments:
317321
318322
Args:
319323
db_object_type (type): A DbObjectType subtype.
320324
data (dict): Keys are attributes or their names (in Python,
321325
snake-case convention) and values are desired attribute values.
322-
Return:
323-
a new object of the given DB object type.
326+
Returns:
327+
A new object of the given DB object type.
324328
Raises:
325-
InvalidAttributeError: in case the DB object type does not contain
329+
InvalidAttributeError: If the DB object type does not contain
326330
any of the attribute names given in `data`.
327331
"""
328332
# Convert string attribute names to Field or Relationship objects.
@@ -347,10 +351,10 @@ def create_dataset(self, **kwargs):
347351
Keyword arguments with new Dataset attribute values.
348352
Keys are attribute names (in Python, snake-case convention) and
349353
values are desired attribute values.
350-
Return:
351-
a new Dataset object.
354+
Returns:
355+
A new Dataset object.
352356
Raises:
353-
InvalidAttributeError: in case the Dataset type does not contain
357+
InvalidAttributeError: If the Dataset type does not contain
354358
any of the attribute names given in kwargs.
355359
"""
356360
return self._create(Dataset, kwargs)
@@ -364,10 +368,10 @@ def create_project(self, **kwargs):
364368
Keyword arguments with new Project attribute values.
365369
Keys are attribute names (in Python, snake-case convention) and
366370
values are desired attribute values.
367-
Return:
368-
a new Project object.
371+
Returns:
372+
A new Project object.
369373
Raises:
370-
InvalidAttributeError: in case the Project type does not contain
374+
InvalidAttributeError: If the Project type does not contain
371375
any of the attribute names given in kwargs.
372376
"""
373377
return self._create(Project, kwargs)

labelbox/schema/data_row.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class DataRow(DbObject, Updateable, BulkDeletable):
2323
@staticmethod
2424
def bulk_delete(data_rows):
2525
""" Deletes all the given DataRows.
26+
2627
Args:
2728
data_rows (list of DataRow): The DataRows to delete.
2829
"""
@@ -35,11 +36,12 @@ def __init__(self, *args, **kwargs):
3536

3637
def create_metadata(self, meta_type, meta_value):
3738
""" Creates an asset metadata for this DataRow.
39+
3840
Args:
3941
meta_type (str): Asset metadata type, must be one of:
4042
VIDEO, IMAGE, TEXT.
4143
meta_value (str): Asset metadata value.
42-
Return:
44+
Returns:
4345
AssetMetadata DB object.
4446
"""
4547
meta_type_param = "metaType"

labelbox/schema/dataset.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Dataset(DbObject, Updateable, Deletable):
2424

2525
def create_data_row(self, **kwargs):
2626
""" Creates a single DataRow belonging to this dataset.
27+
2728
Kwargs:
2829
Key-value arguments containing new `DataRow` data.
2930
At a minimum they must contain `row_data`. The value for
@@ -64,17 +65,17 @@ def create_data_rows(self, items):
6465
Args:
6566
items (iterable of (dict or str)): See above for details.
6667
67-
Return:
68+
Returns:
6869
Task representing the data import on the server side. The Task
6970
can be used for inspecting task progress and waiting until it's done.
7071
71-
Raise:
72-
InvalidQueryError: if the `items` parameter does not conform to
72+
Raises:
73+
InvalidQueryError: If the `items` parameter does not conform to
7374
the specification above or if the server did not accept the
7475
DataRow creation request (unknown reason).
75-
ResourceNotFoundError: if unable to retrieve the Task for the
76+
ResourceNotFoundError: If unable to retrieve the Task for the
7677
import process. This could imply that the import failed.
77-
InvalidAttributeError: if there are fields in `items` not valid for
78+
InvalidAttributeError: If there are fields in `items` not valid for
7879
a DataRow.
7980
"""
8081
file_upload_thread_count = 20
@@ -154,7 +155,7 @@ def data_row_for_external_id(self, external_id):
154155
A single `DataRow` with the given ID.
155156
156157
Raises:
157-
labelbox.exceptions.ResourceNotFoundError: if there is no `DataRow`
158+
labelbox.exceptions.ResourceNotFoundError: If there is no `DataRow`
158159
in this `DataSet` with the given external ID, or if there are
159160
multiple `DataRows` for it.
160161
"""

labelbox/schema/label.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ def __init__(self, *args, **kwargs):
2828
@staticmethod
2929
def bulk_delete(labels):
3030
""" Deletes all the given Labels.
31+
3132
Args:
3233
labels (list of Label): The Labels to delete.
3334
"""
3435
BulkDeletable._bulk_delete(labels, False)
3536

3637
def create_review(self, **kwargs):
3738
""" Creates a Review for this label.
39+
3840
Kwargs:
3941
Review attributes. At a minimum a `Review.score` field
4042
value must be provided.
@@ -45,7 +47,8 @@ def create_review(self, **kwargs):
4547

4648
def create_benchmark(self):
4749
""" Creates a Benchmark for this Label.
48-
Return:
50+
51+
Returns:
4952
The newly created Benchmark.
5053
"""
5154
label_id_param = "labelId"

labelbox/schema/project.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Project(DbObject, Updateable, Deletable):
4343

4444
def create_label(self, **kwargs):
4545
""" Creates a label on this Project.
46+
4647
Kwargs:
4748
Label attributes. At the minimum the label `DataRow`.
4849
"""
@@ -107,9 +108,10 @@ def labels(self, datasets=None, order_by=None):
107108
def export_labels(self, timeout_seconds=60):
108109
""" Calls the server-side Label exporting that generates a JSON
109110
payload, and returns the URL to that payload.
111+
110112
Args:
111113
timeout_seconds (float): Max waiting time, in seconds.
112-
Return:
114+
Returns:
113115
URL of the data file with this Project's labels. If the server
114116
didn't generate during the `timeout_seconds` period, None
115117
is returned.
@@ -136,6 +138,7 @@ def export_labels(self, timeout_seconds=60):
136138

137139
def labeler_performance(self):
138140
""" Returns the labeler performances for this Project.
141+
139142
Returns:
140143
A PaginatedCollection of LabelerPerformance objects.
141144
"""
@@ -161,9 +164,10 @@ def create_labeler_performance(client, result):
161164

162165
def review_metrics(self, net_score):
163166
""" Returns this Project's review metrics.
167+
164168
Args:
165169
net_score (None or Review.NetScore): Indicates desired metric.
166-
Return:
170+
Returns:
167171
int, aggregation count of reviews for given net_score.
168172
"""
169173
if net_score not in (None,) + tuple(Entity.Review.NetScore):
@@ -180,8 +184,10 @@ def review_metrics(self, net_score):
180184

181185
def setup(self, labeling_frontend, labeling_frontend_options):
182186
""" Finalizes the Project setup.
187+
183188
Args:
184-
labeling_frontend (LabelingFrontend): The labeling frontend to use.
189+
labeling_frontend (LabelingFrontend): Which UI to use to label the
190+
data.
185191
labeling_frontend_options (dict or str): Labeling frontend options,
186192
a.k.a. project ontology. If given a `dict` it will be converted
187193
to `str` using `json.dumps`.
@@ -210,8 +216,8 @@ def set_labeling_parameter_overrides(self, data):
210216
Args:
211217
data (iterable): An iterable of tuples. Each tuple must contain
212218
(DataRow, priority, numberOfLabels) for the new override.
213-
Return:
214-
bool indicating if the operation was a success.
219+
Returns:
220+
bool, indicates if the operation was a success.
215221
"""
216222
data_str = ",\n".join(
217223
"{dataRow: {id: \"%s\"}, priority: %d, numLabels: %d }" % (
@@ -226,10 +232,11 @@ def set_labeling_parameter_overrides(self, data):
226232

227233
def unset_labeling_parameter_overrides(self, data_rows):
228234
""" Removes labeling parameter overrides to this project.
235+
229236
Args:
230237
data_rows (iterable): An iterable of DataRows.
231-
Return:
232-
bool indicating if the operation was a success.
238+
Returns:
239+
bool, indicates if the operation was a success.
233240
"""
234241
id_param = "projectId"
235242
query_str = """mutation UnsetLabelingParameterOverridesPyApi($%s: ID!){
@@ -241,7 +248,8 @@ def unset_labeling_parameter_overrides(self, data_rows):
241248
return res["project"]["unsetLabelingParameterOverrides"]["success"]
242249

243250
def upsert_review_queue(self, quota_factor):
244-
""" Reinitiate the review queue for this project.
251+
""" Reinitiates the review queue for this project.
252+
245253
Args:
246254
quota_factor (float): Which part (percentage) of the queue
247255
to reinitiate. Between 0 and 1.
@@ -257,11 +265,12 @@ def upsert_review_queue(self, quota_factor):
257265

258266

259267
def extend_reservations(self, queue_type):
260-
""" Extend all the current reservations for the current user on the given
268+
""" Extends all the current reservations for the current user on the given
261269
queue type.
270+
262271
Args:
263272
queue_type (str): Either "LabelingQueue" or "ReviewQueue"
264-
Return:
273+
Returns:
265274
int, the number of reservations that were extended.
266275
"""
267276
if queue_type not in ("LabelingQueue", "ReviewQueue"):

labelbox/schema/webhook.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Webhook(DbObject, Updateable):
2828
@staticmethod
2929
def create(client, topics, url, secret, project):
3030
""" Creates a Webhook.
31+
3132
Args:
3233
client (Client): The Labelbox client used to connect
3334
to the server.
@@ -39,7 +40,7 @@ def create(client, topics, url, secret, project):
3940
project (Project or None): The project for which notifications
4041
should be sent. If None notifications are sent for all
4142
events in your organization.
42-
Return:
43+
Returns:
4344
A newly created Webhook.
4445
"""
4546
project_str = "" if project is None \
@@ -58,6 +59,7 @@ def create(client, topics, url, secret, project):
5859

5960
def update(self, topics=None, url=None, status=None):
6061
""" Updates this Webhook.
62+
6163
Args:
6264
topics (list of str): The new topics value, optional.
6365
url (str): The new URL value, optional.

0 commit comments

Comments
 (0)