11
11
from google .api_core import retry
12
12
import requests
13
13
import requests .exceptions
14
+ from labelbox .data .annotation_types .feature import FeatureSchema
15
+ from labelbox .data .serialization .ndjson .base import DataRow
14
16
15
17
import labelbox .exceptions
16
18
from labelbox import utils
20
22
from labelbox .orm .model import Entity
21
23
from labelbox .pagination import PaginatedCollection
22
24
from labelbox .schema .data_row_metadata import DataRowMetadataOntology
25
+ from labelbox .schema .dataset import Dataset
23
26
from labelbox .schema .iam_integration import IAMIntegration
24
27
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
32
+ from labelbox .schema .user import User
33
+ from labelbox .schema .project import Project
34
+ from labelbox .schema .role import Role
26
35
27
36
logger = logging .getLogger (__name__ )
28
37
@@ -411,7 +420,7 @@ def get_project(self, project_id):
411
420
"""
412
421
return self ._get_single (Entity .Project , project_id )
413
422
414
- def get_dataset (self , dataset_id ):
423
+ def get_dataset (self , dataset_id ) -> Dataset :
415
424
""" Gets a single Dataset with the given ID.
416
425
417
426
>>> dataset = client.get_dataset("<dataset_id>")
@@ -426,14 +435,14 @@ def get_dataset(self, dataset_id):
426
435
"""
427
436
return self ._get_single (Entity .Dataset , dataset_id )
428
437
429
- def get_user (self ):
438
+ def get_user (self ) -> User :
430
439
""" Gets the current User database object.
431
440
432
441
>>> user = client.get_user()
433
442
"""
434
443
return self ._get_single (Entity .User , None )
435
444
436
- def get_organization (self ):
445
+ def get_organization (self ) -> Organization :
437
446
""" Gets the Organization DB object of the current user.
438
447
439
448
>>> organization = client.get_organization()
@@ -461,7 +470,7 @@ def _get_all(self, db_object_type, where, filter_deleted=True):
461
470
[utils .camel_case (db_object_type .type_name ()) + "s" ],
462
471
db_object_type )
463
472
464
- def get_projects (self , where = None ):
473
+ def get_projects (self , where = None ) -> List [ Project ] :
465
474
""" Fetches all the projects the user has access to.
466
475
467
476
>>> projects = client.get_projects(where=(Project.name == "<project_name>") & (Project.description == "<project_description>"))
@@ -474,7 +483,7 @@ def get_projects(self, where=None):
474
483
"""
475
484
return self ._get_all (Entity .Project , where )
476
485
477
- def get_datasets (self , where = None ):
486
+ def get_datasets (self , where = None ) -> List [ Dataset ] :
478
487
""" Fetches one or more datasets.
479
488
480
489
>>> datasets = client.get_datasets(where=(Dataset.name == "<dataset_name>") & (Dataset.description == "<dataset_description>"))
@@ -487,7 +496,7 @@ def get_datasets(self, where=None):
487
496
"""
488
497
return self ._get_all (Entity .Dataset , where )
489
498
490
- def get_labeling_frontends (self , where = None ):
499
+ def get_labeling_frontends (self , where = None ) -> List [ LabelingFrontend ] :
491
500
""" Fetches all the labeling frontends.
492
501
493
502
>>> frontend = client.get_labeling_frontends(where=LabelingFrontend.name == "Editor")
@@ -527,7 +536,9 @@ def _create(self, db_object_type, data):
527
536
res = res ["create%s" % db_object_type .type_name ()]
528
537
return db_object_type (self , res )
529
538
530
- def create_dataset (self , iam_integration = IAMIntegration ._DEFAULT , ** kwargs ):
539
+ def create_dataset (self ,
540
+ iam_integration = IAMIntegration ._DEFAULT ,
541
+ ** kwargs ) -> Dataset :
531
542
""" Creates a Dataset object on the server.
532
543
533
544
Attribute values are passed as keyword arguments.
@@ -585,7 +596,7 @@ def create_dataset(self, iam_integration=IAMIntegration._DEFAULT, **kwargs):
585
596
raise e
586
597
return dataset
587
598
588
- def create_project (self , ** kwargs ):
599
+ def create_project (self , ** kwargs ) -> Project :
589
600
""" Creates a Project object on the server.
590
601
591
602
Attribute values are passed as keyword arguments.
@@ -602,15 +613,15 @@ def create_project(self, **kwargs):
602
613
"""
603
614
return self ._create (Entity .Project , kwargs )
604
615
605
- def get_roles (self ):
616
+ def get_roles (self ) -> List [ Role ] :
606
617
"""
607
618
Returns:
608
619
Roles: Provides information on available roles within an organization.
609
620
Roles are used for user management.
610
621
"""
611
622
return role .get_roles (self )
612
623
613
- def get_data_row (self , data_row_id ):
624
+ def get_data_row (self , data_row_id ) -> DataRow :
614
625
"""
615
626
616
627
Returns:
@@ -619,7 +630,7 @@ def get_data_row(self, data_row_id):
619
630
620
631
return self ._get_single (Entity .DataRow , data_row_id )
621
632
622
- def get_data_row_metadata_ontology (self ):
633
+ def get_data_row_metadata_ontology (self ) -> DataRowMetadataOntology :
623
634
"""
624
635
625
636
Returns:
@@ -628,7 +639,7 @@ def get_data_row_metadata_ontology(self):
628
639
"""
629
640
return DataRowMetadataOntology (self )
630
641
631
- def get_model (self , model_id ):
642
+ def get_model (self , model_id ) -> Model :
632
643
""" Gets a single Model with the given ID.
633
644
634
645
>>> model = client.get_model("<model_id>")
@@ -643,7 +654,7 @@ def get_model(self, model_id):
643
654
"""
644
655
return self ._get_single (Entity .Model , model_id )
645
656
646
- def get_models (self , where = None ):
657
+ def get_models (self , where = None ) -> List [ Model ] :
647
658
""" Fetches all the models the user has access to.
648
659
649
660
>>> models = client.get_models(where=(Model.name == "<model_name>"))
@@ -656,7 +667,7 @@ def get_models(self, where=None):
656
667
"""
657
668
return self ._get_all (Entity .Model , where , filter_deleted = False )
658
669
659
- def create_model (self , name , ontology_id ):
670
+ def create_model (self , name , ontology_id ) -> Model :
660
671
""" Creates a Model object on the server.
661
672
662
673
>>> model = client.create_model(<model_name>, <ontology_id>)
@@ -707,7 +718,7 @@ def get_data_row_ids_for_external_ids(
707
718
result [row ['externalId' ]].append (row ['dataRowId' ])
708
719
return result
709
720
710
- def get_ontology (self , ontology_id ):
721
+ def get_ontology (self , ontology_id ) -> Ontology :
711
722
"""
712
723
Fetches an Ontology by id.
713
724
@@ -718,7 +729,7 @@ def get_ontology(self, ontology_id):
718
729
"""
719
730
return self ._get_single (Entity .Ontology , ontology_id )
720
731
721
- def get_ontologies (self , name_contains ):
732
+ def get_ontologies (self , name_contains ) -> PaginatedCollection :
722
733
"""
723
734
Fetches all ontologies with names that match the name_contains string.
724
735
@@ -739,7 +750,7 @@ def get_ontologies(self, name_contains):
739
750
['ontologies' , 'nodes' ], Entity .Ontology ,
740
751
['ontologies' , 'nextCursor' ])
741
752
742
- def get_feature_schema (self , feature_schema_id ):
753
+ def get_feature_schema (self , feature_schema_id ) -> FeatureSchema :
743
754
"""
744
755
Fetches a feature schema. Only supports top level feature schemas.
745
756
@@ -760,7 +771,7 @@ def get_feature_schema(self, feature_schema_id):
760
771
res ['id' ] = res ['normalized' ]['featureSchemaId' ]
761
772
return Entity .FeatureSchema (self , res )
762
773
763
- def get_feature_schemas (self , name_contains ):
774
+ def get_feature_schemas (self , name_contains ) -> PaginatedCollection :
764
775
"""
765
776
Fetches top level feature schemas with names that match the `name_contains` string
766
777
@@ -789,7 +800,8 @@ def rootSchemaPayloadToFeatureSchema(client, payload):
789
800
rootSchemaPayloadToFeatureSchema ,
790
801
['rootSchemaNodes' , 'nextCursor' ])
791
802
792
- def create_ontology_from_feature_schemas (self , name , feature_schema_ids ):
803
+ def create_ontology_from_feature_schemas (self , name ,
804
+ feature_schema_ids ) -> Ontology :
793
805
"""
794
806
Creates an ontology from a list of feature schema ids
795
807
@@ -828,7 +840,7 @@ def create_ontology_from_feature_schemas(self, name, feature_schema_ids):
828
840
normalized = {'tools' : tools , 'classifications' : classifications }
829
841
return self .create_ontology (name , normalized )
830
842
831
- def create_ontology (self , name , normalized ):
843
+ def create_ontology (self , name , normalized ) -> Ontology :
832
844
"""
833
845
Creates an ontology from normalized data
834
846
>>> normalized = {"tools" : [{'tool': 'polygon', 'name': 'cat', 'color': 'black'}], "classifications" : []}
@@ -855,7 +867,7 @@ def create_ontology(self, name, normalized):
855
867
res = self .execute (query_str , params )
856
868
return Entity .Ontology (self , res ['upsertOntology' ])
857
869
858
- def create_feature_schema (self , normalized ):
870
+ def create_feature_schema (self , normalized ) -> FeatureSchema :
859
871
"""
860
872
Creates a feature schema from normalized data.
861
873
>>> normalized = {'tool': 'polygon', 'name': 'cat', 'color': 'black'}
0 commit comments