Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ imagekit_url = imagekit.url({
"path": "/default-image.jpg",
"url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
"transformation": [{
"height": "300",
"width": "400",
"height": "300",
"width": "400",
"raw": "ar-4-3,q-40"
}],
})
Expand Down Expand Up @@ -313,10 +313,10 @@ extensions = [
'add_shadow': True,
'bg_color': 'pink'
}
},
},
{
'name': 'google-auto-tagging',
'minConfidence': 80,
'minConfidence': 80,
'maxTags': 10
}
]
Expand All @@ -332,7 +332,7 @@ options = UploadFileRequestOptions(
extensions=extensions,
webhook_url='https://webhook.site/c78d617f-33bc-40d9-9e61-608999721e2e',
overwrite_file=True,
overwrite_a_i_tags=False,
overwrite_ai_tags=False,
overwrite_tags=False,
overwrite_custom_metadata=True,
custom_metadata={'testss': 12},
Expand Down Expand Up @@ -445,7 +445,7 @@ the [API documentation here](https://docs.imagekit.io/api-reference/media-api/ge

```python
result = imagekit.get_file_version_details(
file_id='file_id',
file_id='file_id',
version_id='version_id'
)

Expand Down Expand Up @@ -475,21 +475,21 @@ from imagekitio.models.UpdateFileRequestOptions import UpdateFileRequestOptions

extensions = [
{
'name': 'remove-bg',
'name': 'remove-bg',
'options': {
'add_shadow': True,
'bg_color': 'red'
}
},
},
{
'name': 'google-auto-tagging',
'minConfidence': 80,
'minConfidence': 80,
'maxTags': 10
}
]

options = UpdateFileRequestOptions(
remove_a_i_tags=['remove-ai-tag-1', 'remove-ai-tag-2'],
remove_ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'],
webhook_url='url',
extensions=extensions,
tags=['tag-1', 'tag-2'],
Expand Down Expand Up @@ -556,12 +556,12 @@ print(result.successfully_updated_file_ids[0])

**8. Remove AI tags**

Accepts a list of `file_ids` and `a_i_tags` as a parameter to remove AI tags. All parameters specified in
Accepts a list of `file_ids` and `ai_tags` as a parameter to remove AI tags. All parameters specified in
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-aitags-bulk) can be passed to
the `.remove_ai_tags()` functions to get the results.

```python
result = imagekit.remove_ai_tags(file_ids=['file-id-1', 'file-id-2'], a_i_tags=['remove-ai-tag-1', 'remove-ai-tag-2'])
result = imagekit.remove_ai_tags(file_ids=['file-id-1', 'file-id-2'], ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'])

# Final Result
print(result)
Expand Down Expand Up @@ -1237,7 +1237,7 @@ except UnknownException, e:

### Tests

Tests are powered by [Tox](https://tox.wiki/en/latest/).
Tests are powered by [Tox](https://tox.wiki/en/latest/).

```bash
$ git clone https://github.com/imagekit-developer/imagekit-python && cd imagekit-python
Expand Down Expand Up @@ -1270,7 +1270,7 @@ imagekit = ImageKit(
url_endpoint = 'your url_endpoint'
)
```

To install dependencies that are in the `python/requirements.txt` file can fire this command to install them:

```shell
Expand All @@ -1281,13 +1281,13 @@ Now run `python/sample.py`. If you are using CLI Tool (Terminal/Command prompt),

```shell
# if not installed already
pip install imagekitio
pip install imagekitio

# if installing local sdk
pip install -e <path_to_local_sdk>
pip install -e <path_to_local_sdk>

# to run sample.py file
python3 python/sample.py
python3 python/sample.py
```

## Support
Expand Down
4 changes: 2 additions & 2 deletions imagekitio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def remove_tags(self, file_ids, tags) -> TagsResult:
"""Remove tags by file ids and tags"""
return self.file.manage_tags(file_ids, tags, "removeTags")

def remove_ai_tags(self, file_ids, a_i_tags) -> TagsResult:
def remove_ai_tags(self, file_ids, ai_tags) -> TagsResult:
"""Remove AI tags by file ids and AI tags"""
return self.file.remove_ai_tags(file_ids, a_i_tags)
return self.file.remove_ai_tags(file_ids, ai_tags)

def delete_file(self, file_id: str = None) -> ResponseMetadataResult:
"""Delete file by file_id"""
Expand Down
2 changes: 1 addition & 1 deletion imagekitio/constants/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"extensions",
"webhook_url",
"overwrite_file",
"overwrite_a_i_tags",
"overwrite_ai_tags",
"overwrite_tags",
"overwrite_custom_metadata",
"custom_metadata",
Expand Down
24 changes: 19 additions & 5 deletions imagekitio/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ def upload(
raise ValueError("Invalid upload options")
if isinstance(file, str) or isinstance(file, bytes):
files.update({"file": (None, file)})
if 'overwriteAiTags' in options:
options['overwriteAITags'] = options['overwriteAiTags']
del options['overwriteAiTags']
all_fields = {**files, **options}
multipart_data = MultipartEncoder(
fields=all_fields, boundary="--randomBoundary---------------------"
)
headers.update({"Content-Type": multipart_data.content_type})
resp = self.request.request(
"Post", url=url, data=multipart_data, headers=headers
"Post", url=url, data=multipart_data.read(), headers=headers
)
if resp.status_code == 200:
response = convert_to_response_object(resp, UploadFileResult)
Expand All @@ -115,6 +118,10 @@ def list(self, options: ListAndSearchFileRequestOptions = None) -> ListFileResul
:return: ListFileResult
"""
if options is not None:
if 'tags' in options.__dict__ and isinstance(options.tags, list):
val = ", ".join(options.tags)
if val:
options.tags = val
formatted_options = request_formatter(options.__dict__)
if not self.is_valid_list_options(formatted_options):
raise ValueError("Invalid option for list_files")
Expand Down Expand Up @@ -215,8 +222,15 @@ def update_file_details(
url = "{}/v1/files/{}/details/".format(URL.API_BASE_URL, file_id)
headers = {"Content-Type": "application/json"}
headers.update(self.request.get_auth_headers())
formatted_options = request_formatter(options.__dict__)
if 'removeAiTags' in formatted_options:
remove_ai_tags_dict = {'removeAITags': formatted_options['removeAiTags']}
del formatted_options['removeAiTags']
request_data = {**remove_ai_tags_dict, **formatted_options}
else:
request_data = formatted_options
data = (
dumps(request_formatter(options.__dict__))
dumps(request_data)
if options is not None
else dict()
)
Expand Down Expand Up @@ -250,15 +264,15 @@ def manage_tags(self, file_ids, tags, action) -> TagsResult:
else:
general_api_throw_exception(resp)

def remove_ai_tags(self, file_ids, a_i_tags) -> TagsResult:
def remove_ai_tags(self, file_ids, ai_tags) -> TagsResult:
"""Remove AI tags of files
:param file_ids: array of file ids
:param a_i_tags: array of AI tags
:param ai_tags: array of AI tags
"""
url = "{}/v1/files/removeAITags".format(URL.API_BASE_URL)
headers = {"Content-Type": "application/json"}
headers.update(self.request.get_auth_headers())
data = dumps({"fileIds": file_ids, "AITags": a_i_tags})
data = dumps({"fileIds": file_ids, "AITags": ai_tags})
resp = self.request.request(method="Post", url=url, headers=headers, data=data)
if resp.status_code == 200:
response = convert_to_response_object(resp, TagsResult)
Expand Down
5 changes: 4 additions & 1 deletion imagekitio/models/ListAndSearchFileRequestOptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import array


class ListAndSearchFileRequestOptions:
def __init__(
self,
Expand All @@ -8,7 +11,7 @@ def __init__(
file_type: str = None,
limit: int = None,
skip: int = None,
tags: str = None,
tags=None,
):
if type is not None:
self.type = type
Expand Down
6 changes: 3 additions & 3 deletions imagekitio/models/UpdateFileRequestOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
class UpdateFileRequestOptions:
def __init__(
self,
remove_a_i_tags: List[str] = None,
remove_ai_tags: List[str] = None,
webhook_url: str = None,
extensions: json = None,
tags: List[str] = None,
custom_coordinates: str = None,
custom_metadata: json = None,
):
if remove_a_i_tags is not None:
self.remove_a_i_tags = remove_a_i_tags
if remove_ai_tags is not None:
self.remove_ai_tags = remove_ai_tags
if webhook_url is not None:
self.webhook_url = webhook_url
if extensions is not None:
Expand Down
6 changes: 3 additions & 3 deletions imagekitio/models/UploadFileRequestOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(
extensions: json = None,
webhook_url: str = None,
overwrite_file: bool = None,
overwrite_a_i_tags: bool = None,
overwrite_ai_tags: bool = None,
overwrite_tags: bool = None,
overwrite_custom_metadata: bool = None,
custom_metadata: json = None,
Expand All @@ -37,8 +37,8 @@ def __init__(
self.webhook_url = webhook_url
if overwrite_file is not None:
self.overwrite_file = overwrite_file
if overwrite_a_i_tags is not None:
self.overwrite_a_i_tags = overwrite_a_i_tags
if overwrite_ai_tags is not None:
self.overwrite_ai_tags = overwrite_ai_tags
if overwrite_tags is not None:
self.overwrite_tags = overwrite_tags
if overwrite_custom_metadata is not None:
Expand Down
19 changes: 11 additions & 8 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import json
import re
import unittest
from unittest.mock import patch
Expand Down Expand Up @@ -32,6 +33,16 @@ def setUp(self, mock_file, mock_req):
skip=0,
tags="Tag-1, Tag-2, Tag-3",
)
self.opt = ListAndSearchFileRequestOptions(
type="file",
sort="ASC_CREATED",
path="/",
search_query="created_at >= '2d' OR size < '2mb' OR format='png'",
file_type="all",
limit=1,
skip=0,
tags=["Tag-1", "Tag-2", "Tag-3"],
)
self.client = ImageKit(
public_key="fake122",
private_key=ClientTestCase.private_key,
Expand All @@ -50,11 +61,3 @@ def get_auth_headers_for_test():
(ClientTestCase.private_key + ":").encode()
).decode("utf-8")
return {"Authorization": "Basic {}".format(encoded_private_key)}


def make_string_to_single_line(multiline_string):
return (
re.sub(r"\s(?=\s)", "", re.sub(r"\s", " ", multiline_string))
.replace("{ ", "{")
.replace(" }", "}")
)
Loading