Skip to content

Commit

Permalink
feat: Add support for filters in export helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Vojta Valter committed Jan 17, 2025
1 parent 358212d commit 8a94d6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 8 additions & 4 deletions rossum_api/elis_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,27 @@ async def retrieve_upload(self, upload_id: int) -> Upload:
upload = await self._http_client.fetch_one(Resource.Upload, upload_id)
return self._deserializer(Resource.Upload, upload)

async def export_annotations_to_json(self, queue_id: int) -> AsyncIterator[Annotation]:
async def export_annotations_to_json(
self, queue_id: int, **filters: Any
) -> AsyncIterator[Annotation]:
"""https://elis.rossum.ai/api/docs/#export-annotations.

JSON export is paginated and returns the result in a way similar to other list_all methods.
"""
async for chunk in self._http_client.export(Resource.Queue, queue_id, "json"):
async for chunk in self._http_client.export(Resource.Queue, queue_id, "json", **filters):
# JSON export can be translated directly to Annotation object
yield self._deserializer(Resource.Annotation, typing.cast(typing.Dict, chunk))

async def export_annotations_to_file(
self, queue_id: int, export_format: ExportFileFormats
self, queue_id: int, export_format: ExportFileFormats, **filters: Any
) -> AsyncIterator[bytes]:
"""https://elis.rossum.ai/api/docs/#export-annotations.

XLSX/CSV/XML exports can be huge, therefore byte streaming is used to keep memory consumption low.
"""
async for chunk in self._http_client.export(Resource.Queue, queue_id, str(export_format)):
async for chunk in self._http_client.export(
Resource.Queue, queue_id, str(export_format), **filters
):
yield typing.cast(bytes, chunk)

# ##### ORGANIZATIONS #####
Expand Down
10 changes: 6 additions & 4 deletions rossum_api/elis_api_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,24 @@ def retrieve_upload(self, upload_id: int) -> Upload:

return self._run_coroutine(self.elis_api_client.retrieve_upload(upload_id))

def export_annotations_to_json(self, queue_id: int) -> Iterator[Annotation]:
def export_annotations_to_json(self, queue_id: int, **filters: Any) -> Iterator[Annotation]:
"""https://elis.rossum.ai/api/docs/#export-annotations.

JSON export is paginated and returns the result in a way similar to other list_all methods.
"""
return self._iter_over_async(self.elis_api_client.export_annotations_to_json(queue_id))
return self._iter_over_async(
self.elis_api_client.export_annotations_to_json(queue_id, **filters)
)

def export_annotations_to_file(
self, queue_id: int, export_format: ExportFileFormats
self, queue_id: int, export_format: ExportFileFormats, **filters: Any
) -> Iterator[bytes]:
"""https://elis.rossum.ai/api/docs/#export-annotations.

XLSX/CSV/XML exports can be huge, therefore byte streaming is used to keep memory consumption low.
"""
return self._iter_over_async(
self.elis_api_client.export_annotations_to_file(queue_id, export_format)
self.elis_api_client.export_annotations_to_file(queue_id, export_format, **filters)
)

# ##### ORGANIZATIONS #####
Expand Down

0 comments on commit 8a94d6f

Please sign in to comment.