Skip to content

Commit 5a44e3c

Browse files
committed
update with schema folder
1 parent 85a214e commit 5a44e3c

File tree

13 files changed

+110
-89
lines changed

13 files changed

+110
-89
lines changed

labelbox/client.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from google.api_core import retry
1212
import requests
1313
import requests.exceptions
14+
from labelbox.data.annotation_types.feature import FeatureSchema
15+
from labelbox.data.serialization.ndjson.base import DataRow
1416

1517
import labelbox.exceptions
1618
from labelbox import utils
@@ -20,9 +22,13 @@
2022
from labelbox.orm.model import Entity
2123
from labelbox.pagination import PaginatedCollection
2224
from labelbox.schema.data_row_metadata import DataRowMetadataOntology
25+
from labelbox.schema.dataset import Dataset
2326
from labelbox.schema.iam_integration import IAMIntegration
2427
from labelbox.schema import role
25-
from labelbox.schema.ontology import Tool, Classification
28+
from labelbox.schema.labeling_frontend import LabelingFrontend
29+
from labelbox.schema.model import Model
30+
from labelbox.schema.ontology import Ontology, Tool, Classification
31+
from labelbox.schema.organization import Organization
2632

2733
logger = logging.getLogger(__name__)
2834

@@ -411,7 +417,7 @@ def get_project(self, project_id):
411417
"""
412418
return self._get_single(Entity.Project, project_id)
413419

414-
def get_dataset(self, dataset_id):
420+
def get_dataset(self, dataset_id) -> Dataset:
415421
""" Gets a single Dataset with the given ID.
416422
417423
>>> dataset = client.get_dataset("<dataset_id>")
@@ -426,14 +432,14 @@ def get_dataset(self, dataset_id):
426432
"""
427433
return self._get_single(Entity.Dataset, dataset_id)
428434

429-
def get_user(self):
435+
def get_user(self) -> User:
430436
""" Gets the current User database object.
431437
432438
>>> user = client.get_user()
433439
"""
434440
return self._get_single(Entity.User, None)
435441

436-
def get_organization(self):
442+
def get_organization(self) -> Organization:
437443
""" Gets the Organization DB object of the current user.
438444
439445
>>> organization = client.get_organization()
@@ -461,7 +467,7 @@ def _get_all(self, db_object_type, where, filter_deleted=True):
461467
[utils.camel_case(db_object_type.type_name()) + "s"],
462468
db_object_type)
463469

464-
def get_projects(self, where=None):
470+
def get_projects(self, where=None) -> List[Project]:
465471
""" Fetches all the projects the user has access to.
466472
467473
>>> projects = client.get_projects(where=(Project.name == "<project_name>") & (Project.description == "<project_description>"))
@@ -474,7 +480,7 @@ def get_projects(self, where=None):
474480
"""
475481
return self._get_all(Entity.Project, where)
476482

477-
def get_datasets(self, where=None):
483+
def get_datasets(self, where=None) -> List[Dataset]:
478484
""" Fetches one or more datasets.
479485
480486
>>> datasets = client.get_datasets(where=(Dataset.name == "<dataset_name>") & (Dataset.description == "<dataset_description>"))
@@ -487,7 +493,7 @@ def get_datasets(self, where=None):
487493
"""
488494
return self._get_all(Entity.Dataset, where)
489495

490-
def get_labeling_frontends(self, where=None):
496+
def get_labeling_frontends(self, where=None) -> List[LabelingFrontend]:
491497
""" Fetches all the labeling frontends.
492498
493499
>>> frontend = client.get_labeling_frontends(where=LabelingFrontend.name == "Editor")
@@ -527,7 +533,7 @@ def _create(self, db_object_type, data):
527533
res = res["create%s" % db_object_type.type_name()]
528534
return db_object_type(self, res)
529535

530-
def create_dataset(self, iam_integration=IAMIntegration._DEFAULT, **kwargs):
536+
def create_dataset(self, iam_integration=IAMIntegration._DEFAULT, **kwargs) -> Dataset:
531537
""" Creates a Dataset object on the server.
532538
533539
Attribute values are passed as keyword arguments.
@@ -585,7 +591,7 @@ def create_dataset(self, iam_integration=IAMIntegration._DEFAULT, **kwargs):
585591
raise e
586592
return dataset
587593

588-
def create_project(self, **kwargs):
594+
def create_project(self, **kwargs) -> Project:
589595
""" Creates a Project object on the server.
590596
591597
Attribute values are passed as keyword arguments.
@@ -602,15 +608,15 @@ def create_project(self, **kwargs):
602608
"""
603609
return self._create(Entity.Project, kwargs)
604610

605-
def get_roles(self):
611+
def get_roles(self) -> List[Role]:
606612
"""
607613
Returns:
608614
Roles: Provides information on available roles within an organization.
609615
Roles are used for user management.
610616
"""
611617
return role.get_roles(self)
612618

613-
def get_data_row(self, data_row_id):
619+
def get_data_row(self, data_row_id) -> DataRow:
614620
"""
615621
616622
Returns:
@@ -619,7 +625,7 @@ def get_data_row(self, data_row_id):
619625

620626
return self._get_single(Entity.DataRow, data_row_id)
621627

622-
def get_data_row_metadata_ontology(self):
628+
def get_data_row_metadata_ontology(self) -> DataRowMetadataOntology:
623629
"""
624630
625631
Returns:
@@ -628,7 +634,7 @@ def get_data_row_metadata_ontology(self):
628634
"""
629635
return DataRowMetadataOntology(self)
630636

631-
def get_model(self, model_id):
637+
def get_model(self, model_id) -> Model:
632638
""" Gets a single Model with the given ID.
633639
634640
>>> model = client.get_model("<model_id>")
@@ -643,7 +649,7 @@ def get_model(self, model_id):
643649
"""
644650
return self._get_single(Entity.Model, model_id)
645651

646-
def get_models(self, where=None):
652+
def get_models(self, where=None) -> List[Model]:
647653
""" Fetches all the models the user has access to.
648654
649655
>>> models = client.get_models(where=(Model.name == "<model_name>"))
@@ -656,7 +662,7 @@ def get_models(self, where=None):
656662
"""
657663
return self._get_all(Entity.Model, where, filter_deleted=False)
658664

659-
def create_model(self, name, ontology_id):
665+
def create_model(self, name, ontology_id) -> Model:
660666
""" Creates a Model object on the server.
661667
662668
>>> model = client.create_model(<model_name>, <ontology_id>)
@@ -707,7 +713,7 @@ def get_data_row_ids_for_external_ids(
707713
result[row['externalId']].append(row['dataRowId'])
708714
return result
709715

710-
def get_ontology(self, ontology_id):
716+
def get_ontology(self, ontology_id) -> Ontology:
711717
"""
712718
Fetches an Ontology by id.
713719
@@ -718,7 +724,7 @@ def get_ontology(self, ontology_id):
718724
"""
719725
return self._get_single(Entity.Ontology, ontology_id)
720726

721-
def get_ontologies(self, name_contains):
727+
def get_ontologies(self, name_contains) -> PaginatedCollection]:
722728
"""
723729
Fetches all ontologies with names that match the name_contains string.
724730
@@ -739,7 +745,7 @@ def get_ontologies(self, name_contains):
739745
['ontologies', 'nodes'], Entity.Ontology,
740746
['ontologies', 'nextCursor'])
741747

742-
def get_feature_schema(self, feature_schema_id):
748+
def get_feature_schema(self, feature_schema_id) -> FeatureSchema:
743749
"""
744750
Fetches a feature schema. Only supports top level feature schemas.
745751
@@ -760,7 +766,7 @@ def get_feature_schema(self, feature_schema_id):
760766
res['id'] = res['normalized']['featureSchemaId']
761767
return Entity.FeatureSchema(self, res)
762768

763-
def get_feature_schemas(self, name_contains):
769+
def get_feature_schemas(self, name_contains) -> PaginatedCollection:
764770
"""
765771
Fetches top level feature schemas with names that match the `name_contains` string
766772
@@ -789,7 +795,7 @@ def rootSchemaPayloadToFeatureSchema(client, payload):
789795
rootSchemaPayloadToFeatureSchema,
790796
['rootSchemaNodes', 'nextCursor'])
791797

792-
def create_ontology_from_feature_schemas(self, name, feature_schema_ids):
798+
def create_ontology_from_feature_schemas(self, name, feature_schema_ids) -> Ontology:
793799
"""
794800
Creates an ontology from a list of feature schema ids
795801
@@ -828,7 +834,7 @@ def create_ontology_from_feature_schemas(self, name, feature_schema_ids):
828834
normalized = {'tools': tools, 'classifications': classifications}
829835
return self.create_ontology(name, normalized)
830836

831-
def create_ontology(self, name, normalized):
837+
def create_ontology(self, name, normalized) -> Ontology:
832838
"""
833839
Creates an ontology from normalized data
834840
>>> normalized = {"tools" : [{'tool': 'polygon', 'name': 'cat', 'color': 'black'}], "classifications" : []}
@@ -855,7 +861,7 @@ def create_ontology(self, name, normalized):
855861
res = self.execute(query_str, params)
856862
return Entity.Ontology(self, res['upsertOntology'])
857863

858-
def create_feature_schema(self, normalized):
864+
def create_feature_schema(self, normalized) -> FeatureSchema:
859865
"""
860866
Creates a feature schema from normalized data.
861867
>>> normalized = {'tool': 'polygon', 'name': 'cat', 'color': 'black'}

labelbox/data/serialization/labelbox_v1/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LBV1ObjectBase(LBV1Feature):
2323
classifications: List[Union[LBV1Text, LBV1Radio, LBV1Dropdown,
2424
LBV1Checklist]] = []
2525

26-
def dict(self, *args, **kwargs) -> Dict[str, str]:
26+
def dict(self, *args, **kwargs) -> Dict[str, Any]:
2727
res = super().dict(*args, **kwargs)
2828
# This means these are not video frames ..
2929
if self.instanceURI is None:

labelbox/schema/benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Benchmark(DbObject):
2727

2828
reference_label = Relationship.ToOne("Label", False, "reference_label")
2929

30-
def delete(self):
30+
def delete(self) -> None:
3131
label_param = "labelId"
3232
query_str = """mutation DeleteBenchmarkPyApi($%s: ID!) {
3333
deleteBenchmark(where: {labelId: $%s}) {id}} """ % (label_param,

labelbox/schema/data_row.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ def __init__(self, *args, **kwargs):
4949
self.attachments.supports_sorting = False
5050

5151
@staticmethod
52-
def bulk_delete(data_rows):
52+
def bulk_delete(data_rows) -> None:
5353
""" Deletes all the given DataRows.
5454
5555
Args:
5656
data_rows (list of DataRow): The DataRows to delete.
5757
"""
5858
BulkDeletable._bulk_delete(data_rows, True)
5959

60-
def create_attachment(self, attachment_type, attachment_value):
60+
def create_attachment(self, attachment_type,
61+
attachment_value) -> AssetAttachment:
6162
""" Adds an AssetAttachment to a DataRow.
6263
Labelers can view these attachments while labeling.
6364

labelbox/schema/dataset.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
from labelbox.schema import iam_integration
2-
from labelbox import utils
1+
from typing import Generator, List
32
import os
43
import json
54
import logging
6-
from itertools import islice
7-
from concurrent.futures import ThreadPoolExecutor, as_completed
5+
from collections.abc import Iterable
86
import time
97
import ndjson
8+
from itertools import islice
9+
10+
from labelbox.data.serialization.ndjson.base import DataRow
11+
from labelbox.schema import iam_integration
12+
from labelbox.schema.task import Task
13+
from labelbox import utils
14+
from concurrent.futures import ThreadPoolExecutor, as_completed
1015
from io import StringIO
1116
import requests
12-
from collections.abc import Iterable
1317

1418
from labelbox.exceptions import InvalidQueryError, LabelboxError, ResourceNotFoundError, InvalidAttributeError
1519
from labelbox.orm.db_object import DbObject, Updateable, Deletable
@@ -48,7 +52,7 @@ class Dataset(DbObject, Updateable, Deletable):
4852
iam_integration = Relationship.ToOne("IAMIntegration", False,
4953
"iam_integration", "signer")
5054

51-
def create_data_row(self, **kwargs):
55+
def create_data_row(self, **kwargs) -> DataRow:
5256
""" Creates a single DataRow belonging to this dataset.
5357
5458
>>> dataset.create_data_row(row_data="http://my_site.com/photos/img_01.jpg")
@@ -76,7 +80,7 @@ def create_data_row(self, **kwargs):
7680
kwargs[DataRow.dataset.name] = self
7781
return self.client._create(DataRow, kwargs)
7882

79-
def create_data_rows_sync(self, items):
83+
def create_data_rows_sync(self, items) -> None:
8084
""" Synchronously bulk upload data rows.
8185
8286
Use this instead of `Dataset.create_data_rows` for smaller batches of data rows that need to be uploaded quickly.
@@ -117,7 +121,7 @@ def create_data_rows_sync(self, items):
117121
url_param: descriptor_url
118122
})
119123

120-
def create_data_rows(self, items):
124+
def create_data_rows(self, items) -> Task:
121125
""" Asynchronously bulk upload data rows
122126
123127
Use this instead of `Dataset.create_data_rows_sync` uploads for batches that contain more than 1000 data rows.
@@ -311,16 +315,16 @@ def convert_item(item):
311315
data = json.dumps(items)
312316
return self.client.upload_data(data)
313317

314-
def data_rows_for_external_id(self, external_id, limit=10):
315-
""" Convenience method for getting a single `DataRow` belonging to this
318+
def data_rows_for_external_id(self, external_id, limit=10) -> List[DataRow]:
319+
""" Convenience method for getting a multiple `DataRow` belonging to this
316320
`Dataset` that has the given `external_id`.
317321
318322
Args:
319323
external_id (str): External ID of the sought `DataRow`.
320324
limit (int): The maximum number of data rows to return for the given external_id
321325
322326
Returns:
323-
A single `DataRow` with the given ID.
327+
A list of `DataRow` with the given ID.
324328
325329
Raises:
326330
labelbox.exceptions.ResourceNotFoundError: If there is no `DataRow`
@@ -338,7 +342,7 @@ def data_rows_for_external_id(self, external_id, limit=10):
338342
raise ResourceNotFoundError(DataRow, where)
339343
return data_rows
340344

341-
def data_row_for_external_id(self, external_id):
345+
def data_row_for_external_id(self, external_id) -> DataRow:
342346
""" Convenience method for getting a single `DataRow` belonging to this
343347
`Dataset` that has the given `external_id`.
344348
@@ -361,7 +365,7 @@ def data_row_for_external_id(self, external_id):
361365
external_id)
362366
return data_rows[0]
363367

364-
def export_data_rows(self, timeout_seconds=120):
368+
def export_data_rows(self, timeout_seconds=120) -> Generator:
365369
""" Returns a generator that produces all data rows that are currently
366370
attached to this dataset.
367371

labelbox/schema/label.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from labelbox.data.serialization.labelbox_v1.label import Review
12
from labelbox.orm import query
23
from labelbox.orm.db_object import DbObject, Updateable, BulkDeletable
34
from labelbox.orm.model import Entity, Field, Relationship
5+
from labelbox.schema.benchmark import Benchmark
46
""" Client-side object type definitions. """
57

68

@@ -40,15 +42,15 @@ def __init__(self, *args, **kwargs):
4042
created_by = Relationship.ToOne("User", False, "created_by")
4143

4244
@staticmethod
43-
def bulk_delete(labels):
45+
def bulk_delete(labels) -> None:
4446
""" Deletes all the given Labels.
4547
4648
Args:
4749
labels (list of Label): The Labels to delete.
4850
"""
4951
BulkDeletable._bulk_delete(labels, False)
5052

51-
def create_review(self, **kwargs):
53+
def create_review(self, **kwargs) -> Review:
5254
""" Creates a Review for this label.
5355
5456
Args:
@@ -58,7 +60,7 @@ def create_review(self, **kwargs):
5860
kwargs[Entity.Review.project.name] = self.project()
5961
return self.client._create(Entity.Review, kwargs)
6062

61-
def create_benchmark(self):
63+
def create_benchmark(self) -> Benchmark:
6264
""" Creates a Benchmark for this Label.
6365
6466
Returns:

0 commit comments

Comments
 (0)