|
12 | 12 |
|
13 | 13 | from labelbox import utils |
14 | 14 | from labelbox.exceptions import (InvalidQueryError, LabelboxError, |
15 | | - ProcessingWaitTimeout, ResourceConflict) |
| 15 | + ProcessingWaitTimeout, ResourceConflict, |
| 16 | + ResourceNotFoundError) |
16 | 17 | from labelbox.orm import query |
17 | 18 | from labelbox.orm.db_object import DbObject, Deletable, Updateable |
18 | 19 | from labelbox.orm.model import Entity, Field, Relationship |
19 | 20 | from labelbox.pagination import PaginatedCollection |
20 | 21 | from labelbox.schema.consensus_settings import ConsensusSettings |
21 | 22 | from labelbox.schema.data_row import DataRow |
| 23 | +from labelbox.schema.export_params import ProjectExportParams |
22 | 24 | from labelbox.schema.media_type import MediaType |
23 | 25 | from labelbox.schema.queue_mode import QueueMode |
24 | 26 | from labelbox.schema.resource_tag import ResourceTag |
| 27 | +from labelbox.schema.task import Task |
| 28 | +from labelbox.schema.user import User |
25 | 29 |
|
26 | 30 | if TYPE_CHECKING: |
27 | 31 | from labelbox import BulkImportRequest |
@@ -371,6 +375,71 @@ def _validate_datetime(string_date: str) -> bool: |
371 | 375 | self.uid) |
372 | 376 | time.sleep(sleep_time) |
373 | 377 |
|
| 378 | + """ |
| 379 | + Creates a project run export task with the given params and returns the task. |
| 380 | + |
| 381 | + >>> export_task = export_v2("my_export_task", filter={"media_attributes": True}) |
| 382 | + |
| 383 | + """ |
| 384 | + |
| 385 | + def export_v2(self, task_name: str, |
| 386 | + params: Optional[ProjectExportParams]) -> Task: |
| 387 | + defaultParams: ProjectExportParams = { |
| 388 | + "attachments": False, |
| 389 | + "media_attributes": False, |
| 390 | + "metadata_fields": False, |
| 391 | + "data_row_details": False, |
| 392 | + "project_details": False, |
| 393 | + "labels": False, |
| 394 | + "performance_details": False |
| 395 | + } |
| 396 | + _params: ProjectExportParams = params if params is not None else defaultParams |
| 397 | + mutation_name = "exportDataRowsInProject" |
| 398 | + create_task_query_str = """mutation exportDataRowsInProjectPyApi($input: ExportDataRowsInProjectInput!){ |
| 399 | + %s(input: $input) {taskId} } |
| 400 | + """ % (mutation_name) |
| 401 | + query_params = { |
| 402 | + "input": { |
| 403 | + "taskName": task_name, |
| 404 | + "filters": { |
| 405 | + "projectId": self.uid |
| 406 | + }, |
| 407 | + "params": { |
| 408 | + "includeAttachments": |
| 409 | + _params.get('attachments', False), |
| 410 | + "includeMediaAttributes": |
| 411 | + _params.get('media_attributes', False), |
| 412 | + "includeMetadata": |
| 413 | + _params.get('metadata_fields', False), |
| 414 | + "includeDataRowDetails": |
| 415 | + _params.get('data_row_details', False), |
| 416 | + "includeProjectDetails": |
| 417 | + _params.get('project_details', False), |
| 418 | + "includeLabels": |
| 419 | + _params.get('labels', False), |
| 420 | + "includePerformanceDetails": |
| 421 | + _params.get('performance_details', False), |
| 422 | + }, |
| 423 | + } |
| 424 | + } |
| 425 | + res = self.client.execute( |
| 426 | + create_task_query_str, |
| 427 | + query_params, |
| 428 | + ) |
| 429 | + res = res[mutation_name] |
| 430 | + task_id = res["taskId"] |
| 431 | + user: User = self.client.get_user() |
| 432 | + tasks: List[Task] = list( |
| 433 | + user.created_tasks(where=Entity.Task.uid == task_id)) |
| 434 | + # Cache user in a private variable as the relationship can't be |
| 435 | + # resolved due to server-side limitations (see Task.created_by) |
| 436 | + # for more info. |
| 437 | + if len(tasks) != 1: |
| 438 | + raise ResourceNotFoundError(Entity.Task, task_id) |
| 439 | + task: Task = tasks[0] |
| 440 | + task._user = user |
| 441 | + return task |
| 442 | + |
374 | 443 | def export_issues(self, status=None) -> str: |
375 | 444 | """ Calls the server-side Issues exporting that |
376 | 445 | returns the URL to that payload. |
|
0 commit comments