-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add export with filters (#198)
* feat: Add export with filters * Add chunked export and import to migrate script * Fix with workspace * Fix empty tasks on import * Set empty label config, import, then copy label config * Black
- Loading branch information
Showing
8 changed files
with
371 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" Export a snapshot with tasks filtered by ID range. | ||
Note: at this moment it's not possible to export snapshots with filters, | ||
LS API doesn't support it yet. However, it's achievable by creating a view | ||
with a filter and then exporting a snapshot using this view. | ||
This approach is hidden behind the `project.export()` method. | ||
""" | ||
|
||
from label_studio_sdk import Client | ||
from label_studio_sdk.data_manager import Filters, Operator, Type, Column | ||
|
||
|
||
# Usage example | ||
host = 'https://app.heartex.com' | ||
api_key = '<your_api_key>' | ||
project_id = 14528 | ||
start_id = 10000 | ||
end_id = 20000 | ||
|
||
# Create a filter for task ID range | ||
filters = Filters.create( | ||
Filters.AND, | ||
[ | ||
Filters.item( | ||
Column.inner_id, | ||
Operator.GREATER_OR_EQUAL, | ||
Type.Number, | ||
Filters.value(start_id), | ||
), | ||
Filters.item( | ||
Column.inner_id, | ||
Operator.LESS, | ||
Type.Number, | ||
Filters.value(end_id), | ||
), | ||
], | ||
) | ||
|
||
print('Export started ...') | ||
ls = Client(url=host, api_key=api_key) | ||
project = ls.get_project(project_id) | ||
result = project.export(filters=filters, export_type="JSON", output_dir='exported') | ||
print( | ||
f"Export file saved as: exported/{result['filename']}, status: {result['status']}, export_id: {result['export_id']}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.