1111from google .api_core import retry
1212import requests
1313import requests .exceptions
14+ from labelbox .data .annotation_types .feature import FeatureSchema
15+ from labelbox .data .serialization .ndjson .base import DataRow
1416
1517import labelbox .exceptions
1618from labelbox import utils
2022from labelbox .orm .model import Entity
2123from labelbox .pagination import PaginatedCollection
2224from labelbox .schema .data_row_metadata import DataRowMetadataOntology
25+ from labelbox .schema .dataset import Dataset
2326from labelbox .schema .iam_integration import IAMIntegration
2427from 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
2733logger = 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'}
0 commit comments