Skip to content

Commit df1c1ba

Browse files
author
Matt Sokoloff
committed
easier fetch bulk import ndjson
1 parent 206c5b0 commit df1c1ba

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

labelbox/schema/bulk_import_request.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,37 @@ class BulkImportRequest(DbObject):
113113
project = Relationship.ToOne("Project")
114114
created_by = Relationship.ToOne("User", False, "created_by")
115115

116+
@property
117+
def inputs(self):
118+
"""
119+
Inputs for each individual annotation uploaded.
120+
* This should match the ndjson annotations that you have uploaded.
121+
* This information will expire after 24 hours.
122+
"""
123+
return self._fetch_remote_ndjson(self.input_file_url)
124+
125+
@property
126+
def errors(self):
127+
"""
128+
Errors for each individual annotation uploaded.
129+
* Returns an empty list if there are no errors and None if the update is still running.
130+
* This information will expire after 24 hours.
131+
"""
132+
return self._fetch_remote_ndjson(self.error_file_url)
133+
134+
@property
135+
def statuses(self):
136+
"""
137+
Status for each individual annotation uploaded.
138+
* Returns a status for each row if the upload is done running and was successful. Otherwise it returns None.
139+
* This information will expire after 24 hours.
140+
"""
141+
return self._fetch_remote_ndjson(self.status_file_url)
142+
143+
def _fetch_remote_ndjson(self, url):
144+
if url is not None:
145+
return ndjson.loads(requests.get(url).text)
146+
116147
def refresh(self) -> None:
117148
"""Synchronizes values of all fields with the database.
118149
"""

labelbox/schema/enums.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33

44
class BulkImportRequestState(Enum):
55
""" State of the import job when importing annotations (RUNNING, FAILED, or FINISHED).
6+
7+
.. list-table::
8+
:widths: 15 150
9+
:header-rows: 1
10+
11+
* - State
12+
- Description
13+
* - RUNNING
14+
- Indicates that the import job is not done yet.
15+
* - FAILED
16+
- Indicates the import job failed. Check `BulkImportRequest.errors` for more information
17+
* - FINISHED
18+
- Indicates the import job is no longer running. Check `BulkImportRequest.statuses` for more information
619
"""
720
RUNNING = "RUNNING"
821
FAILED = "FAILED"

tests/integration/bulk_import/test_bulk_import_request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def test_wait_till_done(configured_project):
133133
assert (bulk_import_request.state == BulkImportRequestState.FINISHED or
134134
bulk_import_request.state == BulkImportRequestState.FAILED)
135135

136+
assert bulk_import_request.errors is not None
137+
assert bulk_import_request.inputs is not None
138+
136139

137140
def assert_file_content(url: str, predictions):
138141
response = requests.get(url)

0 commit comments

Comments
 (0)