label-studio-sdk 1.0.7__py3-none-any.whl → 1.0.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of label-studio-sdk might be problematic. Click here for more details.

Files changed (206) hide show
  1. label_studio_sdk/__init__.py +26 -7
  2. label_studio_sdk/_extensions/label_studio_tools/core/label_config.py +13 -4
  3. label_studio_sdk/_extensions/label_studio_tools/core/utils/io.py +16 -4
  4. label_studio_sdk/_extensions/label_studio_tools/core/utils/json_schema.py +86 -0
  5. label_studio_sdk/_extensions/pager_ext.py +8 -0
  6. label_studio_sdk/_legacy/schema/label_config_schema.json +42 -11
  7. label_studio_sdk/actions/client.py +91 -40
  8. label_studio_sdk/actions/types/actions_create_request_filters.py +14 -24
  9. label_studio_sdk/actions/types/actions_create_request_filters_items_item.py +16 -26
  10. label_studio_sdk/actions/types/actions_create_request_filters_items_item_value.py +3 -1
  11. label_studio_sdk/actions/types/actions_create_request_selected_items.py +1 -2
  12. label_studio_sdk/actions/types/actions_create_request_selected_items_excluded.py +15 -25
  13. label_studio_sdk/actions/types/actions_create_request_selected_items_included.py +15 -25
  14. label_studio_sdk/annotations/__init__.py +2 -2
  15. label_studio_sdk/annotations/client.py +278 -104
  16. label_studio_sdk/annotations/types/__init__.py +2 -1
  17. label_studio_sdk/annotations/types/annotations_create_bulk_request_selected_items.py +34 -0
  18. label_studio_sdk/annotations/types/annotations_create_bulk_response_item.py +11 -21
  19. label_studio_sdk/base_client.py +46 -27
  20. label_studio_sdk/client.py +1 -0
  21. label_studio_sdk/comments/client.py +190 -44
  22. label_studio_sdk/converter/converter.py +66 -18
  23. label_studio_sdk/converter/imports/yolo.py +1 -1
  24. label_studio_sdk/converter/utils.py +3 -2
  25. label_studio_sdk/core/__init__.py +21 -4
  26. label_studio_sdk/core/client_wrapper.py +9 -10
  27. label_studio_sdk/core/file.py +37 -8
  28. label_studio_sdk/core/http_client.py +52 -28
  29. label_studio_sdk/core/jsonable_encoder.py +33 -31
  30. label_studio_sdk/core/pagination.py +5 -4
  31. label_studio_sdk/core/pydantic_utilities.py +272 -4
  32. label_studio_sdk/core/query_encoder.py +38 -13
  33. label_studio_sdk/core/request_options.py +3 -0
  34. label_studio_sdk/core/serialization.py +272 -0
  35. label_studio_sdk/errors/bad_request_error.py +2 -3
  36. label_studio_sdk/export_storage/azure/client.py +228 -58
  37. label_studio_sdk/export_storage/azure/types/azure_create_response.py +19 -29
  38. label_studio_sdk/export_storage/azure/types/azure_update_response.py +19 -29
  39. label_studio_sdk/export_storage/client.py +48 -18
  40. label_studio_sdk/export_storage/gcs/client.py +228 -58
  41. label_studio_sdk/export_storage/gcs/types/gcs_create_response.py +19 -29
  42. label_studio_sdk/export_storage/gcs/types/gcs_update_response.py +19 -29
  43. label_studio_sdk/export_storage/local/client.py +222 -56
  44. label_studio_sdk/export_storage/local/types/local_create_response.py +17 -27
  45. label_studio_sdk/export_storage/local/types/local_update_response.py +17 -27
  46. label_studio_sdk/export_storage/redis/client.py +228 -58
  47. label_studio_sdk/export_storage/redis/types/redis_create_response.py +20 -30
  48. label_studio_sdk/export_storage/redis/types/redis_update_response.py +20 -30
  49. label_studio_sdk/export_storage/s3/client.py +228 -58
  50. label_studio_sdk/export_storage/s3/types/s3create_response.py +27 -35
  51. label_studio_sdk/export_storage/s3/types/s3update_response.py +27 -35
  52. label_studio_sdk/export_storage/s3s/client.py +187 -43
  53. label_studio_sdk/export_storage/types/export_storage_list_types_response_item.py +11 -21
  54. label_studio_sdk/files/client.py +172 -56
  55. label_studio_sdk/import_storage/azure/client.py +223 -53
  56. label_studio_sdk/import_storage/azure/types/azure_create_response.py +22 -32
  57. label_studio_sdk/import_storage/azure/types/azure_update_response.py +22 -32
  58. label_studio_sdk/import_storage/client.py +48 -18
  59. label_studio_sdk/import_storage/gcs/client.py +223 -53
  60. label_studio_sdk/import_storage/gcs/types/gcs_create_response.py +22 -32
  61. label_studio_sdk/import_storage/gcs/types/gcs_update_response.py +22 -32
  62. label_studio_sdk/import_storage/local/client.py +223 -53
  63. label_studio_sdk/import_storage/local/types/local_create_response.py +17 -27
  64. label_studio_sdk/import_storage/local/types/local_update_response.py +17 -27
  65. label_studio_sdk/import_storage/redis/client.py +223 -53
  66. label_studio_sdk/import_storage/redis/types/redis_create_response.py +20 -30
  67. label_studio_sdk/import_storage/redis/types/redis_update_response.py +20 -30
  68. label_studio_sdk/import_storage/s3/client.py +223 -53
  69. label_studio_sdk/import_storage/s3/types/s3create_response.py +31 -39
  70. label_studio_sdk/import_storage/s3/types/s3update_response.py +31 -39
  71. label_studio_sdk/import_storage/s3s/client.py +222 -52
  72. label_studio_sdk/import_storage/types/import_storage_list_types_response_item.py +11 -21
  73. label_studio_sdk/label_interface/control_tags.py +205 -10
  74. label_studio_sdk/label_interface/interface.py +80 -6
  75. label_studio_sdk/label_interface/region.py +1 -10
  76. label_studio_sdk/ml/client.py +280 -78
  77. label_studio_sdk/ml/types/ml_create_response.py +21 -31
  78. label_studio_sdk/ml/types/ml_update_response.py +21 -31
  79. label_studio_sdk/model_providers/client.py +656 -21
  80. label_studio_sdk/predictions/client.py +247 -101
  81. label_studio_sdk/projects/__init__.py +3 -0
  82. label_studio_sdk/projects/client.py +309 -115
  83. label_studio_sdk/projects/client_ext.py +16 -0
  84. label_studio_sdk/projects/exports/__init__.py +3 -0
  85. label_studio_sdk/projects/exports/client.py +447 -296
  86. label_studio_sdk/projects/exports/client_ext.py +134 -0
  87. label_studio_sdk/projects/exports/types/__init__.py +6 -0
  88. label_studio_sdk/projects/exports/types/exports_convert_response.py +24 -0
  89. label_studio_sdk/projects/exports/types/exports_list_formats_response_item.py +44 -0
  90. label_studio_sdk/projects/types/projects_create_response.py +29 -34
  91. label_studio_sdk/projects/types/projects_import_tasks_response.py +19 -29
  92. label_studio_sdk/projects/types/projects_list_response.py +11 -21
  93. label_studio_sdk/projects/types/projects_update_response.py +24 -34
  94. label_studio_sdk/prompts/client.py +309 -92
  95. label_studio_sdk/prompts/indicators/client.py +67 -23
  96. label_studio_sdk/prompts/runs/client.py +95 -40
  97. label_studio_sdk/prompts/types/prompts_batch_failed_predictions_request_failed_predictions_item.py +14 -24
  98. label_studio_sdk/prompts/types/prompts_batch_failed_predictions_response.py +11 -21
  99. label_studio_sdk/prompts/types/prompts_batch_predictions_request_results_item.py +26 -29
  100. label_studio_sdk/prompts/types/prompts_batch_predictions_response.py +11 -21
  101. label_studio_sdk/prompts/versions/client.py +389 -75
  102. label_studio_sdk/tasks/client.py +263 -90
  103. label_studio_sdk/tasks/types/tasks_list_response.py +15 -25
  104. label_studio_sdk/types/__init__.py +16 -6
  105. label_studio_sdk/types/annotation.py +29 -38
  106. label_studio_sdk/types/annotation_filter_options.py +14 -24
  107. label_studio_sdk/types/annotations_dm_field.py +30 -39
  108. label_studio_sdk/types/azure_blob_export_storage.py +28 -37
  109. label_studio_sdk/types/azure_blob_import_storage.py +28 -37
  110. label_studio_sdk/types/base_task.py +30 -39
  111. label_studio_sdk/types/base_task_updated_by.py +3 -1
  112. label_studio_sdk/types/base_user.py +14 -21
  113. label_studio_sdk/types/comment.py +12 -21
  114. label_studio_sdk/types/comment_created_by.py +1 -1
  115. label_studio_sdk/types/converted_format.py +12 -22
  116. label_studio_sdk/types/data_manager_task_serializer.py +31 -40
  117. label_studio_sdk/types/data_manager_task_serializer_annotators_item.py +1 -1
  118. label_studio_sdk/types/data_manager_task_serializer_drafts_item.py +13 -22
  119. label_studio_sdk/types/data_manager_task_serializer_predictions_item.py +15 -24
  120. label_studio_sdk/types/export.py +17 -26
  121. label_studio_sdk/types/export_format.py +25 -0
  122. label_studio_sdk/types/export_snapshot.py +45 -0
  123. label_studio_sdk/types/export_snapshot_status.py +5 -0
  124. label_studio_sdk/types/file_upload.py +11 -21
  125. label_studio_sdk/types/filter.py +16 -26
  126. label_studio_sdk/types/filter_group.py +12 -22
  127. label_studio_sdk/types/gcs_export_storage.py +28 -37
  128. label_studio_sdk/types/gcs_import_storage.py +28 -37
  129. label_studio_sdk/types/inference_run.py +14 -23
  130. label_studio_sdk/types/inference_run_cost_estimate.py +47 -0
  131. label_studio_sdk/types/inference_run_created_by.py +1 -1
  132. label_studio_sdk/types/inference_run_organization.py +1 -1
  133. label_studio_sdk/types/key_indicator_value.py +12 -22
  134. label_studio_sdk/types/key_indicators.py +0 -1
  135. label_studio_sdk/types/key_indicators_item.py +15 -25
  136. label_studio_sdk/types/key_indicators_item_additional_kpis_item.py +13 -23
  137. label_studio_sdk/types/key_indicators_item_extra_kpis_item.py +13 -23
  138. label_studio_sdk/types/local_files_export_storage.py +25 -34
  139. label_studio_sdk/types/local_files_import_storage.py +24 -33
  140. label_studio_sdk/types/ml_backend.py +23 -32
  141. label_studio_sdk/types/model_provider_connection.py +47 -26
  142. label_studio_sdk/types/model_provider_connection_budget_reset_period.py +5 -0
  143. label_studio_sdk/types/model_provider_connection_created_by.py +1 -1
  144. label_studio_sdk/types/model_provider_connection_organization.py +1 -1
  145. label_studio_sdk/types/model_provider_connection_provider.py +3 -1
  146. label_studio_sdk/types/prediction.py +21 -30
  147. label_studio_sdk/types/project.py +48 -55
  148. label_studio_sdk/types/project_import.py +21 -30
  149. label_studio_sdk/types/project_label_config.py +12 -22
  150. label_studio_sdk/types/prompt.py +24 -32
  151. label_studio_sdk/types/prompt_associated_projects_item.py +6 -0
  152. label_studio_sdk/types/prompt_associated_projects_item_id.py +20 -0
  153. label_studio_sdk/types/prompt_created_by.py +1 -1
  154. label_studio_sdk/types/prompt_organization.py +1 -1
  155. label_studio_sdk/types/prompt_version.py +13 -22
  156. label_studio_sdk/types/prompt_version_created_by.py +1 -1
  157. label_studio_sdk/types/prompt_version_organization.py +1 -1
  158. label_studio_sdk/types/prompt_version_provider.py +3 -1
  159. label_studio_sdk/types/redis_export_storage.py +29 -38
  160. label_studio_sdk/types/redis_import_storage.py +28 -37
  161. label_studio_sdk/types/refined_prompt_response.py +19 -29
  162. label_studio_sdk/types/s3export_storage.py +36 -43
  163. label_studio_sdk/types/s3import_storage.py +37 -44
  164. label_studio_sdk/types/s3s_export_storage.py +26 -33
  165. label_studio_sdk/types/s3s_import_storage.py +35 -42
  166. label_studio_sdk/types/serialization_option.py +12 -22
  167. label_studio_sdk/types/serialization_options.py +18 -28
  168. label_studio_sdk/types/task.py +46 -48
  169. label_studio_sdk/types/task_annotators_item.py +1 -1
  170. label_studio_sdk/types/task_comment_authors_item.py +5 -0
  171. label_studio_sdk/types/task_filter_options.py +15 -25
  172. label_studio_sdk/types/user_simple.py +11 -21
  173. label_studio_sdk/types/view.py +16 -26
  174. label_studio_sdk/types/webhook.py +19 -28
  175. label_studio_sdk/types/webhook_serializer_for_update.py +19 -28
  176. label_studio_sdk/types/workspace.py +22 -31
  177. label_studio_sdk/users/client.py +257 -63
  178. label_studio_sdk/users/types/users_get_token_response.py +12 -22
  179. label_studio_sdk/users/types/users_reset_token_response.py +12 -22
  180. label_studio_sdk/version.py +0 -1
  181. label_studio_sdk/versions/__init__.py +5 -0
  182. label_studio_sdk/versions/client.py +112 -0
  183. label_studio_sdk/versions/types/__init__.py +6 -0
  184. label_studio_sdk/versions/types/versions_get_response.py +73 -0
  185. label_studio_sdk/versions/types/versions_get_response_edition.py +5 -0
  186. label_studio_sdk/views/client.py +219 -52
  187. label_studio_sdk/views/types/views_create_request_data.py +13 -23
  188. label_studio_sdk/views/types/views_create_request_data_filters.py +14 -24
  189. label_studio_sdk/views/types/views_create_request_data_filters_items_item.py +16 -26
  190. label_studio_sdk/views/types/views_create_request_data_filters_items_item_value.py +3 -1
  191. label_studio_sdk/views/types/views_update_request_data.py +13 -23
  192. label_studio_sdk/views/types/views_update_request_data_filters.py +14 -24
  193. label_studio_sdk/views/types/views_update_request_data_filters_items_item.py +16 -26
  194. label_studio_sdk/views/types/views_update_request_data_filters_items_item_value.py +3 -1
  195. label_studio_sdk/webhooks/client.py +191 -61
  196. label_studio_sdk/workspaces/client.py +164 -41
  197. label_studio_sdk/workspaces/members/client.py +109 -31
  198. label_studio_sdk/workspaces/members/types/members_create_response.py +12 -22
  199. label_studio_sdk/workspaces/members/types/members_list_response_item.py +12 -22
  200. {label_studio_sdk-1.0.7.dist-info → label_studio_sdk-1.0.10.dist-info}/METADATA +9 -5
  201. {label_studio_sdk-1.0.7.dist-info → label_studio_sdk-1.0.10.dist-info}/RECORD +203 -186
  202. {label_studio_sdk-1.0.7.dist-info → label_studio_sdk-1.0.10.dist-info}/WHEEL +1 -1
  203. label_studio_sdk/types/export_convert.py +0 -32
  204. label_studio_sdk/types/export_create.py +0 -54
  205. label_studio_sdk/types/export_create_status.py +0 -5
  206. {label_studio_sdk-1.0.7.dist-info → label_studio_sdk-1.0.10.dist-info}/LICENSE +0 -0
@@ -1,23 +1,26 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
- import datetime as dt
4
3
  import typing
4
+ from ...core.client_wrapper import SyncClientWrapper
5
+ from ...core.request_options import RequestOptions
6
+ from ...core.jsonable_encoder import jsonable_encoder
5
7
  from json.decoder import JSONDecodeError
6
-
7
8
  from ...core.api_error import ApiError
8
- from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9
- from ...core.jsonable_encoder import jsonable_encoder
10
- from ...core.pydantic_utilities import pydantic_v1
11
- from ...core.request_options import RequestOptions
12
- from ...types.annotation_filter_options import AnnotationFilterOptions
13
- from ...types.converted_format import ConvertedFormat
9
+ from .types.exports_list_formats_response_item import ExportsListFormatsResponseItem
10
+ from ...core.pydantic_utilities import parse_obj_as
14
11
  from ...types.export import Export
15
- from ...types.export_convert import ExportConvert
16
- from ...types.export_create import ExportCreate
17
- from ...types.export_create_status import ExportCreateStatus
18
- from ...types.serialization_options import SerializationOptions
19
- from ...types.task_filter_options import TaskFilterOptions
20
12
  from ...types.user_simple import UserSimple
13
+ import datetime as dt
14
+ from ...types.export_snapshot_status import ExportSnapshotStatus
15
+ from ...types.converted_format import ConvertedFormat
16
+ from ...types.task_filter_options import TaskFilterOptions
17
+ from ...types.annotation_filter_options import AnnotationFilterOptions
18
+ from ...types.serialization_options import SerializationOptions
19
+ from ...types.export_snapshot import ExportSnapshot
20
+ from ...core.serialization import convert_and_respect_annotation_metadata
21
+ from ...types.export_format import ExportFormat
22
+ from .types.exports_convert_response import ExportsConvertResponse
23
+ from ...core.client_wrapper import AsyncClientWrapper
21
24
 
22
25
  # this is used as the default value for optional parameters
23
26
  OMIT = typing.cast(typing.Any, ...)
@@ -27,34 +30,30 @@ class ExportsClient:
27
30
  def __init__(self, *, client_wrapper: SyncClientWrapper):
28
31
  self._client_wrapper = client_wrapper
29
32
 
30
- def create_export(
33
+ def download_sync(
31
34
  self,
32
35
  id: int,
33
36
  *,
34
37
  export_type: typing.Optional[str] = None,
35
- download_all_tasks: typing.Optional[str] = None,
38
+ download_all_tasks: typing.Optional[bool] = None,
36
39
  download_resources: typing.Optional[bool] = None,
37
40
  ids: typing.Optional[typing.Union[int, typing.Sequence[int]]] = None,
38
41
  request_options: typing.Optional[RequestOptions] = None,
39
42
  ) -> typing.Iterator[bytes]:
40
43
  """
44
+
41
45
  <Note>If you have a large project it's recommended to use export snapshots, this easy export endpoint might have timeouts.</Note>
42
46
  Export annotated tasks as a file in a specific format.
43
47
  For example, to export JSON annotations for a project to a file called `annotations.json`,
44
48
  run the following from the command line:
45
-
46
49
  ```bash
47
50
  curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON -H 'Authorization: Token abc123' --output 'annotations.json'
48
51
  ```
49
-
50
52
  To export all tasks, including skipped tasks and others without annotations, run the following from the command line:
51
-
52
53
  ```bash
53
54
  curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON&download_all_tasks=true -H 'Authorization: Token abc123' --output 'annotations.json'
54
55
  ```
55
-
56
56
  To export specific tasks with IDs of 123 and 345, run the following from the command line:
57
-
58
57
  ```bash
59
58
  curl -X GET https://localhost:8080/api/projects/{id}/export?ids[]=123\&ids[]=345 -H 'Authorization: Token abc123' --output 'annotations.json'
60
59
  ```
@@ -69,37 +68,25 @@ class ExportsClient:
69
68
  export_type : typing.Optional[str]
70
69
  Selected export format (JSON by default)
71
70
 
72
- download_all_tasks : typing.Optional[str]
71
+ download_all_tasks : typing.Optional[bool]
72
+
73
73
  If true, download all tasks regardless of status. If false, download only annotated tasks.
74
74
 
75
75
  download_resources : typing.Optional[bool]
76
+
76
77
  If true, download all resource files such as images, audio, and others relevant to the tasks.
77
78
 
78
79
  ids : typing.Optional[typing.Union[int, typing.Sequence[int]]]
80
+
79
81
  Specify a list of task IDs to retrieve only the details for those tasks.
80
82
 
81
83
  request_options : typing.Optional[RequestOptions]
82
- Request-specific configuration.
84
+ Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
83
85
 
84
86
  Yields
85
87
  ------
86
88
  typing.Iterator[bytes]
87
- Exported data
88
-
89
- Examples
90
- --------
91
- from label_studio_sdk.client import LabelStudio
92
-
93
- client = LabelStudio(
94
- api_key="YOUR_API_KEY",
95
- )
96
- client.projects.exports.create_export(
97
- id=1,
98
- export_type="string",
99
- download_all_tasks="string",
100
- download_resources=True,
101
- ids=1,
102
- )
89
+ Exported data in binary format
103
90
  """
104
91
  with self._client_wrapper.httpx_client.stream(
105
92
  f"api/projects/{jsonable_encoder(id)}/export",
@@ -114,7 +101,8 @@ class ExportsClient:
114
101
  ) as _response:
115
102
  try:
116
103
  if 200 <= _response.status_code < 300:
117
- for _chunk in _response.iter_bytes():
104
+ _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
105
+ for _chunk in _response.iter_bytes(chunk_size=_chunk_size):
118
106
  yield _chunk
119
107
  return
120
108
  _response.read()
@@ -123,8 +111,11 @@ class ExportsClient:
123
111
  raise ApiError(status_code=_response.status_code, body=_response.text)
124
112
  raise ApiError(status_code=_response.status_code, body=_response_json)
125
113
 
126
- def list_formats(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[str]:
114
+ def list_formats(
115
+ self, id: int, *, request_options: typing.Optional[RequestOptions] = None
116
+ ) -> typing.List[ExportsListFormatsResponseItem]:
127
117
  """
118
+
128
119
  Before exporting annotations, you can check with formats are supported by the specified project. For more information about export formats, see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
129
120
 
130
121
  You must provide a project ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
@@ -139,12 +130,12 @@ class ExportsClient:
139
130
 
140
131
  Returns
141
132
  -------
142
- typing.List[str]
133
+ typing.List[ExportsListFormatsResponseItem]
143
134
  Export formats
144
135
 
145
136
  Examples
146
137
  --------
147
- from label_studio_sdk.client import LabelStudio
138
+ from label_studio_sdk import LabelStudio
148
139
 
149
140
  client = LabelStudio(
150
141
  api_key="YOUR_API_KEY",
@@ -154,25 +145,34 @@ class ExportsClient:
154
145
  )
155
146
  """
156
147
  _response = self._client_wrapper.httpx_client.request(
157
- f"api/projects/{jsonable_encoder(id)}/export/formats", method="GET", request_options=request_options
148
+ f"api/projects/{jsonable_encoder(id)}/export/formats",
149
+ method="GET",
150
+ request_options=request_options,
158
151
  )
159
152
  try:
160
153
  if 200 <= _response.status_code < 300:
161
- return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore
154
+ return typing.cast(
155
+ typing.List[ExportsListFormatsResponseItem],
156
+ parse_obj_as(
157
+ type_=typing.List[ExportsListFormatsResponseItem], # type: ignore
158
+ object_=_response.json(),
159
+ ),
160
+ )
162
161
  _response_json = _response.json()
163
162
  except JSONDecodeError:
164
163
  raise ApiError(status_code=_response.status_code, body=_response.text)
165
164
  raise ApiError(status_code=_response.status_code, body=_response_json)
166
165
 
167
- def list(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Export]:
166
+ def list(self, project_id: int, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Export]:
168
167
  """
168
+
169
169
  Returns a list of export file (snapshots) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
170
170
 
171
171
  Included in the response is information about each snapshot, such as who created it and what format it is in.
172
172
 
173
173
  Parameters
174
174
  ----------
175
- id : int
175
+ project_id : int
176
176
  A unique integer value identifying this project.
177
177
 
178
178
  request_options : typing.Optional[RequestOptions]
@@ -185,21 +185,29 @@ class ExportsClient:
185
185
 
186
186
  Examples
187
187
  --------
188
- from label_studio_sdk.client import LabelStudio
188
+ from label_studio_sdk import LabelStudio
189
189
 
190
190
  client = LabelStudio(
191
191
  api_key="YOUR_API_KEY",
192
192
  )
193
193
  client.projects.exports.list(
194
- id=1,
194
+ project_id=1,
195
195
  )
196
196
  """
197
197
  _response = self._client_wrapper.httpx_client.request(
198
- f"api/projects/{jsonable_encoder(id)}/exports/", method="GET", request_options=request_options
198
+ f"api/projects/{jsonable_encoder(project_id)}/exports",
199
+ method="GET",
200
+ request_options=request_options,
199
201
  )
200
202
  try:
201
203
  if 200 <= _response.status_code < 300:
202
- return pydantic_v1.parse_obj_as(typing.List[Export], _response.json()) # type: ignore
204
+ return typing.cast(
205
+ typing.List[Export],
206
+ parse_obj_as(
207
+ type_=typing.List[Export], # type: ignore
208
+ object_=_response.json(),
209
+ ),
210
+ )
203
211
  _response_json = _response.json()
204
212
  except JSONDecodeError:
205
213
  raise ApiError(status_code=_response.status_code, body=_response.text)
@@ -207,23 +215,24 @@ class ExportsClient:
207
215
 
208
216
  def create(
209
217
  self,
210
- id_: int,
218
+ project_id: int,
211
219
  *,
212
220
  title: typing.Optional[str] = OMIT,
213
221
  id: typing.Optional[int] = OMIT,
214
222
  created_by: typing.Optional[UserSimple] = OMIT,
215
223
  created_at: typing.Optional[dt.datetime] = OMIT,
216
224
  finished_at: typing.Optional[dt.datetime] = OMIT,
217
- status: typing.Optional[ExportCreateStatus] = OMIT,
225
+ status: typing.Optional[ExportSnapshotStatus] = OMIT,
218
226
  md5: typing.Optional[str] = OMIT,
219
- counters: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
227
+ counters: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
220
228
  converted_formats: typing.Optional[typing.Sequence[ConvertedFormat]] = OMIT,
221
229
  task_filter_options: typing.Optional[TaskFilterOptions] = OMIT,
222
230
  annotation_filter_options: typing.Optional[AnnotationFilterOptions] = OMIT,
223
231
  serialization_options: typing.Optional[SerializationOptions] = OMIT,
224
232
  request_options: typing.Optional[RequestOptions] = None,
225
- ) -> ExportCreate:
233
+ ) -> ExportSnapshot:
226
234
  """
235
+
227
236
  Create a new export request to start a background task and generate an export file (snapshot) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
228
237
 
229
238
  A snapshot is a static export of your project's data and annotations at a specific point in time. It captures the current state of your tasks, annotations, and other relevant data, allowing you to download and review them later. Snapshots are particularly useful for large projects as they help avoid timeouts during export operations by processing the data asynchronously.
@@ -232,7 +241,7 @@ class ExportsClient:
232
241
 
233
242
  Parameters
234
243
  ----------
235
- id_ : int
244
+ project_id : int
236
245
  A unique integer value identifying this project.
237
246
 
238
247
  title : typing.Optional[str]
@@ -247,11 +256,11 @@ class ExportsClient:
247
256
  finished_at : typing.Optional[dt.datetime]
248
257
  Complete or fail time
249
258
 
250
- status : typing.Optional[ExportCreateStatus]
259
+ status : typing.Optional[ExportSnapshotStatus]
251
260
 
252
261
  md5 : typing.Optional[str]
253
262
 
254
- counters : typing.Optional[typing.Dict[str, typing.Any]]
263
+ counters : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
255
264
 
256
265
  converted_formats : typing.Optional[typing.Sequence[ConvertedFormat]]
257
266
 
@@ -266,106 +275,133 @@ class ExportsClient:
266
275
 
267
276
  Returns
268
277
  -------
269
- ExportCreate
278
+ ExportSnapshot
270
279
 
271
280
 
272
281
  Examples
273
282
  --------
274
- from label_studio_sdk.client import LabelStudio
283
+ from label_studio_sdk import LabelStudio
275
284
 
276
285
  client = LabelStudio(
277
286
  api_key="YOUR_API_KEY",
278
287
  )
279
288
  client.projects.exports.create(
280
- id_=1,
289
+ project_id=1,
281
290
  )
282
291
  """
283
292
  _response = self._client_wrapper.httpx_client.request(
284
- f"api/projects/{jsonable_encoder(id_)}/exports/",
293
+ f"api/projects/{jsonable_encoder(project_id)}/exports",
285
294
  method="POST",
286
295
  json={
287
296
  "title": title,
288
297
  "id": id,
289
- "created_by": created_by,
298
+ "created_by": convert_and_respect_annotation_metadata(
299
+ object_=created_by, annotation=UserSimple, direction="write"
300
+ ),
290
301
  "created_at": created_at,
291
302
  "finished_at": finished_at,
292
303
  "status": status,
293
304
  "md5": md5,
294
305
  "counters": counters,
295
- "converted_formats": converted_formats,
296
- "task_filter_options": task_filter_options,
297
- "annotation_filter_options": annotation_filter_options,
298
- "serialization_options": serialization_options,
306
+ "converted_formats": convert_and_respect_annotation_metadata(
307
+ object_=converted_formats, annotation=typing.Sequence[ConvertedFormat], direction="write"
308
+ ),
309
+ "task_filter_options": convert_and_respect_annotation_metadata(
310
+ object_=task_filter_options, annotation=TaskFilterOptions, direction="write"
311
+ ),
312
+ "annotation_filter_options": convert_and_respect_annotation_metadata(
313
+ object_=annotation_filter_options, annotation=AnnotationFilterOptions, direction="write"
314
+ ),
315
+ "serialization_options": convert_and_respect_annotation_metadata(
316
+ object_=serialization_options, annotation=SerializationOptions, direction="write"
317
+ ),
299
318
  },
300
319
  request_options=request_options,
301
320
  omit=OMIT,
302
321
  )
303
322
  try:
304
323
  if 200 <= _response.status_code < 300:
305
- return pydantic_v1.parse_obj_as(ExportCreate, _response.json()) # type: ignore
324
+ return typing.cast(
325
+ ExportSnapshot,
326
+ parse_obj_as(
327
+ type_=ExportSnapshot, # type: ignore
328
+ object_=_response.json(),
329
+ ),
330
+ )
306
331
  _response_json = _response.json()
307
332
  except JSONDecodeError:
308
333
  raise ApiError(status_code=_response.status_code, body=_response.text)
309
334
  raise ApiError(status_code=_response.status_code, body=_response_json)
310
335
 
311
- def get(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> Export:
336
+ def download(
337
+ self,
338
+ project_id: int,
339
+ export_pk: str,
340
+ *,
341
+ export_type: typing.Optional[ExportFormat] = None,
342
+ request_options: typing.Optional[RequestOptions] = None,
343
+ ) -> typing.Iterator[bytes]:
312
344
  """
313
- Retrieve information about a specific export file (snapshot).
314
345
 
315
- You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).
346
+ Download an export snapshot as a file in a specified format. To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
316
347
 
317
- You will also need the project ID. This can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
348
+ You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).
349
+
350
+ The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
318
351
 
319
352
  Parameters
320
353
  ----------
321
- id : int
354
+ project_id : int
322
355
  A unique integer value identifying this project.
323
356
 
324
357
  export_pk : str
325
358
  Primary key identifying the export file.
326
359
 
327
- request_options : typing.Optional[RequestOptions]
328
- Request-specific configuration.
329
-
330
- Returns
331
- -------
332
- Export
333
-
360
+ export_type : typing.Optional[ExportFormat]
361
+ Selected export format. JSON is available by default. For other formats, you need to convert the export first.
334
362
 
335
- Examples
336
- --------
337
- from label_studio_sdk.client import LabelStudio
363
+ request_options : typing.Optional[RequestOptions]
364
+ Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
338
365
 
339
- client = LabelStudio(
340
- api_key="YOUR_API_KEY",
341
- )
342
- client.projects.exports.get(
343
- id=1,
344
- export_pk="export_pk",
345
- )
366
+ Yields
367
+ ------
368
+ typing.Iterator[bytes]
369
+ Exported data in binary format
346
370
  """
347
- _response = self._client_wrapper.httpx_client.request(
348
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
371
+ with self._client_wrapper.httpx_client.stream(
372
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}/download",
349
373
  method="GET",
374
+ params={
375
+ "exportType": export_type,
376
+ },
350
377
  request_options=request_options,
351
- )
352
- try:
353
- if 200 <= _response.status_code < 300:
354
- return pydantic_v1.parse_obj_as(Export, _response.json()) # type: ignore
355
- _response_json = _response.json()
356
- except JSONDecodeError:
357
- raise ApiError(status_code=_response.status_code, body=_response.text)
358
- raise ApiError(status_code=_response.status_code, body=_response_json)
378
+ ) as _response:
379
+ try:
380
+ if 200 <= _response.status_code < 300:
381
+ _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
382
+ for _chunk in _response.iter_bytes(chunk_size=_chunk_size):
383
+ yield _chunk
384
+ return
385
+ _response.read()
386
+ _response_json = _response.json()
387
+ except JSONDecodeError:
388
+ raise ApiError(status_code=_response.status_code, body=_response.text)
389
+ raise ApiError(status_code=_response.status_code, body=_response_json)
359
390
 
360
- def delete(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
391
+ def get(
392
+ self, project_id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None
393
+ ) -> Export:
361
394
  """
362
- Delete an export file by specified export ID.
395
+
396
+ Retrieve information about a specific export file (snapshot).
363
397
 
364
398
  You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).
365
399
 
400
+ You will also need the project ID. This can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
401
+
366
402
  Parameters
367
403
  ----------
368
- id : int
404
+ project_id : int
369
405
  A unique integer value identifying this project.
370
406
 
371
407
  export_pk : str
@@ -376,102 +412,103 @@ class ExportsClient:
376
412
 
377
413
  Returns
378
414
  -------
379
- None
415
+ Export
416
+
380
417
 
381
418
  Examples
382
419
  --------
383
- from label_studio_sdk.client import LabelStudio
420
+ from label_studio_sdk import LabelStudio
384
421
 
385
422
  client = LabelStudio(
386
423
  api_key="YOUR_API_KEY",
387
424
  )
388
- client.projects.exports.delete(
389
- id=1,
425
+ client.projects.exports.get(
426
+ project_id=1,
390
427
  export_pk="export_pk",
391
428
  )
392
429
  """
393
430
  _response = self._client_wrapper.httpx_client.request(
394
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
395
- method="DELETE",
431
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}",
432
+ method="GET",
396
433
  request_options=request_options,
397
434
  )
398
435
  try:
399
436
  if 200 <= _response.status_code < 300:
400
- return
437
+ return typing.cast(
438
+ Export,
439
+ parse_obj_as(
440
+ type_=Export, # type: ignore
441
+ object_=_response.json(),
442
+ ),
443
+ )
401
444
  _response_json = _response.json()
402
445
  except JSONDecodeError:
403
446
  raise ApiError(status_code=_response.status_code, body=_response.text)
404
447
  raise ApiError(status_code=_response.status_code, body=_response_json)
405
448
 
406
- def convert(
407
- self, id: int, export_pk: str, *, export_type: str, request_options: typing.Optional[RequestOptions] = None
408
- ) -> ExportConvert:
449
+ def delete(
450
+ self, project_id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None
451
+ ) -> None:
409
452
  """
410
- You can use this to convert an export snapshot into the selected format.
411
-
412
- To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
413
453
 
414
- You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).
454
+ Delete an export file by specified export ID.
415
455
 
416
- The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
456
+ You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).
417
457
 
418
458
  Parameters
419
459
  ----------
420
- id : int
460
+ project_id : int
421
461
  A unique integer value identifying this project.
422
462
 
423
463
  export_pk : str
424
464
  Primary key identifying the export file.
425
465
 
426
- export_type : str
427
- Export file format.
428
-
429
466
  request_options : typing.Optional[RequestOptions]
430
467
  Request-specific configuration.
431
468
 
432
469
  Returns
433
470
  -------
434
- ExportConvert
435
-
471
+ None
436
472
 
437
473
  Examples
438
474
  --------
439
- from label_studio_sdk.client import LabelStudio
475
+ from label_studio_sdk import LabelStudio
440
476
 
441
477
  client = LabelStudio(
442
478
  api_key="YOUR_API_KEY",
443
479
  )
444
- client.projects.exports.convert(
445
- id=1,
480
+ client.projects.exports.delete(
481
+ project_id=1,
446
482
  export_pk="export_pk",
447
- export_type="export_type",
448
483
  )
449
484
  """
450
485
  _response = self._client_wrapper.httpx_client.request(
451
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/convert",
452
- method="POST",
453
- json={"export_type": export_type},
486
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}",
487
+ method="DELETE",
454
488
  request_options=request_options,
455
- omit=OMIT,
456
489
  )
457
490
  try:
458
491
  if 200 <= _response.status_code < 300:
459
- return pydantic_v1.parse_obj_as(ExportConvert, _response.json()) # type: ignore
492
+ return
460
493
  _response_json = _response.json()
461
494
  except JSONDecodeError:
462
495
  raise ApiError(status_code=_response.status_code, body=_response.text)
463
496
  raise ApiError(status_code=_response.status_code, body=_response_json)
464
497
 
465
- def download(
498
+ def convert(
466
499
  self,
467
- id: int,
500
+ project_id: int,
468
501
  export_pk: str,
469
502
  *,
470
- export_type: typing.Optional[str] = None,
503
+ export_type: typing.Optional[ExportFormat] = OMIT,
504
+ download_resources: typing.Optional[bool] = OMIT,
471
505
  request_options: typing.Optional[RequestOptions] = None,
472
- ) -> None:
506
+ ) -> ExportsConvertResponse:
473
507
  """
474
- Download an export snapshot as a file in a specified format. To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
508
+
509
+ You can use this to convert an export snapshot into the selected format.
510
+
511
+ To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
475
512
 
476
513
  You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).
477
514
 
@@ -479,43 +516,59 @@ class ExportsClient:
479
516
 
480
517
  Parameters
481
518
  ----------
482
- id : int
519
+ project_id : int
483
520
  A unique integer value identifying this project.
484
521
 
485
522
  export_pk : str
486
523
  Primary key identifying the export file.
487
524
 
488
- export_type : typing.Optional[str]
489
- Selected export format
525
+ export_type : typing.Optional[ExportFormat]
526
+
527
+ download_resources : typing.Optional[bool]
528
+ If true, download all resource files such as images, audio, and others relevant to the tasks.
490
529
 
491
530
  request_options : typing.Optional[RequestOptions]
492
531
  Request-specific configuration.
493
532
 
494
533
  Returns
495
534
  -------
496
- None
535
+ ExportsConvertResponse
536
+
497
537
 
498
538
  Examples
499
539
  --------
500
- from label_studio_sdk.client import LabelStudio
540
+ from label_studio_sdk import LabelStudio
501
541
 
502
542
  client = LabelStudio(
503
543
  api_key="YOUR_API_KEY",
504
544
  )
505
- client.projects.exports.download(
506
- id=1,
545
+ client.projects.exports.convert(
546
+ project_id=1,
507
547
  export_pk="export_pk",
508
548
  )
509
549
  """
510
550
  _response = self._client_wrapper.httpx_client.request(
511
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/download",
512
- method="GET",
513
- params={"exportType": export_type},
551
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}/convert",
552
+ method="POST",
553
+ json={
554
+ "export_type": export_type,
555
+ "download_resources": download_resources,
556
+ },
557
+ headers={
558
+ "content-type": "application/json",
559
+ },
514
560
  request_options=request_options,
561
+ omit=OMIT,
515
562
  )
516
563
  try:
517
564
  if 200 <= _response.status_code < 300:
518
- return
565
+ return typing.cast(
566
+ ExportsConvertResponse,
567
+ parse_obj_as(
568
+ type_=ExportsConvertResponse, # type: ignore
569
+ object_=_response.json(),
570
+ ),
571
+ )
519
572
  _response_json = _response.json()
520
573
  except JSONDecodeError:
521
574
  raise ApiError(status_code=_response.status_code, body=_response.text)
@@ -526,34 +579,30 @@ class AsyncExportsClient:
526
579
  def __init__(self, *, client_wrapper: AsyncClientWrapper):
527
580
  self._client_wrapper = client_wrapper
528
581
 
529
- async def create_export(
582
+ async def download_sync(
530
583
  self,
531
584
  id: int,
532
585
  *,
533
586
  export_type: typing.Optional[str] = None,
534
- download_all_tasks: typing.Optional[str] = None,
587
+ download_all_tasks: typing.Optional[bool] = None,
535
588
  download_resources: typing.Optional[bool] = None,
536
589
  ids: typing.Optional[typing.Union[int, typing.Sequence[int]]] = None,
537
590
  request_options: typing.Optional[RequestOptions] = None,
538
591
  ) -> typing.AsyncIterator[bytes]:
539
592
  """
593
+
540
594
  <Note>If you have a large project it's recommended to use export snapshots, this easy export endpoint might have timeouts.</Note>
541
595
  Export annotated tasks as a file in a specific format.
542
596
  For example, to export JSON annotations for a project to a file called `annotations.json`,
543
597
  run the following from the command line:
544
-
545
598
  ```bash
546
599
  curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON -H 'Authorization: Token abc123' --output 'annotations.json'
547
600
  ```
548
-
549
601
  To export all tasks, including skipped tasks and others without annotations, run the following from the command line:
550
-
551
602
  ```bash
552
603
  curl -X GET https://localhost:8080/api/projects/{id}/export?exportType=JSON&download_all_tasks=true -H 'Authorization: Token abc123' --output 'annotations.json'
553
604
  ```
554
-
555
605
  To export specific tasks with IDs of 123 and 345, run the following from the command line:
556
-
557
606
  ```bash
558
607
  curl -X GET https://localhost:8080/api/projects/{id}/export?ids[]=123\&ids[]=345 -H 'Authorization: Token abc123' --output 'annotations.json'
559
608
  ```
@@ -568,37 +617,25 @@ class AsyncExportsClient:
568
617
  export_type : typing.Optional[str]
569
618
  Selected export format (JSON by default)
570
619
 
571
- download_all_tasks : typing.Optional[str]
620
+ download_all_tasks : typing.Optional[bool]
621
+
572
622
  If true, download all tasks regardless of status. If false, download only annotated tasks.
573
623
 
574
624
  download_resources : typing.Optional[bool]
625
+
575
626
  If true, download all resource files such as images, audio, and others relevant to the tasks.
576
627
 
577
628
  ids : typing.Optional[typing.Union[int, typing.Sequence[int]]]
629
+
578
630
  Specify a list of task IDs to retrieve only the details for those tasks.
579
631
 
580
632
  request_options : typing.Optional[RequestOptions]
581
- Request-specific configuration.
633
+ Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
582
634
 
583
635
  Yields
584
636
  ------
585
637
  typing.AsyncIterator[bytes]
586
- Exported data
587
-
588
- Examples
589
- --------
590
- from label_studio_sdk.client import AsyncLabelStudio
591
-
592
- client = AsyncLabelStudio(
593
- api_key="YOUR_API_KEY",
594
- )
595
- await client.projects.exports.create_export(
596
- id=1,
597
- export_type="string",
598
- download_all_tasks="string",
599
- download_resources=True,
600
- ids=1,
601
- )
638
+ Exported data in binary format
602
639
  """
603
640
  async with self._client_wrapper.httpx_client.stream(
604
641
  f"api/projects/{jsonable_encoder(id)}/export",
@@ -613,7 +650,8 @@ class AsyncExportsClient:
613
650
  ) as _response:
614
651
  try:
615
652
  if 200 <= _response.status_code < 300:
616
- async for _chunk in _response.aiter_bytes():
653
+ _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
654
+ async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size):
617
655
  yield _chunk
618
656
  return
619
657
  await _response.aread()
@@ -624,8 +662,9 @@ class AsyncExportsClient:
624
662
 
625
663
  async def list_formats(
626
664
  self, id: int, *, request_options: typing.Optional[RequestOptions] = None
627
- ) -> typing.List[str]:
665
+ ) -> typing.List[ExportsListFormatsResponseItem]:
628
666
  """
667
+
629
668
  Before exporting annotations, you can check with formats are supported by the specified project. For more information about export formats, see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
630
669
 
631
670
  You must provide a project ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
@@ -640,40 +679,59 @@ class AsyncExportsClient:
640
679
 
641
680
  Returns
642
681
  -------
643
- typing.List[str]
682
+ typing.List[ExportsListFormatsResponseItem]
644
683
  Export formats
645
684
 
646
685
  Examples
647
686
  --------
648
- from label_studio_sdk.client import AsyncLabelStudio
687
+ import asyncio
688
+
689
+ from label_studio_sdk import AsyncLabelStudio
649
690
 
650
691
  client = AsyncLabelStudio(
651
692
  api_key="YOUR_API_KEY",
652
693
  )
653
- await client.projects.exports.list_formats(
654
- id=1,
655
- )
694
+
695
+
696
+ async def main() -> None:
697
+ await client.projects.exports.list_formats(
698
+ id=1,
699
+ )
700
+
701
+
702
+ asyncio.run(main())
656
703
  """
657
704
  _response = await self._client_wrapper.httpx_client.request(
658
- f"api/projects/{jsonable_encoder(id)}/export/formats", method="GET", request_options=request_options
705
+ f"api/projects/{jsonable_encoder(id)}/export/formats",
706
+ method="GET",
707
+ request_options=request_options,
659
708
  )
660
709
  try:
661
710
  if 200 <= _response.status_code < 300:
662
- return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore
711
+ return typing.cast(
712
+ typing.List[ExportsListFormatsResponseItem],
713
+ parse_obj_as(
714
+ type_=typing.List[ExportsListFormatsResponseItem], # type: ignore
715
+ object_=_response.json(),
716
+ ),
717
+ )
663
718
  _response_json = _response.json()
664
719
  except JSONDecodeError:
665
720
  raise ApiError(status_code=_response.status_code, body=_response.text)
666
721
  raise ApiError(status_code=_response.status_code, body=_response_json)
667
722
 
668
- async def list(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[Export]:
723
+ async def list(
724
+ self, project_id: int, *, request_options: typing.Optional[RequestOptions] = None
725
+ ) -> typing.List[Export]:
669
726
  """
727
+
670
728
  Returns a list of export file (snapshots) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
671
729
 
672
730
  Included in the response is information about each snapshot, such as who created it and what format it is in.
673
731
 
674
732
  Parameters
675
733
  ----------
676
- id : int
734
+ project_id : int
677
735
  A unique integer value identifying this project.
678
736
 
679
737
  request_options : typing.Optional[RequestOptions]
@@ -686,21 +744,37 @@ class AsyncExportsClient:
686
744
 
687
745
  Examples
688
746
  --------
689
- from label_studio_sdk.client import AsyncLabelStudio
747
+ import asyncio
748
+
749
+ from label_studio_sdk import AsyncLabelStudio
690
750
 
691
751
  client = AsyncLabelStudio(
692
752
  api_key="YOUR_API_KEY",
693
753
  )
694
- await client.projects.exports.list(
695
- id=1,
696
- )
754
+
755
+
756
+ async def main() -> None:
757
+ await client.projects.exports.list(
758
+ project_id=1,
759
+ )
760
+
761
+
762
+ asyncio.run(main())
697
763
  """
698
764
  _response = await self._client_wrapper.httpx_client.request(
699
- f"api/projects/{jsonable_encoder(id)}/exports/", method="GET", request_options=request_options
765
+ f"api/projects/{jsonable_encoder(project_id)}/exports",
766
+ method="GET",
767
+ request_options=request_options,
700
768
  )
701
769
  try:
702
770
  if 200 <= _response.status_code < 300:
703
- return pydantic_v1.parse_obj_as(typing.List[Export], _response.json()) # type: ignore
771
+ return typing.cast(
772
+ typing.List[Export],
773
+ parse_obj_as(
774
+ type_=typing.List[Export], # type: ignore
775
+ object_=_response.json(),
776
+ ),
777
+ )
704
778
  _response_json = _response.json()
705
779
  except JSONDecodeError:
706
780
  raise ApiError(status_code=_response.status_code, body=_response.text)
@@ -708,23 +782,24 @@ class AsyncExportsClient:
708
782
 
709
783
  async def create(
710
784
  self,
711
- id_: int,
785
+ project_id: int,
712
786
  *,
713
787
  title: typing.Optional[str] = OMIT,
714
788
  id: typing.Optional[int] = OMIT,
715
789
  created_by: typing.Optional[UserSimple] = OMIT,
716
790
  created_at: typing.Optional[dt.datetime] = OMIT,
717
791
  finished_at: typing.Optional[dt.datetime] = OMIT,
718
- status: typing.Optional[ExportCreateStatus] = OMIT,
792
+ status: typing.Optional[ExportSnapshotStatus] = OMIT,
719
793
  md5: typing.Optional[str] = OMIT,
720
- counters: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
794
+ counters: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
721
795
  converted_formats: typing.Optional[typing.Sequence[ConvertedFormat]] = OMIT,
722
796
  task_filter_options: typing.Optional[TaskFilterOptions] = OMIT,
723
797
  annotation_filter_options: typing.Optional[AnnotationFilterOptions] = OMIT,
724
798
  serialization_options: typing.Optional[SerializationOptions] = OMIT,
725
799
  request_options: typing.Optional[RequestOptions] = None,
726
- ) -> ExportCreate:
800
+ ) -> ExportSnapshot:
727
801
  """
802
+
728
803
  Create a new export request to start a background task and generate an export file (snapshot) for a specific project by ID. The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
729
804
 
730
805
  A snapshot is a static export of your project's data and annotations at a specific point in time. It captures the current state of your tasks, annotations, and other relevant data, allowing you to download and review them later. Snapshots are particularly useful for large projects as they help avoid timeouts during export operations by processing the data asynchronously.
@@ -733,7 +808,7 @@ class AsyncExportsClient:
733
808
 
734
809
  Parameters
735
810
  ----------
736
- id_ : int
811
+ project_id : int
737
812
  A unique integer value identifying this project.
738
813
 
739
814
  title : typing.Optional[str]
@@ -748,11 +823,11 @@ class AsyncExportsClient:
748
823
  finished_at : typing.Optional[dt.datetime]
749
824
  Complete or fail time
750
825
 
751
- status : typing.Optional[ExportCreateStatus]
826
+ status : typing.Optional[ExportSnapshotStatus]
752
827
 
753
828
  md5 : typing.Optional[str]
754
829
 
755
- counters : typing.Optional[typing.Dict[str, typing.Any]]
830
+ counters : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
756
831
 
757
832
  converted_formats : typing.Optional[typing.Sequence[ConvertedFormat]]
758
833
 
@@ -767,106 +842,141 @@ class AsyncExportsClient:
767
842
 
768
843
  Returns
769
844
  -------
770
- ExportCreate
845
+ ExportSnapshot
771
846
 
772
847
 
773
848
  Examples
774
849
  --------
775
- from label_studio_sdk.client import AsyncLabelStudio
850
+ import asyncio
851
+
852
+ from label_studio_sdk import AsyncLabelStudio
776
853
 
777
854
  client = AsyncLabelStudio(
778
855
  api_key="YOUR_API_KEY",
779
856
  )
780
- await client.projects.exports.create(
781
- id_=1,
782
- )
857
+
858
+
859
+ async def main() -> None:
860
+ await client.projects.exports.create(
861
+ project_id=1,
862
+ )
863
+
864
+
865
+ asyncio.run(main())
783
866
  """
784
867
  _response = await self._client_wrapper.httpx_client.request(
785
- f"api/projects/{jsonable_encoder(id_)}/exports/",
868
+ f"api/projects/{jsonable_encoder(project_id)}/exports",
786
869
  method="POST",
787
870
  json={
788
871
  "title": title,
789
872
  "id": id,
790
- "created_by": created_by,
873
+ "created_by": convert_and_respect_annotation_metadata(
874
+ object_=created_by, annotation=UserSimple, direction="write"
875
+ ),
791
876
  "created_at": created_at,
792
877
  "finished_at": finished_at,
793
878
  "status": status,
794
879
  "md5": md5,
795
880
  "counters": counters,
796
- "converted_formats": converted_formats,
797
- "task_filter_options": task_filter_options,
798
- "annotation_filter_options": annotation_filter_options,
799
- "serialization_options": serialization_options,
881
+ "converted_formats": convert_and_respect_annotation_metadata(
882
+ object_=converted_formats, annotation=typing.Sequence[ConvertedFormat], direction="write"
883
+ ),
884
+ "task_filter_options": convert_and_respect_annotation_metadata(
885
+ object_=task_filter_options, annotation=TaskFilterOptions, direction="write"
886
+ ),
887
+ "annotation_filter_options": convert_and_respect_annotation_metadata(
888
+ object_=annotation_filter_options, annotation=AnnotationFilterOptions, direction="write"
889
+ ),
890
+ "serialization_options": convert_and_respect_annotation_metadata(
891
+ object_=serialization_options, annotation=SerializationOptions, direction="write"
892
+ ),
800
893
  },
801
894
  request_options=request_options,
802
895
  omit=OMIT,
803
896
  )
804
897
  try:
805
898
  if 200 <= _response.status_code < 300:
806
- return pydantic_v1.parse_obj_as(ExportCreate, _response.json()) # type: ignore
899
+ return typing.cast(
900
+ ExportSnapshot,
901
+ parse_obj_as(
902
+ type_=ExportSnapshot, # type: ignore
903
+ object_=_response.json(),
904
+ ),
905
+ )
807
906
  _response_json = _response.json()
808
907
  except JSONDecodeError:
809
908
  raise ApiError(status_code=_response.status_code, body=_response.text)
810
909
  raise ApiError(status_code=_response.status_code, body=_response_json)
811
910
 
812
- async def get(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> Export:
911
+ async def download(
912
+ self,
913
+ project_id: int,
914
+ export_pk: str,
915
+ *,
916
+ export_type: typing.Optional[ExportFormat] = None,
917
+ request_options: typing.Optional[RequestOptions] = None,
918
+ ) -> typing.AsyncIterator[bytes]:
813
919
  """
814
- Retrieve information about a specific export file (snapshot).
815
920
 
816
- You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).
921
+ Download an export snapshot as a file in a specified format. To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
817
922
 
818
- You will also need the project ID. This can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
923
+ You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).
924
+
925
+ The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
819
926
 
820
927
  Parameters
821
928
  ----------
822
- id : int
929
+ project_id : int
823
930
  A unique integer value identifying this project.
824
931
 
825
932
  export_pk : str
826
933
  Primary key identifying the export file.
827
934
 
828
- request_options : typing.Optional[RequestOptions]
829
- Request-specific configuration.
830
-
831
- Returns
832
- -------
833
- Export
834
-
935
+ export_type : typing.Optional[ExportFormat]
936
+ Selected export format. JSON is available by default. For other formats, you need to convert the export first.
835
937
 
836
- Examples
837
- --------
838
- from label_studio_sdk.client import AsyncLabelStudio
938
+ request_options : typing.Optional[RequestOptions]
939
+ Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.
839
940
 
840
- client = AsyncLabelStudio(
841
- api_key="YOUR_API_KEY",
842
- )
843
- await client.projects.exports.get(
844
- id=1,
845
- export_pk="export_pk",
846
- )
941
+ Yields
942
+ ------
943
+ typing.AsyncIterator[bytes]
944
+ Exported data in binary format
847
945
  """
848
- _response = await self._client_wrapper.httpx_client.request(
849
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
946
+ async with self._client_wrapper.httpx_client.stream(
947
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}/download",
850
948
  method="GET",
949
+ params={
950
+ "exportType": export_type,
951
+ },
851
952
  request_options=request_options,
852
- )
853
- try:
854
- if 200 <= _response.status_code < 300:
855
- return pydantic_v1.parse_obj_as(Export, _response.json()) # type: ignore
856
- _response_json = _response.json()
857
- except JSONDecodeError:
858
- raise ApiError(status_code=_response.status_code, body=_response.text)
859
- raise ApiError(status_code=_response.status_code, body=_response_json)
953
+ ) as _response:
954
+ try:
955
+ if 200 <= _response.status_code < 300:
956
+ _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None
957
+ async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size):
958
+ yield _chunk
959
+ return
960
+ await _response.aread()
961
+ _response_json = _response.json()
962
+ except JSONDecodeError:
963
+ raise ApiError(status_code=_response.status_code, body=_response.text)
964
+ raise ApiError(status_code=_response.status_code, body=_response_json)
860
965
 
861
- async def delete(self, id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
966
+ async def get(
967
+ self, project_id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None
968
+ ) -> Export:
862
969
  """
863
- Delete an export file by specified export ID.
970
+
971
+ Retrieve information about a specific export file (snapshot).
864
972
 
865
973
  You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).
866
974
 
975
+ You will also need the project ID. This can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
976
+
867
977
  Parameters
868
978
  ----------
869
- id : int
979
+ project_id : int
870
980
  A unique integer value identifying this project.
871
981
 
872
982
  export_pk : str
@@ -877,102 +987,119 @@ class AsyncExportsClient:
877
987
 
878
988
  Returns
879
989
  -------
880
- None
990
+ Export
991
+
881
992
 
882
993
  Examples
883
994
  --------
884
- from label_studio_sdk.client import AsyncLabelStudio
995
+ import asyncio
996
+
997
+ from label_studio_sdk import AsyncLabelStudio
885
998
 
886
999
  client = AsyncLabelStudio(
887
1000
  api_key="YOUR_API_KEY",
888
1001
  )
889
- await client.projects.exports.delete(
890
- id=1,
891
- export_pk="export_pk",
892
- )
1002
+
1003
+
1004
+ async def main() -> None:
1005
+ await client.projects.exports.get(
1006
+ project_id=1,
1007
+ export_pk="export_pk",
1008
+ )
1009
+
1010
+
1011
+ asyncio.run(main())
893
1012
  """
894
1013
  _response = await self._client_wrapper.httpx_client.request(
895
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}",
896
- method="DELETE",
1014
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}",
1015
+ method="GET",
897
1016
  request_options=request_options,
898
1017
  )
899
1018
  try:
900
1019
  if 200 <= _response.status_code < 300:
901
- return
1020
+ return typing.cast(
1021
+ Export,
1022
+ parse_obj_as(
1023
+ type_=Export, # type: ignore
1024
+ object_=_response.json(),
1025
+ ),
1026
+ )
902
1027
  _response_json = _response.json()
903
1028
  except JSONDecodeError:
904
1029
  raise ApiError(status_code=_response.status_code, body=_response.text)
905
1030
  raise ApiError(status_code=_response.status_code, body=_response_json)
906
1031
 
907
- async def convert(
908
- self, id: int, export_pk: str, *, export_type: str, request_options: typing.Optional[RequestOptions] = None
909
- ) -> ExportConvert:
1032
+ async def delete(
1033
+ self, project_id: int, export_pk: str, *, request_options: typing.Optional[RequestOptions] = None
1034
+ ) -> None:
910
1035
  """
911
- You can use this to convert an export snapshot into the selected format.
912
-
913
- To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
914
1036
 
915
- You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).
1037
+ Delete an export file by specified export ID.
916
1038
 
917
- The project ID can be found in the URL when viewing the project in Label Studio, or you can retrieve all project IDs using [List all projects](../list).
1039
+ You will need the export ID. You can find this in the response when you [create the snapshot via the API](create) or using [List all export snapshots](list).
918
1040
 
919
1041
  Parameters
920
1042
  ----------
921
- id : int
1043
+ project_id : int
922
1044
  A unique integer value identifying this project.
923
1045
 
924
1046
  export_pk : str
925
1047
  Primary key identifying the export file.
926
1048
 
927
- export_type : str
928
- Export file format.
929
-
930
1049
  request_options : typing.Optional[RequestOptions]
931
1050
  Request-specific configuration.
932
1051
 
933
1052
  Returns
934
1053
  -------
935
- ExportConvert
936
-
1054
+ None
937
1055
 
938
1056
  Examples
939
1057
  --------
940
- from label_studio_sdk.client import AsyncLabelStudio
1058
+ import asyncio
1059
+
1060
+ from label_studio_sdk import AsyncLabelStudio
941
1061
 
942
1062
  client = AsyncLabelStudio(
943
1063
  api_key="YOUR_API_KEY",
944
1064
  )
945
- await client.projects.exports.convert(
946
- id=1,
947
- export_pk="export_pk",
948
- export_type="export_type",
949
- )
1065
+
1066
+
1067
+ async def main() -> None:
1068
+ await client.projects.exports.delete(
1069
+ project_id=1,
1070
+ export_pk="export_pk",
1071
+ )
1072
+
1073
+
1074
+ asyncio.run(main())
950
1075
  """
951
1076
  _response = await self._client_wrapper.httpx_client.request(
952
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/convert",
953
- method="POST",
954
- json={"export_type": export_type},
1077
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}",
1078
+ method="DELETE",
955
1079
  request_options=request_options,
956
- omit=OMIT,
957
1080
  )
958
1081
  try:
959
1082
  if 200 <= _response.status_code < 300:
960
- return pydantic_v1.parse_obj_as(ExportConvert, _response.json()) # type: ignore
1083
+ return
961
1084
  _response_json = _response.json()
962
1085
  except JSONDecodeError:
963
1086
  raise ApiError(status_code=_response.status_code, body=_response.text)
964
1087
  raise ApiError(status_code=_response.status_code, body=_response_json)
965
1088
 
966
- async def download(
1089
+ async def convert(
967
1090
  self,
968
- id: int,
1091
+ project_id: int,
969
1092
  export_pk: str,
970
1093
  *,
971
- export_type: typing.Optional[str] = None,
1094
+ export_type: typing.Optional[ExportFormat] = OMIT,
1095
+ download_resources: typing.Optional[bool] = OMIT,
972
1096
  request_options: typing.Optional[RequestOptions] = None,
973
- ) -> None:
1097
+ ) -> ExportsConvertResponse:
974
1098
  """
975
- Download an export snapshot as a file in a specified format. To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
1099
+
1100
+ You can use this to convert an export snapshot into the selected format.
1101
+
1102
+ To see what formats are supported, you can use [Get export formats](list-formats) or see [Export formats supported by Label Studio](https://labelstud.io/guide/export#Export-formats-supported-by-Label-Studio).
976
1103
 
977
1104
  You will need to provide the project ID and export ID (`export_pk`). The export ID is returned when you create the export or you can use [List all export snapshots](list).
978
1105
 
@@ -980,43 +1107,67 @@ class AsyncExportsClient:
980
1107
 
981
1108
  Parameters
982
1109
  ----------
983
- id : int
1110
+ project_id : int
984
1111
  A unique integer value identifying this project.
985
1112
 
986
1113
  export_pk : str
987
1114
  Primary key identifying the export file.
988
1115
 
989
- export_type : typing.Optional[str]
990
- Selected export format
1116
+ export_type : typing.Optional[ExportFormat]
1117
+
1118
+ download_resources : typing.Optional[bool]
1119
+ If true, download all resource files such as images, audio, and others relevant to the tasks.
991
1120
 
992
1121
  request_options : typing.Optional[RequestOptions]
993
1122
  Request-specific configuration.
994
1123
 
995
1124
  Returns
996
1125
  -------
997
- None
1126
+ ExportsConvertResponse
1127
+
998
1128
 
999
1129
  Examples
1000
1130
  --------
1001
- from label_studio_sdk.client import AsyncLabelStudio
1131
+ import asyncio
1132
+
1133
+ from label_studio_sdk import AsyncLabelStudio
1002
1134
 
1003
1135
  client = AsyncLabelStudio(
1004
1136
  api_key="YOUR_API_KEY",
1005
1137
  )
1006
- await client.projects.exports.download(
1007
- id=1,
1008
- export_pk="export_pk",
1009
- )
1138
+
1139
+
1140
+ async def main() -> None:
1141
+ await client.projects.exports.convert(
1142
+ project_id=1,
1143
+ export_pk="export_pk",
1144
+ )
1145
+
1146
+
1147
+ asyncio.run(main())
1010
1148
  """
1011
1149
  _response = await self._client_wrapper.httpx_client.request(
1012
- f"api/projects/{jsonable_encoder(id)}/exports/{jsonable_encoder(export_pk)}/download",
1013
- method="GET",
1014
- params={"exportType": export_type},
1150
+ f"api/projects/{jsonable_encoder(project_id)}/exports/{jsonable_encoder(export_pk)}/convert",
1151
+ method="POST",
1152
+ json={
1153
+ "export_type": export_type,
1154
+ "download_resources": download_resources,
1155
+ },
1156
+ headers={
1157
+ "content-type": "application/json",
1158
+ },
1015
1159
  request_options=request_options,
1160
+ omit=OMIT,
1016
1161
  )
1017
1162
  try:
1018
1163
  if 200 <= _response.status_code < 300:
1019
- return
1164
+ return typing.cast(
1165
+ ExportsConvertResponse,
1166
+ parse_obj_as(
1167
+ type_=ExportsConvertResponse, # type: ignore
1168
+ object_=_response.json(),
1169
+ ),
1170
+ )
1020
1171
  _response_json = _response.json()
1021
1172
  except JSONDecodeError:
1022
1173
  raise ApiError(status_code=_response.status_code, body=_response.text)