label-studio-sdk 0.0.34__py3-none-any.whl → 1.0.1__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 (272) hide show
  1. label_studio_sdk/__init__.py +232 -9
  2. label_studio_sdk/_extensions/label_studio_tools/__init__.py +0 -0
  3. label_studio_sdk/_extensions/label_studio_tools/core/__init__.py +0 -0
  4. label_studio_sdk/_extensions/label_studio_tools/core/label_config.py +163 -0
  5. label_studio_sdk/_extensions/label_studio_tools/core/utils/__init__.py +0 -0
  6. label_studio_sdk/_extensions/label_studio_tools/core/utils/exceptions.py +2 -0
  7. label_studio_sdk/_extensions/label_studio_tools/core/utils/io.py +228 -0
  8. label_studio_sdk/_extensions/label_studio_tools/core/utils/params.py +45 -0
  9. label_studio_sdk/_extensions/label_studio_tools/etl/__init__.py +1 -0
  10. label_studio_sdk/_extensions/label_studio_tools/etl/beam.py +34 -0
  11. label_studio_sdk/_extensions/label_studio_tools/etl/example.py +17 -0
  12. label_studio_sdk/_extensions/label_studio_tools/etl/registry.py +67 -0
  13. label_studio_sdk/_extensions/label_studio_tools/postprocessing/__init__.py +0 -0
  14. label_studio_sdk/_extensions/label_studio_tools/postprocessing/video.py +97 -0
  15. label_studio_sdk/_extensions/pager_ext.py +49 -0
  16. label_studio_sdk/_legacy/__init__.py +11 -0
  17. label_studio_sdk/_legacy/client.py +471 -0
  18. label_studio_sdk/_legacy/objects.py +74 -0
  19. label_studio_sdk/{project.py → _legacy/project.py} +2 -2
  20. label_studio_sdk/{schema → _legacy/schema}/label_config_schema.json +14 -14
  21. label_studio_sdk/actions/__init__.py +27 -0
  22. label_studio_sdk/actions/client.py +223 -0
  23. label_studio_sdk/actions/types/__init__.py +25 -0
  24. label_studio_sdk/actions/types/actions_create_request_filters.py +43 -0
  25. label_studio_sdk/actions/types/actions_create_request_filters_conjunction.py +5 -0
  26. label_studio_sdk/actions/types/actions_create_request_filters_items_item.py +49 -0
  27. label_studio_sdk/actions/types/actions_create_request_filters_items_item_filter.py +31 -0
  28. label_studio_sdk/actions/types/actions_create_request_filters_items_item_operator.py +23 -0
  29. label_studio_sdk/actions/types/actions_create_request_id.py +19 -0
  30. label_studio_sdk/actions/types/actions_create_request_ordering_item.py +31 -0
  31. label_studio_sdk/actions/types/actions_create_request_selected_items.py +10 -0
  32. label_studio_sdk/actions/types/actions_create_request_selected_items_excluded.py +39 -0
  33. label_studio_sdk/actions/types/actions_create_request_selected_items_included.py +39 -0
  34. label_studio_sdk/annotations/__init__.py +2 -0
  35. label_studio_sdk/annotations/client.py +750 -0
  36. label_studio_sdk/base_client.py +183 -0
  37. label_studio_sdk/client.py +17 -463
  38. label_studio_sdk/converter/__init__.py +7 -0
  39. label_studio_sdk/converter/audio.py +56 -0
  40. label_studio_sdk/converter/brush.py +452 -0
  41. label_studio_sdk/converter/converter.py +1175 -0
  42. label_studio_sdk/converter/exports/__init__.py +0 -0
  43. label_studio_sdk/converter/exports/csv.py +82 -0
  44. label_studio_sdk/converter/exports/csv2.py +103 -0
  45. label_studio_sdk/converter/funsd.py +85 -0
  46. label_studio_sdk/converter/imports/__init__.py +0 -0
  47. label_studio_sdk/converter/imports/coco.py +314 -0
  48. label_studio_sdk/converter/imports/colors.py +198 -0
  49. label_studio_sdk/converter/imports/label_config.py +45 -0
  50. label_studio_sdk/converter/imports/pathtrack.py +269 -0
  51. label_studio_sdk/converter/imports/yolo.py +236 -0
  52. label_studio_sdk/converter/main.py +202 -0
  53. label_studio_sdk/converter/utils.py +473 -0
  54. label_studio_sdk/core/__init__.py +33 -0
  55. label_studio_sdk/core/api_error.py +15 -0
  56. label_studio_sdk/core/client_wrapper.py +55 -0
  57. label_studio_sdk/core/datetime_utils.py +28 -0
  58. label_studio_sdk/core/file.py +38 -0
  59. label_studio_sdk/core/http_client.py +447 -0
  60. label_studio_sdk/core/jsonable_encoder.py +99 -0
  61. label_studio_sdk/core/pagination.py +87 -0
  62. label_studio_sdk/core/pydantic_utilities.py +28 -0
  63. label_studio_sdk/core/query_encoder.py +33 -0
  64. label_studio_sdk/core/remove_none_from_dict.py +11 -0
  65. label_studio_sdk/core/request_options.py +32 -0
  66. label_studio_sdk/environment.py +7 -0
  67. label_studio_sdk/errors/__init__.py +6 -0
  68. label_studio_sdk/errors/bad_request_error.py +8 -0
  69. label_studio_sdk/errors/internal_server_error.py +8 -0
  70. label_studio_sdk/export_storage/__init__.py +28 -0
  71. label_studio_sdk/export_storage/azure/__init__.py +5 -0
  72. label_studio_sdk/export_storage/azure/client.py +888 -0
  73. label_studio_sdk/export_storage/azure/types/__init__.py +6 -0
  74. label_studio_sdk/export_storage/azure/types/azure_create_response.py +67 -0
  75. label_studio_sdk/export_storage/azure/types/azure_update_response.py +67 -0
  76. label_studio_sdk/export_storage/client.py +107 -0
  77. label_studio_sdk/export_storage/gcs/__init__.py +5 -0
  78. label_studio_sdk/export_storage/gcs/client.py +888 -0
  79. label_studio_sdk/export_storage/gcs/types/__init__.py +6 -0
  80. label_studio_sdk/export_storage/gcs/types/gcs_create_response.py +67 -0
  81. label_studio_sdk/export_storage/gcs/types/gcs_update_response.py +67 -0
  82. label_studio_sdk/export_storage/local/__init__.py +5 -0
  83. label_studio_sdk/export_storage/local/client.py +834 -0
  84. label_studio_sdk/export_storage/local/types/__init__.py +6 -0
  85. label_studio_sdk/export_storage/local/types/local_create_response.py +57 -0
  86. label_studio_sdk/export_storage/local/types/local_update_response.py +57 -0
  87. label_studio_sdk/export_storage/redis/__init__.py +5 -0
  88. label_studio_sdk/export_storage/redis/client.py +918 -0
  89. label_studio_sdk/export_storage/redis/types/__init__.py +6 -0
  90. label_studio_sdk/export_storage/redis/types/redis_create_response.py +72 -0
  91. label_studio_sdk/export_storage/redis/types/redis_update_response.py +72 -0
  92. label_studio_sdk/export_storage/s3/__init__.py +5 -0
  93. label_studio_sdk/export_storage/s3/client.py +1008 -0
  94. label_studio_sdk/export_storage/s3/types/__init__.py +6 -0
  95. label_studio_sdk/export_storage/s3/types/s3create_response.py +89 -0
  96. label_studio_sdk/export_storage/s3/types/s3update_response.py +89 -0
  97. label_studio_sdk/export_storage/types/__init__.py +5 -0
  98. label_studio_sdk/export_storage/types/export_storage_list_types_response_item.py +30 -0
  99. label_studio_sdk/files/__init__.py +2 -0
  100. label_studio_sdk/files/client.py +556 -0
  101. label_studio_sdk/import_storage/__init__.py +28 -0
  102. label_studio_sdk/import_storage/azure/__init__.py +5 -0
  103. label_studio_sdk/import_storage/azure/client.py +988 -0
  104. label_studio_sdk/import_storage/azure/types/__init__.py +6 -0
  105. label_studio_sdk/import_storage/azure/types/azure_create_response.py +82 -0
  106. label_studio_sdk/import_storage/azure/types/azure_update_response.py +82 -0
  107. label_studio_sdk/import_storage/client.py +107 -0
  108. label_studio_sdk/import_storage/gcs/__init__.py +5 -0
  109. label_studio_sdk/import_storage/gcs/client.py +988 -0
  110. label_studio_sdk/import_storage/gcs/types/__init__.py +6 -0
  111. label_studio_sdk/import_storage/gcs/types/gcs_create_response.py +82 -0
  112. label_studio_sdk/import_storage/gcs/types/gcs_update_response.py +82 -0
  113. label_studio_sdk/import_storage/local/__init__.py +5 -0
  114. label_studio_sdk/import_storage/local/client.py +836 -0
  115. label_studio_sdk/import_storage/local/types/__init__.py +6 -0
  116. label_studio_sdk/import_storage/local/types/local_create_response.py +57 -0
  117. label_studio_sdk/import_storage/local/types/local_update_response.py +57 -0
  118. label_studio_sdk/import_storage/redis/__init__.py +5 -0
  119. label_studio_sdk/import_storage/redis/client.py +924 -0
  120. label_studio_sdk/import_storage/redis/types/__init__.py +6 -0
  121. label_studio_sdk/import_storage/redis/types/redis_create_response.py +72 -0
  122. label_studio_sdk/import_storage/redis/types/redis_update_response.py +72 -0
  123. label_studio_sdk/import_storage/s3/__init__.py +5 -0
  124. label_studio_sdk/import_storage/s3/client.py +1138 -0
  125. label_studio_sdk/import_storage/s3/types/__init__.py +6 -0
  126. label_studio_sdk/import_storage/s3/types/s3create_response.py +109 -0
  127. label_studio_sdk/import_storage/s3/types/s3update_response.py +109 -0
  128. label_studio_sdk/import_storage/types/__init__.py +5 -0
  129. label_studio_sdk/import_storage/types/import_storage_list_types_response_item.py +30 -0
  130. label_studio_sdk/label_interface/base.py +10 -0
  131. label_studio_sdk/label_interface/control_tags.py +109 -71
  132. label_studio_sdk/label_interface/data_examples.json +96 -0
  133. label_studio_sdk/label_interface/interface.py +102 -53
  134. label_studio_sdk/label_interface/object_tags.py +8 -13
  135. label_studio_sdk/label_interface/region.py +33 -1
  136. label_studio_sdk/ml/__init__.py +19 -0
  137. label_studio_sdk/ml/client.py +981 -0
  138. label_studio_sdk/ml/types/__init__.py +17 -0
  139. label_studio_sdk/ml/types/ml_create_request_auth_method.py +5 -0
  140. label_studio_sdk/ml/types/ml_create_response.py +78 -0
  141. label_studio_sdk/ml/types/ml_create_response_auth_method.py +5 -0
  142. label_studio_sdk/ml/types/ml_update_request_auth_method.py +5 -0
  143. label_studio_sdk/ml/types/ml_update_response.py +78 -0
  144. label_studio_sdk/ml/types/ml_update_response_auth_method.py +5 -0
  145. label_studio_sdk/predictions/__init__.py +2 -0
  146. label_studio_sdk/predictions/client.py +638 -0
  147. label_studio_sdk/projects/__init__.py +6 -0
  148. label_studio_sdk/projects/client.py +1055 -0
  149. label_studio_sdk/projects/client_ext.py +19 -0
  150. label_studio_sdk/projects/exports/__init__.py +2 -0
  151. label_studio_sdk/projects/exports/client.py +930 -0
  152. label_studio_sdk/projects/types/__init__.py +7 -0
  153. label_studio_sdk/projects/types/projects_create_response.py +96 -0
  154. label_studio_sdk/projects/types/projects_import_tasks_response.py +71 -0
  155. label_studio_sdk/projects/types/projects_list_response.py +33 -0
  156. label_studio_sdk/py.typed +0 -0
  157. label_studio_sdk/tasks/__init__.py +5 -0
  158. label_studio_sdk/tasks/client.py +835 -0
  159. label_studio_sdk/tasks/client_ext.py +18 -0
  160. label_studio_sdk/tasks/types/__init__.py +6 -0
  161. label_studio_sdk/tasks/types/tasks_list_request_fields.py +5 -0
  162. label_studio_sdk/tasks/types/tasks_list_response.py +48 -0
  163. label_studio_sdk/types/__init__.py +115 -0
  164. label_studio_sdk/types/annotation.py +116 -0
  165. label_studio_sdk/types/annotation_filter_options.py +42 -0
  166. label_studio_sdk/types/annotation_last_action.py +19 -0
  167. label_studio_sdk/types/azure_blob_export_storage.py +112 -0
  168. label_studio_sdk/types/azure_blob_export_storage_status.py +7 -0
  169. label_studio_sdk/types/azure_blob_import_storage.py +113 -0
  170. label_studio_sdk/types/azure_blob_import_storage_status.py +7 -0
  171. label_studio_sdk/types/base_task.py +113 -0
  172. label_studio_sdk/types/base_user.py +42 -0
  173. label_studio_sdk/types/converted_format.py +36 -0
  174. label_studio_sdk/types/converted_format_status.py +5 -0
  175. label_studio_sdk/types/export.py +48 -0
  176. label_studio_sdk/types/export_convert.py +32 -0
  177. label_studio_sdk/types/export_create.py +54 -0
  178. label_studio_sdk/types/export_create_status.py +5 -0
  179. label_studio_sdk/types/export_status.py +5 -0
  180. label_studio_sdk/types/file_upload.py +30 -0
  181. label_studio_sdk/types/filter.py +53 -0
  182. label_studio_sdk/types/filter_group.py +35 -0
  183. label_studio_sdk/types/gcs_export_storage.py +112 -0
  184. label_studio_sdk/types/gcs_export_storage_status.py +7 -0
  185. label_studio_sdk/types/gcs_import_storage.py +113 -0
  186. label_studio_sdk/types/gcs_import_storage_status.py +7 -0
  187. label_studio_sdk/types/local_files_export_storage.py +97 -0
  188. label_studio_sdk/types/local_files_export_storage_status.py +7 -0
  189. label_studio_sdk/types/local_files_import_storage.py +92 -0
  190. label_studio_sdk/types/local_files_import_storage_status.py +7 -0
  191. label_studio_sdk/types/ml_backend.py +89 -0
  192. label_studio_sdk/types/ml_backend_auth_method.py +5 -0
  193. label_studio_sdk/types/ml_backend_state.py +5 -0
  194. label_studio_sdk/types/prediction.py +78 -0
  195. label_studio_sdk/types/project.py +198 -0
  196. label_studio_sdk/types/project_import.py +63 -0
  197. label_studio_sdk/types/project_import_status.py +5 -0
  198. label_studio_sdk/types/project_label_config.py +32 -0
  199. label_studio_sdk/types/project_sampling.py +7 -0
  200. label_studio_sdk/types/project_skip_queue.py +5 -0
  201. label_studio_sdk/types/redis_export_storage.py +117 -0
  202. label_studio_sdk/types/redis_export_storage_status.py +7 -0
  203. label_studio_sdk/types/redis_import_storage.py +112 -0
  204. label_studio_sdk/types/redis_import_storage_status.py +7 -0
  205. label_studio_sdk/types/s3export_storage.py +134 -0
  206. label_studio_sdk/types/s3export_storage_status.py +7 -0
  207. label_studio_sdk/types/s3import_storage.py +140 -0
  208. label_studio_sdk/types/s3import_storage_status.py +7 -0
  209. label_studio_sdk/types/serialization_option.py +36 -0
  210. label_studio_sdk/types/serialization_options.py +45 -0
  211. label_studio_sdk/types/task.py +157 -0
  212. label_studio_sdk/types/task_filter_options.py +49 -0
  213. label_studio_sdk/types/user_simple.py +37 -0
  214. label_studio_sdk/types/view.py +55 -0
  215. label_studio_sdk/types/webhook.py +67 -0
  216. label_studio_sdk/types/webhook_actions_item.py +21 -0
  217. label_studio_sdk/types/webhook_serializer_for_update.py +67 -0
  218. label_studio_sdk/types/webhook_serializer_for_update_actions_item.py +21 -0
  219. label_studio_sdk/users/__init__.py +5 -0
  220. label_studio_sdk/users/client.py +830 -0
  221. label_studio_sdk/users/types/__init__.py +6 -0
  222. label_studio_sdk/users/types/users_get_token_response.py +36 -0
  223. label_studio_sdk/users/types/users_reset_token_response.py +36 -0
  224. label_studio_sdk/version.py +4 -0
  225. label_studio_sdk/views/__init__.py +35 -0
  226. label_studio_sdk/views/client.py +564 -0
  227. label_studio_sdk/views/types/__init__.py +33 -0
  228. label_studio_sdk/views/types/views_create_request_data.py +43 -0
  229. label_studio_sdk/views/types/views_create_request_data_filters.py +43 -0
  230. label_studio_sdk/views/types/views_create_request_data_filters_conjunction.py +5 -0
  231. label_studio_sdk/views/types/views_create_request_data_filters_items_item.py +49 -0
  232. label_studio_sdk/views/types/views_create_request_data_filters_items_item_filter.py +31 -0
  233. label_studio_sdk/views/types/views_create_request_data_filters_items_item_operator.py +23 -0
  234. label_studio_sdk/views/types/views_create_request_data_ordering_item.py +31 -0
  235. label_studio_sdk/views/types/views_update_request_data.py +43 -0
  236. label_studio_sdk/views/types/views_update_request_data_filters.py +43 -0
  237. label_studio_sdk/views/types/views_update_request_data_filters_conjunction.py +5 -0
  238. label_studio_sdk/views/types/views_update_request_data_filters_items_item.py +49 -0
  239. label_studio_sdk/views/types/views_update_request_data_filters_items_item_filter.py +31 -0
  240. label_studio_sdk/views/types/views_update_request_data_filters_items_item_operator.py +23 -0
  241. label_studio_sdk/views/types/views_update_request_data_ordering_item.py +31 -0
  242. label_studio_sdk/webhooks/__init__.py +5 -0
  243. label_studio_sdk/webhooks/client.py +636 -0
  244. label_studio_sdk/webhooks/types/__init__.py +5 -0
  245. label_studio_sdk/webhooks/types/webhooks_update_request_actions_item.py +21 -0
  246. label_studio_sdk-1.0.1.dist-info/METADATA +163 -0
  247. label_studio_sdk-1.0.1.dist-info/RECORD +256 -0
  248. {label_studio_sdk-0.0.34.dist-info → label_studio_sdk-1.0.1.dist-info}/WHEEL +1 -2
  249. label_studio_sdk/objects.py +0 -35
  250. label_studio_sdk-0.0.34.dist-info/LICENSE +0 -201
  251. label_studio_sdk-0.0.34.dist-info/METADATA +0 -24
  252. label_studio_sdk-0.0.34.dist-info/RECORD +0 -37
  253. label_studio_sdk-0.0.34.dist-info/top_level.txt +0 -2
  254. tests/test_client.py +0 -37
  255. tests/test_export.py +0 -105
  256. tests/test_interface/__init__.py +0 -1
  257. tests/test_interface/configs.py +0 -137
  258. tests/test_interface/mockups.py +0 -22
  259. tests/test_interface/test_compat.py +0 -64
  260. tests/test_interface/test_control_tags.py +0 -55
  261. tests/test_interface/test_data_generation.py +0 -45
  262. tests/test_interface/test_lpi.py +0 -15
  263. tests/test_interface/test_main.py +0 -196
  264. tests/test_interface/test_object_tags.py +0 -36
  265. tests/test_interface/test_region.py +0 -36
  266. tests/test_interface/test_validate_summary.py +0 -35
  267. tests/test_interface/test_validation.py +0 -59
  268. {tests → label_studio_sdk/_extensions}/__init__.py +0 -0
  269. /label_studio_sdk/{exceptions.py → _legacy/exceptions.py} +0 -0
  270. /label_studio_sdk/{users.py → _legacy/users.py} +0 -0
  271. /label_studio_sdk/{utils.py → _legacy/utils.py} +0 -0
  272. /label_studio_sdk/{workspaces.py → _legacy/workspaces.py} +0 -0
@@ -0,0 +1,183 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import os
4
+ import typing
5
+
6
+ import httpx
7
+
8
+ from .actions.client import ActionsClient, AsyncActionsClient
9
+ from .annotations.client import AnnotationsClient, AsyncAnnotationsClient
10
+ from .core.api_error import ApiError
11
+ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
12
+ from .environment import LabelStudioEnvironment
13
+ from .export_storage.client import AsyncExportStorageClient, ExportStorageClient
14
+ from .files.client import AsyncFilesClient, FilesClient
15
+ from .import_storage.client import AsyncImportStorageClient, ImportStorageClient
16
+ from .ml.client import AsyncMlClient, MlClient
17
+ from .predictions.client import AsyncPredictionsClient, PredictionsClient
18
+ from .projects.client import AsyncProjectsClient, ProjectsClient
19
+ from .tasks.client import AsyncTasksClient, TasksClient
20
+ from .users.client import AsyncUsersClient, UsersClient
21
+ from .views.client import AsyncViewsClient, ViewsClient
22
+ from .webhooks.client import AsyncWebhooksClient, WebhooksClient
23
+
24
+
25
+ class LabelStudioBase:
26
+ """
27
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
28
+
29
+ Parameters
30
+ ----------
31
+ base_url : typing.Optional[str]
32
+ The base url to use for requests from the client.
33
+
34
+ environment : LabelStudioEnvironment
35
+ The environment to use for requests from the client. from .environment import LabelStudioEnvironment
36
+
37
+
38
+
39
+ Defaults to LabelStudioEnvironment.DEFAULT
40
+
41
+
42
+
43
+ api_key : typing.Optional[str]
44
+ timeout : typing.Optional[float]
45
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
46
+
47
+ follow_redirects : typing.Optional[bool]
48
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
49
+
50
+ httpx_client : typing.Optional[httpx.Client]
51
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
52
+
53
+ Examples
54
+ --------
55
+ from label_studio_sdk.client import LabelStudio
56
+
57
+ client = LabelStudio(
58
+ api_key="YOUR_API_KEY",
59
+ )
60
+ """
61
+
62
+ def __init__(
63
+ self,
64
+ *,
65
+ base_url: typing.Optional[str] = None,
66
+ environment: LabelStudioEnvironment = LabelStudioEnvironment.DEFAULT,
67
+ api_key: typing.Optional[str] = os.getenv("LABEL_STUDIO_API_KEY"),
68
+ timeout: typing.Optional[float] = None,
69
+ follow_redirects: typing.Optional[bool] = True,
70
+ httpx_client: typing.Optional[httpx.Client] = None
71
+ ):
72
+ _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
73
+ if api_key is None:
74
+ raise ApiError(
75
+ body="The client must be instantiated be either passing in api_key or setting LABEL_STUDIO_API_KEY"
76
+ )
77
+ self._client_wrapper = SyncClientWrapper(
78
+ base_url=_get_base_url(base_url=base_url, environment=environment),
79
+ api_key=api_key,
80
+ httpx_client=httpx_client
81
+ if httpx_client is not None
82
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
83
+ if follow_redirects is not None
84
+ else httpx.Client(timeout=_defaulted_timeout),
85
+ timeout=_defaulted_timeout,
86
+ )
87
+ self.annotations = AnnotationsClient(client_wrapper=self._client_wrapper)
88
+ self.users = UsersClient(client_wrapper=self._client_wrapper)
89
+ self.actions = ActionsClient(client_wrapper=self._client_wrapper)
90
+ self.views = ViewsClient(client_wrapper=self._client_wrapper)
91
+ self.files = FilesClient(client_wrapper=self._client_wrapper)
92
+ self.projects = ProjectsClient(client_wrapper=self._client_wrapper)
93
+ self.ml = MlClient(client_wrapper=self._client_wrapper)
94
+ self.predictions = PredictionsClient(client_wrapper=self._client_wrapper)
95
+ self.tasks = TasksClient(client_wrapper=self._client_wrapper)
96
+ self.import_storage = ImportStorageClient(client_wrapper=self._client_wrapper)
97
+ self.export_storage = ExportStorageClient(client_wrapper=self._client_wrapper)
98
+ self.webhooks = WebhooksClient(client_wrapper=self._client_wrapper)
99
+
100
+
101
+ class AsyncLabelStudioBase:
102
+ """
103
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
104
+
105
+ Parameters
106
+ ----------
107
+ base_url : typing.Optional[str]
108
+ The base url to use for requests from the client.
109
+
110
+ environment : LabelStudioEnvironment
111
+ The environment to use for requests from the client. from .environment import LabelStudioEnvironment
112
+
113
+
114
+
115
+ Defaults to LabelStudioEnvironment.DEFAULT
116
+
117
+
118
+
119
+ api_key : typing.Optional[str]
120
+ timeout : typing.Optional[float]
121
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
122
+
123
+ follow_redirects : typing.Optional[bool]
124
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
125
+
126
+ httpx_client : typing.Optional[httpx.AsyncClient]
127
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
128
+
129
+ Examples
130
+ --------
131
+ from label_studio_sdk.client import AsyncLabelStudio
132
+
133
+ client = AsyncLabelStudio(
134
+ api_key="YOUR_API_KEY",
135
+ )
136
+ """
137
+
138
+ def __init__(
139
+ self,
140
+ *,
141
+ base_url: typing.Optional[str] = None,
142
+ environment: LabelStudioEnvironment = LabelStudioEnvironment.DEFAULT,
143
+ api_key: typing.Optional[str] = os.getenv("LABEL_STUDIO_API_KEY"),
144
+ timeout: typing.Optional[float] = None,
145
+ follow_redirects: typing.Optional[bool] = True,
146
+ httpx_client: typing.Optional[httpx.AsyncClient] = None
147
+ ):
148
+ _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
149
+ if api_key is None:
150
+ raise ApiError(
151
+ body="The client must be instantiated be either passing in api_key or setting LABEL_STUDIO_API_KEY"
152
+ )
153
+ self._client_wrapper = AsyncClientWrapper(
154
+ base_url=_get_base_url(base_url=base_url, environment=environment),
155
+ api_key=api_key,
156
+ httpx_client=httpx_client
157
+ if httpx_client is not None
158
+ else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
159
+ if follow_redirects is not None
160
+ else httpx.AsyncClient(timeout=_defaulted_timeout),
161
+ timeout=_defaulted_timeout,
162
+ )
163
+ self.annotations = AsyncAnnotationsClient(client_wrapper=self._client_wrapper)
164
+ self.users = AsyncUsersClient(client_wrapper=self._client_wrapper)
165
+ self.actions = AsyncActionsClient(client_wrapper=self._client_wrapper)
166
+ self.views = AsyncViewsClient(client_wrapper=self._client_wrapper)
167
+ self.files = AsyncFilesClient(client_wrapper=self._client_wrapper)
168
+ self.projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
169
+ self.ml = AsyncMlClient(client_wrapper=self._client_wrapper)
170
+ self.predictions = AsyncPredictionsClient(client_wrapper=self._client_wrapper)
171
+ self.tasks = AsyncTasksClient(client_wrapper=self._client_wrapper)
172
+ self.import_storage = AsyncImportStorageClient(client_wrapper=self._client_wrapper)
173
+ self.export_storage = AsyncExportStorageClient(client_wrapper=self._client_wrapper)
174
+ self.webhooks = AsyncWebhooksClient(client_wrapper=self._client_wrapper)
175
+
176
+
177
+ def _get_base_url(*, base_url: typing.Optional[str] = None, environment: LabelStudioEnvironment) -> str:
178
+ if base_url is not None:
179
+ return base_url
180
+ elif environment is not None:
181
+ return environment.value
182
+ else:
183
+ raise Exception("Please pass in either base_url or environment to construct the client")
@@ -1,471 +1,25 @@
1
- """ .. include::../docs/client.md
2
- """
1
+ from .base_client import LabelStudioBase, AsyncLabelStudioBase
2
+ from .tasks.client_ext import TasksClientExt, AsyncTasksClientExt
3
+ from .projects.client_ext import ProjectsClientExt, AsyncProjectsClientExt
3
4
 
4
- import json
5
- import logging
6
- import os
7
5
 
8
- import requests
6
+ class LabelStudio(LabelStudioBase):
7
+ """"""
8
+ __doc__ += LabelStudioBase.__doc__
9
9
 
10
- from typing import Optional
11
- from pydantic import BaseModel, constr, root_validator
12
- from requests.adapters import HTTPAdapter
10
+ def __init__(self, *args, **kwargs):
11
+ super().__init__(*args, **kwargs)
13
12
 
14
- logger = logging.getLogger(__name__)
13
+ self.tasks = TasksClientExt(client_wrapper=self._client_wrapper)
14
+ self.projects = ProjectsClientExt(client_wrapper=self._client_wrapper)
15
15
 
16
- MAX_RETRIES = 3
17
- TIMEOUT = (10.0, int(os.environ.get('TIMEOUT', 180)))
18
- HEADERS = {}
19
- LABEL_STUDIO_DEFAULT_URL = "http://localhost:8080"
20
16
 
17
+ class AsyncLabelStudio(AsyncLabelStudioBase):
18
+ """"""
19
+ __doc__ += AsyncLabelStudioBase.__doc__
21
20
 
22
- class ClientCredentials(BaseModel):
23
- email: Optional[str] = None
24
- password: Optional[str] = None
25
- api_key: Optional[constr()] = None
21
+ def __init__(self, *args, **kwargs):
22
+ super().__init__(*args, **kwargs)
26
23
 
27
- @root_validator(pre=True, allow_reuse=True)
28
- def either_key_or_email_password(cls, values):
29
- assert (
30
- "email" in values or "api_key" in values
31
- ), "At least one of email or api_key should be included"
32
- assert (
33
- "email" not in values or "password" in values
34
- ), "Provide both email and password for login auth"
35
- return values
36
-
37
-
38
- class Client(object):
39
- def __init__(
40
- self,
41
- url: str = None,
42
- api_key: str = None,
43
- credentials=None,
44
- session=None,
45
- extra_headers: dict = None,
46
- cookies: dict = None,
47
- oidc_token=None,
48
- versions=None,
49
- make_request_raise=True,
50
- ):
51
- """Initialize the client. Do this before using other Label Studio SDK classes and methods in your script.
52
-
53
- Parameters
54
- ----------
55
- url: str
56
- Label Studio host address.
57
- Example: http://localhost:8080
58
- api_key: str
59
- User token for the API. You can find this on your user account page in Label Studio.
60
- credentials: ClientCredentials
61
- User email and password or api_key.
62
- session: requests.Session()
63
- If None, a new one is created.
64
- extra_headers: dict
65
- Additional headers that will be passed to each http request
66
- cookies: dict
67
- Cookies that will be passed to each http request.
68
- oidc_token: str
69
- Bearer token for proxy authentication - in case the server is behind an authenticating proxy.
70
- versions: dict
71
- Versions of Label Studio components for the connected instance
72
- make_request_raise: bool
73
- If true, make_request will raise exceptions on request errors
74
- """
75
- if not url:
76
- url = os.getenv("LABEL_STUDIO_URL", LABEL_STUDIO_DEFAULT_URL)
77
- self.url = url.rstrip("/")
78
- self.make_request_raise = make_request_raise
79
- self.session = session or self.get_session()
80
-
81
- # set cookies
82
- self.cookies = cookies
83
-
84
- # set api key or get it using credentials (username and password)
85
- if api_key is None and credentials is None:
86
- api_key = os.getenv("LABEL_STUDIO_API_KEY")
87
-
88
- if api_key is not None:
89
- credentials = ClientCredentials(api_key=api_key)
90
-
91
- if api_key is None and credentials is None:
92
- raise RuntimeError(
93
- "If neither 'api_key' nor 'credentials' are provided, 'LABEL_STUDIO_API_KEY' environment variable must "
94
- "be set"
95
- )
96
-
97
- self.api_key = (
98
- credentials.api_key
99
- if credentials.api_key
100
- else self.get_api_key(credentials)
101
- )
102
-
103
- # set headers
104
- self.headers = {"Authorization": f"Token {self.api_key}"}
105
- if oidc_token:
106
- self.headers.update({"Proxy-Authorization": f"Bearer {oidc_token}"})
107
- if extra_headers:
108
- self.headers.update(extra_headers)
109
-
110
- # set versions from /version endpoint
111
- self.versions = versions if versions else self.get_versions()
112
- self.is_enterprise = "label-studio-enterprise-backend" in self.versions
113
-
114
- def get_versions(self):
115
- """Call /version api and get all Label Studio component versions
116
-
117
- Returns
118
- -------
119
- dict with Label Studio component names and their versions
120
-
121
- """
122
- self.versions = self.make_request("GET", "/api/version").json()
123
- return self.versions
124
-
125
- def get_api_key(self, credentials: ClientCredentials):
126
- login_url = self.get_url("/user/login")
127
- # Retrieve and set the CSRF token first
128
- self.session.get(login_url)
129
- csrf_token = self.session.cookies.get("csrftoken", None)
130
- login_data = dict(**credentials.dict(), csrfmiddlewaretoken=csrf_token)
131
- self.session.post(
132
- login_url,
133
- data=login_data,
134
- headers=dict(Referer=self.url),
135
- cookies=self.cookies,
136
- ).raise_for_status()
137
- api_key = (
138
- self.session.get(self.get_url("/api/current-user/token"))
139
- .json()
140
- .get("token")
141
- )
142
- return api_key
143
-
144
- def check_connection(self):
145
- """Call Label Studio /health endpoint to check the connection to the server.
146
-
147
- Returns
148
- -------
149
- dict
150
- Status string like "UP"
151
- """
152
- response = self.make_request("GET", "/health")
153
- return response.json()
154
-
155
- def get_projects(self, **query_params):
156
- """List all projects in Label Studio.
157
-
158
- Returns
159
- -------
160
- list or `label_studio_sdk.project.Project` instances
161
-
162
- """
163
- return self.list_projects(**query_params)
164
-
165
- def delete_project(self, project_id: int):
166
- """Delete a project in Label Studio.
167
-
168
- Returns
169
- -------
170
- dict
171
- Status string
172
- """
173
- response = self.make_request("DELETE", f"/api/projects/{project_id}/")
174
- return response
175
-
176
- def delete_all_projects(self):
177
- """Deletes all projects in Label Studio.
178
-
179
- Returns
180
- -------
181
- List
182
- List of (dict) status strings
183
- """
184
- responses = []
185
- project_ids = [project.get_params()["id"] for project in self.list_projects()]
186
- for project_id in project_ids:
187
- response = self.delete_project(project_id)
188
- responses.append(response)
189
- return responses
190
-
191
- def list_projects(self, **query_params):
192
- """List all projects in Label Studio.
193
-
194
- Returns
195
- -------
196
- list or `label_studio_sdk.project.Project` instances
197
-
198
- """
199
- from .project import Project
200
-
201
- params = {"page_size": 10000000}
202
- params.update(query_params)
203
- response = self.make_request("GET", "/api/projects", params=params)
204
- if response.status_code == 200:
205
- projects = []
206
- for data in response.json()["results"]:
207
- project = Project._create_from_id(
208
- client=self, project_id=data["id"], params=data
209
- )
210
- projects.append(project)
211
- logger.debug(
212
- f'Project {project.id} "{project.get_params().get("title")}" is retrieved'
213
- )
214
- return projects
215
-
216
- def create_project(self, **kwargs):
217
- return self.start_project(**kwargs)
218
-
219
- def start_project(self, **kwargs):
220
- """Create a new project instance.
221
-
222
- Parameters
223
- ----------
224
- kwargs:
225
- Parameters for `project.start_project(**kwargs)`
226
-
227
- Returns
228
- -------
229
- `label_studio_sdk.project.Project`
230
-
231
- """
232
- from .project import Project
233
-
234
- project = Project(
235
- url=self.url,
236
- api_key=self.api_key,
237
- session=self.session,
238
- versions=self.versions,
239
- )
240
- project.start_project(**kwargs)
241
- return project
242
-
243
- def get_project(self, id):
244
- """Return project SDK object by ID existed in Label Studio
245
-
246
- Parameters
247
- ----------
248
- id: int
249
- Project ID for the project you want to retrieve.
250
-
251
- Returns
252
- -------
253
- `label_studio_sdk.project.Project`
254
-
255
- """
256
- from .project import Project
257
-
258
- return Project.get_from_id(self, id)
259
-
260
- def get_users(self):
261
- """Return all users from the current organization account
262
-
263
- Parameters
264
- ----------
265
-
266
- Returns
267
- -------
268
- list of `label_studio_sdk.users.User`
269
-
270
- """
271
- from .users import User
272
-
273
- response = self.make_request("GET", "/api/users")
274
- users = []
275
- for user_data in response.json():
276
- user_data["client"] = self
277
- users.append(User(**user_data))
278
- return users
279
-
280
- def create_user(self, user, exist_ok=True):
281
- """Create a new user
282
-
283
- Parameters
284
- ----------
285
- user: User or dict
286
- User instance, you can initialize it this way:
287
- User(username='x', email='x@x.xx', first_name='X', last_name='Z')
288
- exist_ok: bool
289
- True by default, it won't print error if user exists and exist_ok=True
290
-
291
- Returns
292
- -------
293
- `label_studio_sdk.users.User`
294
- Created user
295
-
296
- """
297
- from .users import User
298
-
299
- payload = (
300
- {
301
- "username": user.username if user.username else user.email,
302
- "email": user.email,
303
- "first_name": user.first_name,
304
- "last_name": user.last_name,
305
- "phone": user.phone,
306
- }
307
- if isinstance(user, User)
308
- else user
309
- )
310
-
311
- response = self.make_request(
312
- "POST", "/api/users", json=payload, raise_exceptions=False
313
- )
314
- user_data = response.json()
315
- user_data["client"] = self
316
-
317
- if response.status_code < 400:
318
- return User(**user_data)
319
- else:
320
- if "already exists" in response.text and exist_ok is True:
321
- return None
322
- logger.error("Create user error: " + str(response.json()))
323
- return None
324
-
325
- def get_workspaces(self):
326
- """Return all workspaces from the current organization account
327
-
328
- Parameters
329
- ----------
330
-
331
- Returns
332
- -------
333
- list of `label_studio_sdk.workspaces.Workspace`
334
-
335
- """
336
- from .workspaces import Workspace
337
-
338
- assert (
339
- self.is_enterprise
340
- ), "Workspaces are available only for Enterprise instance of Label Studio"
341
-
342
- response = self.make_request("GET", "/api/workspaces")
343
- workspaces = []
344
- for workspace_data in response.json():
345
- workspace_data["client"] = self
346
- workspaces.append(Workspace(**workspace_data))
347
- return workspaces
348
-
349
- # write function get_workspace_by_title
350
- def get_workspace_by_title(self, title):
351
- """Return workspace by title from the current organization account
352
-
353
- Parameters
354
- ----------
355
- title: str
356
- Workspace title
357
-
358
- Returns
359
- -------
360
- `label_studio_sdk.workspaces.Workspace` or None
361
-
362
- """
363
- workspaces = self.get_workspaces()
364
- for workspace in workspaces:
365
- if workspace.title == title:
366
- return workspace
367
- return None
368
-
369
- def get_organization(self):
370
- """Return active organization for the current user
371
-
372
- Returns
373
- -------
374
- dict
375
- """
376
- # get organization id from the current user api
377
- response = self.make_request('GET', '/api/current-user/whoami').json()
378
- organization_id = response['active_organization']
379
-
380
- # get organization data by id
381
- response = self.make_request("GET", f"/api/organizations/{organization_id}")
382
- return response.json()
383
-
384
- def get_session(self):
385
- """Create a session with requests.Session()
386
-
387
- Returns
388
- -------
389
- request.Session
390
-
391
- """
392
- session = requests.Session()
393
- session.headers.update(HEADERS)
394
- session.mount("http://", HTTPAdapter(max_retries=MAX_RETRIES))
395
- session.mount("https://", HTTPAdapter(max_retries=MAX_RETRIES))
396
- return session
397
-
398
- def get_url(self, suffix):
399
- """Get the URL of the Label Studio server
400
-
401
- Returns
402
- -------
403
- String with the URL
404
-
405
- """
406
- return f'{self.url}/{suffix.lstrip("/")}'
407
-
408
- def make_request(self, method, url, *args, **kwargs):
409
- """Make a request with an API key to Label Studio instance
410
-
411
- Parameters
412
- ----------
413
- method: str
414
- HTTP method like POST, PATCH, GET, DELETE.
415
- url: str
416
- URL of the API endpoint that you want to make a request to.
417
-
418
- args
419
- session.request(*args)
420
- kwargs
421
- session.request(*kwargs)
422
-
423
- Returns
424
- -------
425
- Response object for the relevant endpoint.
426
-
427
- """
428
- if "timeout" not in kwargs:
429
- kwargs["timeout"] = TIMEOUT
430
-
431
- raise_exceptions = self.make_request_raise
432
- if "raise_exceptions" in kwargs: # kwargs have higher priority
433
- raise_exceptions = kwargs.pop("raise_exceptions")
434
-
435
- logger.debug(f"{method}: {url} with args={args}, kwargs={kwargs}")
436
- response = self.session.request(
437
- method,
438
- self.get_url(url),
439
- headers=self.headers,
440
- cookies=self.cookies,
441
- *args,
442
- **kwargs,
443
- )
444
-
445
- if raise_exceptions:
446
- if response.status_code >= 400:
447
- self.log_response_error(response)
448
- response.raise_for_status()
449
-
450
- return response
451
-
452
- def log_response_error(self, response):
453
- try:
454
- content = json.dumps(json.loads(response.content), indent=2)
455
- except:
456
- content = response.text
457
-
458
- logger.error(
459
- f"\n--------------------------------------------\n"
460
- f"Request URL: {response.url}\n"
461
- f"Response status code: {response.status_code}\n"
462
- f"Response content:\n{content}\n\n"
463
- f"SDK error traceback:"
464
- )
465
-
466
- def sync_storage(self, storage_type, storage_id):
467
- """See project.sync_storage for more info"""
468
- response = self.make_request(
469
- "POST", f"/api/storages/{storage_type}/{str(storage_id)}/sync"
470
- )
471
- return response.json()
24
+ self.tasks = AsyncTasksClientExt(client_wrapper=self._client_wrapper)
25
+ self.projects = AsyncProjectsClientExt(client_wrapper=self._client_wrapper)
@@ -0,0 +1,7 @@
1
+ # try is used here to import this file in setup.py and don't break the setup process
2
+ try:
3
+ from .converter import Converter
4
+ except ModuleNotFoundError as e:
5
+ print(e)
6
+
7
+ __version__ = "0.0.59.dev"