Skip to content

Commit 4245636

Browse files
authored
Merge pull request #156 from Labelbox/ms/download-export
download exported data rows
2 parents b39172d + 3d89e39 commit 4245636

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

labelbox/schema/project.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from pathlib import Path
77
from typing import Dict, Union, Iterable
88
from urllib.parse import urlparse
9+
import requests
10+
import ndjson
911

1012
from labelbox import utils
1113
from labelbox.schema.data_row import DataRow
@@ -166,8 +168,9 @@ def export_queued_data_rows(self, timeout_seconds=120):
166168
Args:
167169
timeout_seconds (float): Max waiting time, in seconds.
168170
Returns:
169-
URL of the data file with this DataRow information. If the server didn't
170-
generate during the `timeout_seconds` period, None is returned.
171+
Data row fields for all data rows in the queue as json
172+
Raises:
173+
LabelboxError: if the export fails or is unable to download within the specified time.
171174
"""
172175
id_param = "projectId"
173176
query_str = """mutation GetQueuedDataRowsExportUrlPyApi($%s: ID!)
@@ -178,7 +181,10 @@ def export_queued_data_rows(self, timeout_seconds=120):
178181
res = self.client.execute(query_str, {id_param: self.uid})
179182
res = res["exportQueuedDataRows"]
180183
if res["status"] == "COMPLETE":
181-
return res["downloadUrl"]
184+
download_url = res["downloadUrl"]
185+
response = requests.get(download_url)
186+
response.raise_for_status()
187+
return ndjson.loads(response.text)
182188
elif res["status"] == "FAILED":
183189
raise LabelboxError("Data row export failed.")
184190

tests/integration/test_project.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,5 @@ def test_attach_instructions(client, project):
105105

106106

107107
def test_queued_data_row_export(configured_project):
108-
url = configured_project.export_queued_data_rows()
109-
assert url
110-
result = ndjson.loads(requests.get(url).text)
108+
result = configured_project.export_queued_data_rows()
111109
assert len(result) == 1

0 commit comments

Comments
 (0)