supervisely 6.73.217__py3-none-any.whl → 6.73.219__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 supervisely might be problematic. Click here for more details.
- supervisely/api/api.py +29 -16
- supervisely/api/image_api.py +88 -5
- {supervisely-6.73.217.dist-info → supervisely-6.73.219.dist-info}/METADATA +1 -1
- {supervisely-6.73.217.dist-info → supervisely-6.73.219.dist-info}/RECORD +8 -8
- {supervisely-6.73.217.dist-info → supervisely-6.73.219.dist-info}/WHEEL +1 -1
- {supervisely-6.73.217.dist-info → supervisely-6.73.219.dist-info}/LICENSE +0 -0
- {supervisely-6.73.217.dist-info → supervisely-6.73.219.dist-info}/entry_points.txt +0 -0
- {supervisely-6.73.217.dist-info → supervisely-6.73.219.dist-info}/top_level.txt +0 -0
supervisely/api/api.py
CHANGED
|
@@ -287,6 +287,8 @@ class Api:
|
|
|
287
287
|
api_server_address: str = None,
|
|
288
288
|
check_instance_version: Union[bool, str] = False,
|
|
289
289
|
):
|
|
290
|
+
self.logger = external_logger or logger
|
|
291
|
+
|
|
290
292
|
if server_address is None and token is None:
|
|
291
293
|
server_address = os.environ.get(SERVER_ADDRESS, None)
|
|
292
294
|
token = os.environ.get(API_TOKEN, None)
|
|
@@ -295,10 +297,7 @@ class Api:
|
|
|
295
297
|
raise ValueError(
|
|
296
298
|
"SERVER_ADDRESS env variable is undefined, https://developer.supervisely.com/getting-started/basics-of-authentication"
|
|
297
299
|
)
|
|
298
|
-
|
|
299
|
-
raise ValueError(
|
|
300
|
-
"API_TOKEN env variable is undefined, https://developer.supervisely.com/getting-started/basics-of-authentication"
|
|
301
|
-
)
|
|
300
|
+
|
|
302
301
|
self.server_address = Api.normalize_server_address(server_address)
|
|
303
302
|
|
|
304
303
|
self._api_server_address = None
|
|
@@ -313,11 +312,10 @@ class Api:
|
|
|
313
312
|
if retry_sleep_sec is None:
|
|
314
313
|
retry_sleep_sec = int(os.getenv(SUPERVISELY_PUBLIC_API_RETRY_SLEEP_SEC, "1"))
|
|
315
314
|
|
|
316
|
-
if len(token) != 128:
|
|
317
|
-
raise ValueError("Invalid token {!r}: length != 128".format(token))
|
|
318
|
-
|
|
319
315
|
self.token = token
|
|
320
|
-
self.headers = {
|
|
316
|
+
self.headers = {}
|
|
317
|
+
if token is not None:
|
|
318
|
+
self.headers["x-api-key"] = token
|
|
321
319
|
self.task_id = os.getenv(SUPERVISELY_TASK_ID)
|
|
322
320
|
if self.task_id is not None and ignore_task_id is False:
|
|
323
321
|
self.headers["x-task-id"] = self.task_id
|
|
@@ -359,8 +357,6 @@ class Api:
|
|
|
359
357
|
self.retry_count = retry_count
|
|
360
358
|
self.retry_sleep_sec = retry_sleep_sec
|
|
361
359
|
|
|
362
|
-
self.logger = external_logger or logger
|
|
363
|
-
|
|
364
360
|
self._require_https_redirect_check = not self.server_address.startswith("https://")
|
|
365
361
|
|
|
366
362
|
if check_instance_version:
|
|
@@ -652,6 +648,14 @@ class Api:
|
|
|
652
648
|
Api._raise_for_status(response)
|
|
653
649
|
return response
|
|
654
650
|
except requests.RequestException as exc:
|
|
651
|
+
if (
|
|
652
|
+
isinstance(exc, requests.exceptions.HTTPError)
|
|
653
|
+
and response.status_code == 400
|
|
654
|
+
and self.token is None
|
|
655
|
+
):
|
|
656
|
+
self.logger.warning(
|
|
657
|
+
"API_TOKEN env variable is undefined. See more: https://developer.supervisely.com/getting-started/basics-of-authentication"
|
|
658
|
+
)
|
|
655
659
|
if raise_error:
|
|
656
660
|
raise exc
|
|
657
661
|
else:
|
|
@@ -715,6 +719,14 @@ class Api:
|
|
|
715
719
|
Api._raise_for_status(response)
|
|
716
720
|
return response
|
|
717
721
|
except requests.RequestException as exc:
|
|
722
|
+
if (
|
|
723
|
+
isinstance(exc, requests.exceptions.HTTPError)
|
|
724
|
+
and response.status_code == 400
|
|
725
|
+
and self.token is None
|
|
726
|
+
):
|
|
727
|
+
self.logger.warning(
|
|
728
|
+
"API_TOKEN env variable is undefined. See more: https://developer.supervisely.com/getting-started/basics-of-authentication"
|
|
729
|
+
)
|
|
718
730
|
process_requests_exception(
|
|
719
731
|
self.logger,
|
|
720
732
|
exc,
|
|
@@ -807,10 +819,11 @@ class Api:
|
|
|
807
819
|
|
|
808
820
|
def _check_https_redirect(self):
|
|
809
821
|
if self._require_https_redirect_check is True:
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
822
|
+
try:
|
|
823
|
+
response = requests.get(
|
|
824
|
+
self.server_address.replace("http://", "https://"), allow_redirects=False
|
|
825
|
+
)
|
|
826
|
+
response.raise_for_status()
|
|
814
827
|
self.server_address = self.server_address.replace("http://", "https://")
|
|
815
828
|
msg = (
|
|
816
829
|
"You're using HTTP server address while the server requires HTTPS. "
|
|
@@ -818,8 +831,8 @@ class Api:
|
|
|
818
831
|
f"Consider updating your server address to {self.server_address}"
|
|
819
832
|
)
|
|
820
833
|
self.logger.warn(msg)
|
|
821
|
-
|
|
822
|
-
|
|
834
|
+
finally:
|
|
835
|
+
self._require_https_redirect_check = False
|
|
823
836
|
|
|
824
837
|
@classmethod
|
|
825
838
|
def from_credentials(
|
supervisely/api/image_api.py
CHANGED
|
@@ -2629,7 +2629,7 @@ class ImageApi(RemoveableBulkModuleApi):
|
|
|
2629
2629
|
"""
|
|
2630
2630
|
return resize_image_url(url, ext, method, width, height, quality)
|
|
2631
2631
|
|
|
2632
|
-
def update_meta(self, id: int, meta: Dict) -> Dict:
|
|
2632
|
+
def update_meta(self, id: int, meta: Dict) -> Dict[str, Any]:
|
|
2633
2633
|
"""
|
|
2634
2634
|
It is possible to add custom JSON data to every image for storing some additional information.
|
|
2635
2635
|
Updates Image metadata by ID. Metadata is visible in Labeling Tool.
|
|
@@ -2669,10 +2669,93 @@ class ImageApi(RemoveableBulkModuleApi):
|
|
|
2669
2669
|
# "Focal Length": "16 mm"
|
|
2670
2670
|
# }
|
|
2671
2671
|
"""
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2672
|
+
return self.edit(id=id, meta=meta, return_json=True)
|
|
2673
|
+
|
|
2674
|
+
def edit(
|
|
2675
|
+
self,
|
|
2676
|
+
id: int,
|
|
2677
|
+
name: Optional[str] = None,
|
|
2678
|
+
description: Optional[str] = None,
|
|
2679
|
+
meta: Optional[Dict] = None,
|
|
2680
|
+
return_json: bool = False,
|
|
2681
|
+
) -> Union[ImageInfo, Dict[str, Any]]:
|
|
2682
|
+
"""Updates the information about the image by given ID with provided parameters.
|
|
2683
|
+
At least one parameter must be set, otherwise ValueError will be raised.
|
|
2684
|
+
|
|
2685
|
+
:param id: Image ID in Supervisely.
|
|
2686
|
+
:type id: int
|
|
2687
|
+
:param name: New Image name.
|
|
2688
|
+
:type name: str, optional
|
|
2689
|
+
:param description: New Image description.
|
|
2690
|
+
:type description: str, optional
|
|
2691
|
+
:param meta: New Image metadata.
|
|
2692
|
+
:type meta: dict, optional
|
|
2693
|
+
:return_json: If True, return response in JSON format, otherwise convert it ImageInfo object.
|
|
2694
|
+
This parameter is only added for backward compatibility for update_meta method.
|
|
2695
|
+
It's not recommended to use it in new code.
|
|
2696
|
+
:type return_json: bool, optional
|
|
2697
|
+
:raises: :class:`ValueError` if at least one parameter is not set
|
|
2698
|
+
:raises: :class:`ValueError if meta parameter was set and it is not a dictionary
|
|
2699
|
+
:return: Information about updated image as ImageInfo object or as dict if return_json is True
|
|
2700
|
+
:rtype: :class:`ImageInfo` or :class:`dict`
|
|
2701
|
+
|
|
2702
|
+
:Usage example:
|
|
2703
|
+
|
|
2704
|
+
.. code-block:: python
|
|
2705
|
+
|
|
2706
|
+
import supervisely as sly
|
|
2707
|
+
|
|
2708
|
+
api = sly.Api.from_env()
|
|
2709
|
+
|
|
2710
|
+
image_id = 123456
|
|
2711
|
+
new_image_name = "IMG_3333_new.jpg"
|
|
2712
|
+
|
|
2713
|
+
api.image.edit(id=image_id, name=new_image_name)
|
|
2714
|
+
"""
|
|
2715
|
+
if name is None and description is None and meta is None:
|
|
2716
|
+
raise ValueError("At least one parameter must be set")
|
|
2717
|
+
|
|
2718
|
+
if meta is not None and not isinstance(meta, dict):
|
|
2719
|
+
raise ValueError("meta parameter must be a dictionary")
|
|
2720
|
+
|
|
2721
|
+
data = {
|
|
2722
|
+
ApiField.ID: id,
|
|
2723
|
+
ApiField.NAME: name,
|
|
2724
|
+
ApiField.DESCRIPTION: description,
|
|
2725
|
+
ApiField.META: meta,
|
|
2726
|
+
}
|
|
2727
|
+
data = {k: v for k, v in data.items() if v is not None}
|
|
2728
|
+
|
|
2729
|
+
response = self._api.post("images.editInfo", data)
|
|
2730
|
+
if return_json:
|
|
2731
|
+
return response.json()
|
|
2732
|
+
return self._convert_json_info(response.json(), skip_missing=True)
|
|
2733
|
+
|
|
2734
|
+
def rename(self, id: int, name: str) -> ImageInfo:
|
|
2735
|
+
"""
|
|
2736
|
+
Renames Image with given ID.
|
|
2737
|
+
|
|
2738
|
+
:param id: Image ID in Supervisely.
|
|
2739
|
+
:type id: int
|
|
2740
|
+
:param name: New Image name.
|
|
2741
|
+
:type name: str
|
|
2742
|
+
:return: Information about updated Image.
|
|
2743
|
+
:rtype: :class:`ImageInfo`
|
|
2744
|
+
:Usage example:
|
|
2745
|
+
|
|
2746
|
+
.. code-block:: python
|
|
2747
|
+
|
|
2748
|
+
import supervisely as sly
|
|
2749
|
+
|
|
2750
|
+
os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
|
|
2751
|
+
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
|
|
2752
|
+
api = sly.Api.from_env()
|
|
2753
|
+
|
|
2754
|
+
image_id = 376729
|
|
2755
|
+
new_image_name = 'new_image_name.jpg'
|
|
2756
|
+
img_info = api.image.rename(image_id, new_image_name)
|
|
2757
|
+
"""
|
|
2758
|
+
return self.edit(id=id, name=name)
|
|
2676
2759
|
|
|
2677
2760
|
def add_tag(self, image_id: int, tag_id: int, value: Optional[Union[str, int]] = None) -> None:
|
|
2678
2761
|
"""
|
|
@@ -22,13 +22,13 @@ supervisely/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
22
22
|
supervisely/api/advanced_api.py,sha256=Nd5cCnHFWc3PSUrCtENxTGtDjS37_lCHXsgXvUI3Ti8,2054
|
|
23
23
|
supervisely/api/agent_api.py,sha256=ShWAIlXcWXcyI9fqVuP5GZVCigCMJmjnvdGUfLspD6Y,8890
|
|
24
24
|
supervisely/api/annotation_api.py,sha256=Eps-Jf10_SQFy7DjghUnyiM6DcVJBsamHDViRAXv2fg,51403
|
|
25
|
-
supervisely/api/api.py,sha256=
|
|
25
|
+
supervisely/api/api.py,sha256=iq5wS7j95dfktZwubT2J9rBBMl-GHy75PkOQtZcwl24,37099
|
|
26
26
|
supervisely/api/app_api.py,sha256=zX3Iy16RuGwtcLZfMs3YfUFc93S9AVGb3W_eINeMjOs,66729
|
|
27
27
|
supervisely/api/dataset_api.py,sha256=7iwAyz3pmzFG2i072gLdXjczfBGbyj-V_rRl7Tx-V30,37944
|
|
28
28
|
supervisely/api/file_api.py,sha256=y8FkE-vx1382cbhNo_rTZs7SobrkxmYQAe79CpvStO4,54279
|
|
29
29
|
supervisely/api/github_api.py,sha256=NIexNjEer9H5rf5sw2LEZd7C1WR-tK4t6IZzsgeAAwQ,623
|
|
30
30
|
supervisely/api/image_annotation_tool_api.py,sha256=YcUo78jRDBJYvIjrd-Y6FJAasLta54nnxhyaGyanovA,5237
|
|
31
|
-
supervisely/api/image_api.py,sha256=
|
|
31
|
+
supervisely/api/image_api.py,sha256=wnzoCbD5vV8f8joBQsNCbRjoG0jhyAXHe1ZM8YhbCsc,138727
|
|
32
32
|
supervisely/api/import_storage_api.py,sha256=BDCgmR0Hv6OoiRHLCVPKt3iDxSVlQp1WrnKhAK_Zl84,460
|
|
33
33
|
supervisely/api/issues_api.py,sha256=BqDJXmNoTzwc3xe6_-mA7FDFC5QQ-ahGbXk_HmpkSeQ,17925
|
|
34
34
|
supervisely/api/labeling_job_api.py,sha256=odnzZjp29yM16Gq-FYkv-OA4WFMNJCLFo4qSikW2A7c,56280
|
|
@@ -997,9 +997,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
|
|
|
997
997
|
supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
|
|
998
998
|
supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
|
|
999
999
|
supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
|
|
1000
|
-
supervisely-6.73.
|
|
1001
|
-
supervisely-6.73.
|
|
1002
|
-
supervisely-6.73.
|
|
1003
|
-
supervisely-6.73.
|
|
1004
|
-
supervisely-6.73.
|
|
1005
|
-
supervisely-6.73.
|
|
1000
|
+
supervisely-6.73.219.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
1001
|
+
supervisely-6.73.219.dist-info/METADATA,sha256=-yzVg7FtlrUZjhE7a0hRmL6ZofE6G3rLY6pB1KVoJ5Q,33090
|
|
1002
|
+
supervisely-6.73.219.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
1003
|
+
supervisely-6.73.219.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
|
|
1004
|
+
supervisely-6.73.219.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
|
|
1005
|
+
supervisely-6.73.219.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|