@@ -569,6 +569,60 @@ def setup(self, labeling_frontend, labeling_frontend_options) -> None:
569569 timestamp = datetime .now (timezone .utc ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
570570 self .update (setup_complete = timestamp )
571571
572+ def create_batch (self , name : str , data_rows : List [Union [str , "DataRow" ]], priority : "BatchPriority" = 5 ):
573+ """Create a new batch for a project
574+
575+ Args:
576+ name: a name for the batch, must be unique within a project
577+ data_rows: Either a list of `DataRows` or Data Row ids
578+ priority: An optional priority for the Data Rows in the Batch. 1 highest -> 5 lowest
579+
580+ """
581+
582+ # @TODO: make this automatic?
583+ if self .queue_mode () != QueueMode .Batch :
584+ raise ValueError ("Project must be in batch mode" )
585+
586+ dr_ids = []
587+ for dr in data_rows :
588+ from labelbox import DataRow
589+ if isinstance (dr , DataRow ):
590+ dr_ids .append (dr .uid )
591+ elif isinstance (dr , str ):
592+ dr_ids .append (dr )
593+ else :
594+ raise ValueError ("Must pass" )
595+
596+ if len (dr_ids ) > 25_000 :
597+ raise ValueError (
598+ f"Batch exceeds max size, break into smaller batches"
599+ )
600+ if not len (dr_ids ):
601+ raise ValueError ("You need at least one data row in a batch" )
602+
603+ method = 'createBatch'
604+ query_str = """mutation %sPyApi($projectId: ID!, $batchInput: CreateBatchInput!) {
605+ project(where: {id: $projectId}) {
606+ %s(input: $batchInput) {
607+ %s
608+ }
609+ }
610+ }
611+ """ % (method , method , query .results_query_part (Entity .Batch ))
612+
613+ params = {
614+ "projectId" : self .uid ,
615+ "batchInput" : {
616+ "name" : name ,
617+ "dataRowIds" : dr_ids ,
618+ "priority" : priority
619+ }
620+ }
621+
622+ res = self .client .execute (query_str , params , experimental = True )["project" ][method ]
623+ res ['size' ] = len (dr_ids )
624+ return Entity .Batch (self .client , res )
625+
572626 def _update_queue_mode (self , mode : QueueMode ) -> QueueMode :
573627
574628 if self .queue_mode () == mode :
@@ -885,7 +939,7 @@ class LabelingParameterOverride(DbObject):
885939
886940LabelerPerformance = namedtuple (
887941 "LabelerPerformance" , "user count seconds_per_label, total_time_labeling "
888- "consensus average_benchmark_agreement last_activity_time" )
942+ "consensus average_benchmark_agreement last_activity_time" )
889943LabelerPerformance .__doc__ = (
890944 "Named tuple containing info about a labeler's performance." )
891945
0 commit comments