imagekitio


Nameimagekitio JSON
Version 4.0.0 PyPI version JSON
download
home_pagehttps://github.com/imagekit-developer/imagekit-python
SummaryPython wrapper for the ImageKit API
upload_time2024-02-09 06:44:36
maintainer
docs_urlNone
author
requires_python>=3.6
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            [<img width="250" alt="ImageKit.io" src="https://raw.githubusercontent.com/imagekit-developer/imagekit-javascript/master/assets/imagekit-light-logo.svg"/>](https://imagekit.io)

# ImageKit.io Python SDK

[![Python CI](https://github.com/imagekit-developer/imagekit-python/workflows/Python%20CI/badge.svg)](https://github.com/imagekit-developer/imagekit-python/)
[![imagekitio](https://img.shields.io/pypi/v/imagekitio.svg)](https://pypi.org/project/imagekitio)
[![codecov](https://codecov.io/gh/imagekit-developer/imagekit-python/branch/master/graph/badge.svg?token=CwKWqBIlCu)](https://codecov.io/gh/imagekit-developer/imagekit-python)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)

Python SDK for [ImageKit](https://imagekit.io/) implements the new APIs and interface for different file operations.

ImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.

Supported Python Versions: >=3.6

Table of contents -

-   [Installation](#installation)
-   [Initialization](#initialization)
-   [Change Log](#change-log)
-   [Usage](#usage)
    -   [URL Generation](#url-generation)
    -   [File Upload](#file-upload)
    -   [File Management](#file-management)
    -   [Utility Functions](#utility-functions)
-   [Handling errors](#handling-errors)
-   [Development](#development)
    -   [Tests](#tests)
    -   [Sample](#sample)
-   [Support](#support)
-   [Links](#links)

## Installation

Go to your terminal and type the following command.

```bash
pip install imagekitio
```

## Initialization

```python
from imagekitio import ImageKit

imagekit = ImageKit(
    private_key='your_private_key',
    public_key='your_public_key',
    url_endpoint='your_url_endpoint'
)
```

## Change log

This document presents a list of changes that break the existing functionality of previous versions. We try to minimize these disruptions, but they are sometimes unavoidable, especially in significant updates. Therefore, versions are marked semantically and tagged as major upgrades whenever such breaking changes occur.

### Breaking History:

Changes from `3.2.0 -> 4.0.0` are listed below

1. Overlay syntax update

* In version 4.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.
* You can migrate to the new layers syntax using the `raw` transformation parameter.


Changes from `2.2.8 -> 3.0.0` are listed below

1. Throw an Error:

**What changed**

-   Before the upgrade, an `error` dict was coming in the return object of any function call. Now, SDK throws an exception in case of an error.

**Who is affected?**

-   This affects any development in your software that calls APIs from ImageKit IO and handles errors based on what's returned.

**How should I update my code?**

-   To avoid failures in an application, you could handle errors as [documented here](#handling-errors)

# Usage

You can use this Python SDK for three different kinds of methods:

-   [URL Generation](#url-generation)
-   [File Upload](#file-upload)
-   [File Management](#file-management)
-   [Utility Functions](#utility-functions)

## URL Generation

**1. Using Image path and endpoint (hostname)**

This method allows you to create a URL using the relative file path where the image exists and the URL
endpoint(url_endpoint) you want to use to access the image. You can refer to the documentation
[here](https://docs.imagekit.io/integration/url-endpoints) to read more about URL endpoints
in ImageKit and the section about [image origins](https://docs.imagekit.io/integration/configure-origin) to understand
about paths with different kinds of origins.

The file can be an image, video, or any other static file supported by ImageKit.

```python
imagekit_url = imagekit.url({
    "path": "/default-image.jpg",
    "url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    "transformation": [{
        "height": "300",
        "width": "400",
        "raw": "ar-4-3,q-40"
    }],
})
```

Sample Result URL -

```
https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400,ar-4-3,q-40/default-image.jpg
```

**2. Using full image URL**

This method allows you to add transformation parameters to an absolute URL using the `src` parameter. This method should be
used if you have the complete image URL stored in your database.

```python
image_url = imagekit.url({
    "src": "https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg",
    "transformation": [{
        "height": "300",
        "width": "400",
        "raw": "ar-4-3,q-40"
    }]
})
```

Sample Result URL -

```
https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400%2Car-4-3%2Cq-40
```

The `.url()` method accepts the following parameters.

| Option                  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| :---------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| url_endpoint            | Optional. The prepended base URL before the path of the image. If not specified, the URL Endpoint specified during SDK initialization gets used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/                                                                                                                                                                                                                                                                             |
| path                    | Conditional. A path at which the image exists. For example, `/path/to/image.jpg`. Specify a `path` or `src` parameter for URL generation.                                                                                                                                                                                                                                                                                                                                                   |
| src                     | Conditional. Complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Specify a `path` or `src` parameter for URL generation.                                                                                                                                                                                                                                                                                |
| transformation          | Optional. Specify an array of objects with name and the value in key-value pair to apply transformation params in the URL. Append different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) as different objects of the array. This document includes a complete list of supported transformations in the SDK with some examples. If one uses an unspecified transformation name, it gets applied as it is in the URL. |
| transformation_position | Optional. The default value is `path`, which places the transformation string as a path parameter in the URL. One can also specify it as a query, which adds the transformation string as the query parameter `tr` in the URL. Suppose one uses the `src` parameter to create the URL. In that case, the transformation string is always a query parameter.                                                                                                                                 |
| query_parameters        | Optional. These are the other query parameters that one wants to add to the final URL. These can be any query parameters and are not necessarily related to ImageKit. Especially useful if one wants to add some versioning parameter to their URLs.                                                                                                                                                                                                                                        |
| signed                  | Optional. Boolean. The default is `false`. If set to `true`, the SDK generates a signed image URL adding the image signature to the image URL. One can only use this if they create the URL with the `url_endpoint` and `path` parameters, not the `src` parameter.                                                                                                                                                                                                                         |
| expire_seconds          | Optional. Integer. Used along with the `signed` parameter to specify the time in seconds from `now` when the URL should expire. If specified, the URL contains the expiry timestamp, and the image signature is modified accordingly.                                                                                                                                                                                                                                                       |

## Examples of generating URLs

**1. Chained Transformations as a query parameter**

```python
image_url = imagekit.url({
    "path": "/default-image.jpg",
    "url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    "transformation": [
        {
            "height": "300",
            "width": "400"
        },
        {
            "rotation": 90
        }
    ],
    "transformation_position": "query"
})
```

Sample Result URL -

```
https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400%3Art-90
```

**2. Sharpening, contrast transform and progressive JPG image**

Add transformations like [Sharpening](https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation) to the URL with or without any other value. To use such transforms without specifying a value, set it as "-" in the transformation object. Otherwise, use the value that one wants to add to this transformation.

```python
image_url = imagekit.url({
    "src": "https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg",
    "transformation": [{
        "format": "jpg",
        "progressive": "true",
        "effect_sharpen": "-",
        "effect_contrast": "1"
    }]
})
```

Sample Result URL -

```
# Note that because the `src` parameter is in effect, the transformation string gets added as a query parameter `tr`

https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=f-jpg%2Cpr-true%2Ce-sharpen%2Ce-contrast-1
```

**3. Signed URL that expires in 300 seconds with the default URL endpoint and other query parameters**

```python
image_url = imagekit.url({
    "path": "/default-image.jpg",
    "query_parameters": {
        "p1": "123",
        "p2": "345"
    },
    "transformation": [{
        "height": "300",
        "width": "400"
    }],
    "signed": True,
    "expire_seconds": 300
})
```

Sample Result URL -

```
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?p1=123&p2=345&ik-t=1658899345&ik-s=8f03aca28432d4e87f697a48143efb4497bbed9e
```

**4. Adding overlays**

ImageKit.io enables you to apply overlays to [images](https://docs.imagekit.io/features/image-transformations/overlay-using-layers) and [videos](https://docs.imagekit.io/features/video-transformation/overlay) using the raw parameter with the concept of [layers](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#layers). The raw parameter facilitates incorporating transformations directly in the URL. A layer is a distinct type of transformation that allows you to define an asset to serve as an overlay, along with its positioning and additional transformations.

**Text as overlays**

You can add any text string over a base video or image using a text layer (l-text).

For example:

```python
image_url = imagekit.url({
    "path": "/default-image",
    "url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    "transformation": [{
        "height": "300",
        "width": "400",
        "raw": "l-text,i-Imagekit,fs-50,l-end"
    }],
})
```
**Sample Result URL**
```
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-text,i-Imagekit,fs-50,l-end/default-image.jpg
```

**Image as overlays**

You can add an image over a base video or image using an image layer (l-image).

For example:

```python
image_url = imagekit.url({
    "path": "/default-image",
    "url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    "transformation": [{
        "height": "300",
        "width": "400",
        "raw": "l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end"
    }],
})
```
**Sample Result URL**
```
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end/default-image.jpg
```

**Solid color blocks as overlays**

You can add solid color blocks over a base video or image using an image layer (l-image).

For example:

```python
image_url = imagekit.url({
    "path": "/img/sample-video",
    "url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    "transformation": [{
        "height": "300",
        "width": "400",
        "raw": "l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end"
    }],
})
```
**Sample Result URL**
```
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end/img/sample-video.mp4
```

**5. Arithmetic expressions in transformations**

ImageKit allows use of [arithmetic expressions](https://docs.imagekit.io/features/arithmetic-expressions-in-transformations) in certain dimension and position-related parameters, making media transformations more flexible and dynamic.

For example:

```python
image_url = imagekit.url({
    "path": "/default-image.jpg",
    "url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    "transformation": [{
        "height": "ih_div_2",
        "width": "iw_div_4",
        "border": "cw_mul_0.05_yellow"
    }],
})
```

**Sample Result URL**
```
https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-iw_div_4,h-ih_div_2,b-cw_mul_0.05_yellow
```

**List of transformations**

The complete list of transformations supported and their usage in ImageKit is available [here](https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations).
The SDK gives a name to each transformation parameter, making the code simpler, more straightforward, and readable. If a transformation is supported in ImageKit, though it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using the `URL` function.

If you want to generate transformations in your application and add them to the URL as it is, use the raw parameter.

| Supported Transformation Name | Translates to parameter         |
| ----------------------------- | ------------------------------- |
| height                        | h                               |
| width                         | w                               |
| aspect_ratio                  | ar                              |
| quality                       | q                               |
| crop                          | c                               |
| crop_mode                     | cm                              |
| x                             | x                               |
| y                             | y                               |
| focus                         | fo                              |
| format                        | f                               |
| radius                        | r                               |
| background                    | bg                              |
| border                        | b                               |
| rotation                      | rt                              |
| blur                          | bl                              |
| named                         | n                               |
| progressive                   | pr                              |
| lossless                      | lo                              |
| trim                          | t                               |
| metadata                      | md                              |
| color_profile                 | cp                              |
| default_image                 | di                              |
| dpr                           | dpr                             |
| effect_sharpen                | e-sharpen                       |
| effect_usm                    | e-usm                           |
| effect_contrast               | e-contrast                      |
| effect_gray                   | e-grayscale                     |
| effect_shadow                 | e-shadow                        |
| effect_gradient               | e-gradient                      |
| original                      | orig                            |
| raw                           | replaced by the parameter value |

## File Upload

The SDK provides a simple interface using the `.upload_file()` method to upload files to the ImageKit Media library. It
accepts all the parameters supported by
the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).

The `upload_file()` method requires at least the `file` as (URL/Base64/Binary) and the `file_name` parameter to upload a
file. The method returns a dict data in case of success, or it will throw a custom exception in case of failure.
Use the `options` parameter to pass other parameters supported by
the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload). Use the same
parameter name as specified in the upload API documentation.

Simple usage

```python
from imagekitio.models.UploadFileRequestOptions import UploadFileRequestOptions

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

transformation = {
    'pre': 'l-text,i-Imagekit,fs-50,l-end', 
    'post': [
        {
            'type': 'transformation', 
            'value': 'w-100'
        }
    ]
}

options = UploadFileRequestOptions(
    use_unique_file_name=False,
    tags=['abc', 'def'],
    folder='/testing-python-folder/',
    is_private_file=False,
    custom_coordinates='10,10,20,20',
    response_fields=['tags', 'custom_coordinates', 'is_private_file',
                     'embedded_metadata', 'custom_metadata'],
    extensions=extensions,
    webhook_url='https://webhook.site/c78d617f-33bc-40d9-9e61-608999721e2e',
    overwrite_file=True,
    overwrite_ai_tags=False,
    overwrite_tags=False,
    overwrite_custom_metadata=True,
    custom_metadata={'testss': 12},
    transformation=transformation
)

result = imagekit.upload_file(file='<url|base_64|binary>', # required
                              file_name='my_file_name.jpg', # required
                              options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print that uploaded file's ID
print(result.file_id)
```

If the upload succeeds, the `result` will be the `UploadFileResult` class.

If the upload fails, the custom exception will be thrown with:

-   `response_help` for any kind of help
-   `response_metadata` with `raw`, `http_status_code` and `headers`
-   `message` can be called to get the error message received from ImageKit's servers.

## File Management

The SDK provides a simple interface for all
the [media APIs mentioned here](https://docs.imagekit.io/api-reference/media-api)
to manage your files. This also returns `result`.

**1. List & Search Files**

Accepts an object specifying the parameters used to list and search files. All parameters specified
in
the [documentation here](https://docs.imagekit.io/api-reference/media-api/list-and-search-files#list-and-search-file-api)
can be passed with the correct values to get the results.

```Python
from imagekitio.models.ListAndSearchFileRequestOptions import ListAndSearchFileRequestOptions

options = ListAndSearchFileRequestOptions(
    type='file',
    sort='ASC_CREATED',
    path='/',
    search_query="created_at >= '2d' OR size < '2mb' OR format='png'",
    file_type='all',
    limit=5,
    skip=0,
    tags='Software, Developer, Engineer',
)

result = imagekit.list_files(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the first file's ID
print(result.list[0].file_id)
```

**2. Get File Details**

Accepts the file ID and fetches the details as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-details)

```python
file_id = "your_file_id"
result = imagekit.get_file_details(file_id=file_id)  # file_id required

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print that file's id
print(result.file_id)
```

**3. Get File Versions**

Accepts the file ID and fetches the details as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-versions)

```python
file_id = "your_file_id"
result = imagekit.get_file_versions(file_id=file_id)  # file_id required


# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print that file's version id
print(result.list[0].version_info.id)
```

**4. Get File Version details**

Accepts the `file_id` and `version_id` and fetches the details as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-version-details)

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

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print that file's id
print(result.file_id)

# print that file's version id
print(result.version_info.id)
```

**5. Update File Details**

Accepts all the parameters as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
The first argument to the `update_file_details()` method is the file ID, and a second argument is an object with the
parameters to be
updated.

```python
from imagekitio.models.UpdateFileRequestOptions import UpdateFileRequestOptions

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

options = UpdateFileRequestOptions(
    remove_ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'],
    webhook_url='url',
    extensions=extensions,
    tags=['tag-1', 'tag-2'],
    custom_coordinates='10,10,100,100',
    custom_metadata={'test': 11},
)

result = imagekit.update_file_details(file_id='62cfd39819ca454d82a07182'
        , options=options)  # required

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print that file's id
print(result.file_id)
```

**6. Add tags**

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

```python
result = imagekit.add_tags(file_ids=['file-id-1', 'file-id-2'], tags=['add-tag-1', 'add-tag-2'])

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# list successfully updated file ids
print(result.successfully_updated_file_ids)

# print the first file's id
print(result.successfully_updated_file_ids[0])
```

**7. Remove tags**

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

```python
result = imagekit.remove_tags(file_ids=['file-id-1', 'file-id-2'], tags=['remove-tag-1', 'remove-tag-2'])

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# list successfully updated file ids
print(result.successfully_updated_file_ids)

# print the first file's id
print(result.successfully_updated_file_ids[0])
```

**8. Remove AI tags**

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'], ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'])

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# list successfully updated file ids
print(result.successfully_updated_file_ids)

# print the first file's id
print(result.successfully_updated_file_ids[0])
```

**9. Delete File**

Delete a file according to the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file). It accepts the file ID of the File that has to be
deleted.

```python
file_id = "file_id"
result = imagekit.delete_file(file_id=file_id)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)
```

**10. Delete FileVersion**

Delete a file version as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file-version).
The method accepts the `file_id` and particular version id of the file that has to be deleted.

```python
result = imagekit.delete_file_version(file_id="file_id", version_id="version_id")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)
```

**11. Bulk File Delete by IDs**

Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-files-bulk).
The method accepts a list of file IDs that have to be deleted.

```python
result = imagekit.bulk_file_delete(file_ids=["file_id1", "file_id2"])

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# list successfully deleted file ids
print(result.successfully_deleted_file_ids)

# print the first file's id
print(result.successfully_deleted_file_ids[0])
```

**12. Copy file**

Copy a file according to the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-file).
The method accepts `source_file_path`, `destination_path`, and `include_file_versions` of the file that has to be copied.

```python
from imagekitio.models.CopyFileRequestOptions import CopyFileRequestOptions

options = \
    CopyFileRequestOptions(source_file_path='/source_file_path.jpg',
                           destination_path='/destination_path',
                           include_file_versions=True)
result = imagekit.copy_file(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)
```

**13. Move File**

Move a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-file).
The method accepts `source_file_path` and `destination_path` of the file that has to be moved.

```python
from imagekitio.models.MoveFileRequestOptions import MoveFileRequestOptions

options = \
    MoveFileRequestOptions(source_file_path='/source_file_path.jpg',
                           destination_path='/destination_path')
result = imagekit.move_file(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)
```

**14. Rename File**

Rename a file per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/rename-file).
The method accepts the `file_path`, `new_file_name`, and `purge_cache` boolean that has to be renamed.

```python
from imagekitio.models.RenameFileRequestOptions import RenameFileRequestOptions

options = RenameFileRequestOptions(file_path='/file_path.jpg',
                                   new_file_name='new_file_name.jpg',
                                   purge_cache=True)
result = imagekit.rename_file(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the purge request id
print(result.purge_request_id)
```

**15. Restore file Version**

Restore a file as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/restore-file-version).
The method accepts the `file_id` and `version_id` of the file that has to be restored.

```python
result = imagekit.restore_file_version(file_id="file_id", version_id="version_id")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print that file's id
print(result.file_id)
```

**16. Create Folder**

Create a folder per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/create-folder).
The method accepts `folder_name` and `parent_folder_path` as options that must be created.

```Python
from imagekitio.models.CreateFolderRequestOptions import CreateFolderRequestOptions

options = CreateFolderRequestOptions(folder_name='test',
                                     parent_folder_path='/')
result = imagekit.create_folder(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)
```

**17. Delete Folder**

Delete a folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder).
The method accepts `folder_path` as an option that must be deleted.

```python
from imagekitio.models.DeleteFolderRequestOptions import DeleteFolderRequestOptions

options = DeleteFolderRequestOptions(folder_path='/test/demo')
result = imagekit.delete_folder(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)
```

**18. Copy Folder**

Copy a folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-folder).
The method accepts the `source_folder_path`, `destination_path`, and `include_file_versions` boolean as options that
have to be copied.

```python
from imagekitio.models.CopyFolderRequestOptions import CopyFolderRequestOptions
options = \
    CopyFolderRequestOptions(source_folder_path='/source_folder_path',
                             destination_path='/destination/path',
                             include_file_versions=True)
result = imagekit.copy_folder(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the job's id
print(result.job_id)
```

**19. Move Folder**

Move a folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-folder).
The method accepts the `source_folder_path` and `destination_path` of a folder as options that must be moved.

```python
from imagekitio.models.MoveFolderRequestOptions import MoveFolderRequestOptions
options = \
    MoveFolderRequestOptions(source_folder_path='/source_folder_path',
                             destination_path='/destination_path')
result = imagekit.move_folder(options=options)
# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the job's id
print(result.job_id)
```

**20. Get Bulk Job Status**

Accepts the `job_id` to get bulk job status as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status).
The method takes only jobId.

```python
result = imagekit.get_bulk_job_status(job_id="job_id")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the job's id
print(result.job_id)

# print the status
print(result.status)
```

**21. Purge Cache**

Programmatically issue an explicit cache request as per
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache).
Accepts the full URL of the File for which the cache has to be cleared.

```python
result = imagekit.purge_file_cache(file_url="full_url_of_file")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the purge file cache request id
print(result.request_id)
```

**22. Purge Cache Status**

Get the purge cache request status using the `cache_request_id` returned when a purge cache request gets submitted as per the
[API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache-status)

```python
result = imagekit.get_purge_file_cache_status(purge_cache_id="cache_request_id")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the purge file cache status
print(result.status)
```

**23. Get File Metadata**

Accepts the `file_id` and fetches the metadata as per
the [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-for-uploaded-media-files)

```python
result = imagekit.get_file_metadata(file_id="file_id")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the file metadata fields
print(result.width)
print(result.exif.image.x_resolution)
```

**24. Get File Metadata from remote URL**

Accepts the `remote_file_url` and fetches the metadata as per
the [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-from-remote-url)

```python
result = imagekit.get_remote_file_url_metadata(remote_file_url="remote_file_url")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the file metadata fields
print(result.width)
print(result.exif.image.x_resolution)
```

**25. Create CustomMetaDataFields**

Accepts an option specifying the parameters used to create custom metadata fields. All parameters specified in
the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)
can be passed as it is with the correct values to get the results.

Check for the [allowed values in the schema](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field#allowed-values-in-the-schema-object).

**Example:**

```python
# Example for the type number

from imagekitio.models.CreateCustomMetadataFieldsRequestOptions import CreateCustomMetadataFieldsRequestOptions
from imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema
from imagekitio.models.CustomMetaDataTypeEnum import CustomMetaDataTypeEnum
schema = CustomMetadataFieldsSchema(type=CustomMetaDataTypeEnum.Number,
                                    min_value=100,
                                    max_value=200)
options = CreateCustomMetadataFieldsRequestOptions(name='test',
                                                   label='test',
                                                   schema=schema)
result = imagekit.create_custom_metadata_fields(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the id of created custom metadata fields
print(result.id)

# print the schema's type of created custom metadata fields
print(result.schema.type)

```

```python
# MultiSelect type Example

from imagekitio.models.CreateCustomMetadataFieldsRequestOptions import CreateCustomMetadataFieldsRequestOptions
from imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema
from imagekitio.models.CustomMetaDataTypeEnum import CustomMetaDataTypeEnum

schema = \
    CustomMetadataFieldsSchema(type=CustomMetaDataTypeEnum.MultiSelect,
                               is_value_required=True,
                               default_value=['small', 30, True],
                               select_options=[
                                    'small',
                                    'medium',
                                    'large',
                                    30,
                                    40,
                                    True,
                                ])
options = \
    CreateCustomMetadataFieldsRequestOptions(name='test-MultiSelect',
        label='test-MultiSelect', schema=schema)
result = imagekit.create_custom_metadata_fields(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the name of created custom metadata fields
print(result.name)

# print the schema's select options of created custom metadata fields
print(result.schema.select_options)

```

```python
# Date type Example

from imagekitio.models.CreateCustomMetadataFieldsRequestOptions import CreateCustomMetadataFieldsRequestOptions
from imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema
from imagekitio.models.CustomMetaDataTypeEnum import CustomMetaDataTypeEnum

schema = CustomMetadataFieldsSchema(type=CustomMetaDataTypeEnum.Date,
                                    min_value='2022-11-29T10:11:10+00:00',
                                    max_value='2022-11-30T10:11:10+00:00')
options = CreateCustomMetadataFieldsRequestOptions(name='test-date',
                                                   label='test-date',
                                                   schema=schema)
result = imagekit.create_custom_metadata_fields(options=options)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the label of created custom metadata fields
print(result.label)

# print the schema's min value of created custom metadata fields
print(result.schema.min_value)

```

**26. Get CustomMetaDataFields**

Accepts the `include_deleted` boolean as the initial parameter and fetches the metadata as per
the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/get-custom-metadata-field)
.

```python
result = imagekit.get_custom_metadata_fields()  # in this case, it will consider includeDeleted as a False

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the first customMetadataField's id
print(result.list[0].id)

# print the first customMetadataField schema's type
print(result.list[0].schema.type)
```

```python
result = imagekit.get_custom_metadata_fields(include_deleted=True)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the first customMetadataField's name
print(result.list[0].name)

# print the first customMetadataField schema's default value
print(result.list[0].schema.default_value)
```

**27. Update CustomMetaDataFields**

Accepts a `field_id` and options for specifying the parameters to be used to edit custom metadata fields
as per
the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field)
.

```python

from imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema
from imagekitio.models.UpdateCustomMetadataFieldsRequestOptions import UpdateCustomMetadataFieldsRequestOptions

schema = CustomMetadataFieldsSchema(min_value=100, max_value=200)
options = UpdateCustomMetadataFieldsRequestOptions(
    label='test-update',
    schema=schema
)
result = imagekit.update_custom_metadata_fields(
    field_id='id_of_custom_metadata_field',
    options=options
)

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)

# print the label of updated custom metadata fields
print(result.label)

# print the schema's min value of updated custom metadata fields
print(result.schema.min_value)
```

**28. Delete CustomMetaDataFields**

Accepts the id to delete the custom metadata fields as per
the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field)
.

```python
result = imagekit.delete_custom_metadata_field(field_id="id_of_custom_metadata_field")

# Final Result
print(result)

# Raw Response
print(result.response_metadata.raw)
```

## Utility functions

We have included the following commonly used utility functions in this package.

**Authentication parameter generation**

Suppose one wants to implement client-side file upload. In that case, one will need a token, expiry timestamp, and a valid signature for that upload. The SDK provides a simple method that one can use in their code to generate these authentication parameters.

<em>Note: Any client-side code should never expose The Private API Key. One must always generate these authentications parameters on the server-side</em>

authentication

`authentication_parameters = imagekit.get_authentication_parameters(token, expire)`

Returns

```python
{
    "token": "unique_token",
    "expire": "valid_expiry_timestamp",
    "signature": "generated_signature"
}
```

Both the `token` and `expire` parameters are optional. If not specified, the SDK uses the UUID to generate a random token and internally generates a valid expiry timestamp. The `token` and `expire` used to generate `signature` is part of a response returned by the server.

**Distance calculation between two `pHash` values**

Perceptual hashing allows you to construct a has value that uniquely identifies an input image based on the contents
of an image. [imagekit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the `pHash`
value of an image in the response. You can use this value
to [find a duplicate or similar image](https://docs.imagekit.io/api-reference/metadata-api#using-phash-to-find-similar-or-duplicate-images)
by calculating the distance between the two images.

This SDK exposes the `phash_distance` function to calculate the distance between two `pHash` values. It accepts two `pHash`
hexadecimal
strings and returns a numeric value indicative of the difference between the two images.

```python
def calculate_distance():
    # fetch metadata of two uploaded image files
    ...
    # extract pHash strings from both: say 'first_hash' and 'second_hash'
    ...
    # calculate the distance between them:

    distance = imagekit.phash_distance(first_hash, second_hash)
    return distance

```

**Distance calculation examples**

```Python
imagekit.phash_distance('f06830ca9f1e3e90', 'f06830ca9f1e3e90')
# output: 0 (same image)

imagekit.phash_distance('2d5ad3936d2e015b', '2d6ed293db36a4fb')
# output: 17 (similar images)

imagekit.phash_distance('a4a65595ac94518b', '7838873e791f8400')
# output: 37 (dissimilar images)
```

**HTTP response metadata of Internal API**

HTTP response metadata of the internal API call can be accessed using the \_response_metadata on the Result object.
Example:

```Python
result = imagekit.upload_file(
    file="<url|base_64|binary>",
    file_name="my_file_name.jpg",
)

# Final Result
print(result)
print(result.response_metadata.raw)
print(result.response_metadata.http_status_code)
print(result.response_metadata.headers)
```

### Sample Code Instruction

To run `sample` code go to the code samples here are hosted on GitHub - https://github.com/imagekit-samples/quickstart/tree/master/python and run.

```shell
python sample.py
```

## Handling errors

Catch and respond to invalid data, internal problems, and more.

ImageKit Python SDK raises exceptions for many reasons, such as not found, invalid parameters, authentication, and
internal server errors. Therefore, we recommend writing code that gracefully handles all possible API exceptions.

#### Example:

```Python
from imagekitio.exceptions.BadRequestException import BadRequestException
from imagekitio.exceptions.UnauthorizedException import UnauthorizedException
from imagekitio.exceptions.ForbiddenException import ForbiddenException
from imagekitio.exceptions.TooManyRequestsException import TooManyRequestsException
from imagekitio.exceptions.InternalServerException import InternalServerException
from imagekitio.exceptions.PartialSuccessException import PartialSuccessException
from imagekitio.exceptions.NotFoundException import NotFoundException
from imagekitio.exceptions.UnknownException import UnknownException

try:

    # Use ImageKit's SDK to make requests...
    print('Run image kit api')
except BadRequestException, e:
    # Missing or Invalid parameters were supplied to Imagekit.io's API
    print('Status is: ' + e.response_metadata.http_status_code)
    print('Message is: ' + e.message)
    print('Headers are: ' + e.response_metadata.headers)
    print('Raw body is: ' + e.response_metadata.raw)
except UnauthorizedException, e:
    print(e)
except ForbiddenException, e:
    # No valid API key was provided.
    print(e)
except TooManyRequestsException, e:
    # Can be for the following reasons:
    # ImageKit could not authenticate your account with the keys provided.
    # An expired key (public or private) was used with the request.
    # The account is disabled.
    # If you use the upload API, the total storage limit (or upload limit) is exceeded.
    print(e)
except InternalServerException, e:
    # Too many requests made to the API too quickly
    print(e)
except PartialSuccessException, e:
    # Something went wrong with ImageKit.io API.
    print(e)
except NotFoundException, e:
    # Error cases on partial success.
    print(e)
except UnknownException, e:
    # If any of the field or parameter is not found in the data
    print(e)

# Something else happened, which can be unrelated to ImageKit; the reason will be indicated in the message field
```

## Development

### Tests

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

```bash
$ git clone https://github.com/imagekit-developer/imagekit-python && cd imagekit-python
$ pip install tox
$ tox
```

### Sample

#### Get & Install local ImageKit Python SDK

```bash
$ git clone https://github.com/imagekit-developer/imagekit-python && cd imagekit-python
$ pip install -e .
```

#### Get samples

To integrate ImageKit Samples in the Python, the code samples covered here are hosted on GitHub - https://github.com/imagekit-samples/quickstart/tree/master/python.

Open the `python/sample.py` file and replace placeholder credentials with actual values. You can get the value of [URL-endpoint](https://imagekit.io/dashboard#url-endpoints) from your ImageKit dashboard. API keys can be obtained from the [developer](https://imagekit.io/dashboard/developer/api-keys) section in your ImageKit dashboard.

In the `python/sample.py` file, set the following parameters for authentication:

```python
from imagekitio import ImageKit
imagekit = ImageKit(
    private_key='your private_key',
    public_key='your public_key',
    url_endpoint = 'your url_endpoint'
)
```

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

```shell
pip install -r python/requirements.txt
```

Now run `python/sample.py`. If you are using CLI Tool (Terminal/Command prompt), open the project in CLI and execute it.

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

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

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

## Support

For any feedback or to report any issues or general implementation support, please reach out
to [support@imagekit.io](https://github.com/imagekit-developer/imagekit-python)

## Links

-   [Documentation](https://docs.imagekit.io/)

-   [Main Website](https://imagekit.io/)

## License

Released under the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/imagekit-developer/imagekit-python",
    "name": "imagekitio",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/25/f3/fe3394109bc150e13ccb26259f0c3e1a7d2253fef2992880f7db6636c67f/imagekitio-4.0.0.tar.gz",
    "platform": null,
    "description": "[<img width=\"250\" alt=\"ImageKit.io\" src=\"https://raw.githubusercontent.com/imagekit-developer/imagekit-javascript/master/assets/imagekit-light-logo.svg\"/>](https://imagekit.io)\n\n# ImageKit.io Python SDK\n\n[![Python CI](https://github.com/imagekit-developer/imagekit-python/workflows/Python%20CI/badge.svg)](https://github.com/imagekit-developer/imagekit-python/)\n[![imagekitio](https://img.shields.io/pypi/v/imagekitio.svg)](https://pypi.org/project/imagekitio)\n[![codecov](https://codecov.io/gh/imagekit-developer/imagekit-python/branch/master/graph/badge.svg?token=CwKWqBIlCu)](https://codecov.io/gh/imagekit-developer/imagekit-python)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)\n\nPython SDK for [ImageKit](https://imagekit.io/) implements the new APIs and interface for different file operations.\n\nImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.\n\nSupported Python Versions: >=3.6\n\nTable of contents -\n\n-   [Installation](#installation)\n-   [Initialization](#initialization)\n-   [Change Log](#change-log)\n-   [Usage](#usage)\n    -   [URL Generation](#url-generation)\n    -   [File Upload](#file-upload)\n    -   [File Management](#file-management)\n    -   [Utility Functions](#utility-functions)\n-   [Handling errors](#handling-errors)\n-   [Development](#development)\n    -   [Tests](#tests)\n    -   [Sample](#sample)\n-   [Support](#support)\n-   [Links](#links)\n\n## Installation\n\nGo to your terminal and type the following command.\n\n```bash\npip install imagekitio\n```\n\n## Initialization\n\n```python\nfrom imagekitio import ImageKit\n\nimagekit = ImageKit(\n    private_key='your_private_key',\n    public_key='your_public_key',\n    url_endpoint='your_url_endpoint'\n)\n```\n\n## Change log\n\nThis document presents a list of changes that break the existing functionality of previous versions. We try to minimize these disruptions, but they are sometimes unavoidable, especially in significant updates. Therefore, versions are marked semantically and tagged as major upgrades whenever such breaking changes occur.\n\n### Breaking History:\n\nChanges from `3.2.0 -> 4.0.0` are listed below\n\n1. Overlay syntax update\n\n* In version 4.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.\n* You can migrate to the new layers syntax using the `raw` transformation parameter.\n\n\nChanges from `2.2.8 -> 3.0.0` are listed below\n\n1. Throw an Error:\n\n**What changed**\n\n-   Before the upgrade, an `error` dict was coming in the return object of any function call. Now, SDK throws an exception in case of an error.\n\n**Who is affected?**\n\n-   This affects any development in your software that calls APIs from ImageKit IO and handles errors based on what's returned.\n\n**How should I update my code?**\n\n-   To avoid failures in an application, you could handle errors as [documented here](#handling-errors)\n\n# Usage\n\nYou can use this Python SDK for three different kinds of methods:\n\n-   [URL Generation](#url-generation)\n-   [File Upload](#file-upload)\n-   [File Management](#file-management)\n-   [Utility Functions](#utility-functions)\n\n## URL Generation\n\n**1. Using Image path and endpoint (hostname)**\n\nThis method allows you to create a URL using the relative file path where the image exists and the URL\nendpoint(url_endpoint) you want to use to access the image. You can refer to the documentation\n[here](https://docs.imagekit.io/integration/url-endpoints) to read more about URL endpoints\nin ImageKit and the section about [image origins](https://docs.imagekit.io/integration/configure-origin) to understand\nabout paths with different kinds of origins.\n\nThe file can be an image, video, or any other static file supported by ImageKit.\n\n```python\nimagekit_url = imagekit.url({\n    \"path\": \"/default-image.jpg\",\n    \"url_endpoint\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/\",\n    \"transformation\": [{\n        \"height\": \"300\",\n        \"width\": \"400\",\n        \"raw\": \"ar-4-3,q-40\"\n    }],\n})\n```\n\nSample Result URL -\n\n```\nhttps://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400,ar-4-3,q-40/default-image.jpg\n```\n\n**2. Using full image URL**\n\nThis method allows you to add transformation parameters to an absolute URL using the `src` parameter. This method should be\nused if you have the complete image URL stored in your database.\n\n```python\nimage_url = imagekit.url({\n    \"src\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg\",\n    \"transformation\": [{\n        \"height\": \"300\",\n        \"width\": \"400\",\n        \"raw\": \"ar-4-3,q-40\"\n    }]\n})\n```\n\nSample Result URL -\n\n```\nhttps://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400%2Car-4-3%2Cq-40\n```\n\nThe `.url()` method accepts the following parameters.\n\n| Option                  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |\n| :---------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| url_endpoint            | Optional. The prepended base URL before the path of the image. If not specified, the URL Endpoint specified during SDK initialization gets used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/                                                                                                                                                                                                                                                                             |\n| path                    | Conditional. A path at which the image exists. For example, `/path/to/image.jpg`. Specify a `path` or `src` parameter for URL generation.                                                                                                                                                                                                                                                                                                                                                   |\n| src                     | Conditional. Complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Specify a `path` or `src` parameter for URL generation.                                                                                                                                                                                                                                                                                |\n| transformation          | Optional. Specify an array of objects with name and the value in key-value pair to apply transformation params in the URL. Append different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) as different objects of the array. This document includes a complete list of supported transformations in the SDK with some examples. If one uses an unspecified transformation name, it gets applied as it is in the URL. |\n| transformation_position | Optional. The default value is `path`, which places the transformation string as a path parameter in the URL. One can also specify it as a query, which adds the transformation string as the query parameter `tr` in the URL. Suppose one uses the `src` parameter to create the URL. In that case, the transformation string is always a query parameter.                                                                                                                                 |\n| query_parameters        | Optional. These are the other query parameters that one wants to add to the final URL. These can be any query parameters and are not necessarily related to ImageKit. Especially useful if one wants to add some versioning parameter to their URLs.                                                                                                                                                                                                                                        |\n| signed                  | Optional. Boolean. The default is `false`. If set to `true`, the SDK generates a signed image URL adding the image signature to the image URL. One can only use this if they create the URL with the `url_endpoint` and `path` parameters, not the `src` parameter.                                                                                                                                                                                                                         |\n| expire_seconds          | Optional. Integer. Used along with the `signed` parameter to specify the time in seconds from `now` when the URL should expire. If specified, the URL contains the expiry timestamp, and the image signature is modified accordingly.                                                                                                                                                                                                                                                       |\n\n## Examples of generating URLs\n\n**1. Chained Transformations as a query parameter**\n\n```python\nimage_url = imagekit.url({\n    \"path\": \"/default-image.jpg\",\n    \"url_endpoint\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/\",\n    \"transformation\": [\n        {\n            \"height\": \"300\",\n            \"width\": \"400\"\n        },\n        {\n            \"rotation\": 90\n        }\n    ],\n    \"transformation_position\": \"query\"\n})\n```\n\nSample Result URL -\n\n```\nhttps://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400%3Art-90\n```\n\n**2. Sharpening, contrast transform and progressive JPG image**\n\nAdd transformations like [Sharpening](https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation) to the URL with or without any other value. To use such transforms without specifying a value, set it as \"-\" in the transformation object. Otherwise, use the value that one wants to add to this transformation.\n\n```python\nimage_url = imagekit.url({\n    \"src\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg\",\n    \"transformation\": [{\n        \"format\": \"jpg\",\n        \"progressive\": \"true\",\n        \"effect_sharpen\": \"-\",\n        \"effect_contrast\": \"1\"\n    }]\n})\n```\n\nSample Result URL -\n\n```\n# Note that because the `src` parameter is in effect, the transformation string gets added as a query parameter `tr`\n\nhttps://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=f-jpg%2Cpr-true%2Ce-sharpen%2Ce-contrast-1\n```\n\n**3. Signed URL that expires in 300 seconds with the default URL endpoint and other query parameters**\n\n```python\nimage_url = imagekit.url({\n    \"path\": \"/default-image.jpg\",\n    \"query_parameters\": {\n        \"p1\": \"123\",\n        \"p2\": \"345\"\n    },\n    \"transformation\": [{\n        \"height\": \"300\",\n        \"width\": \"400\"\n    }],\n    \"signed\": True,\n    \"expire_seconds\": 300\n})\n```\n\nSample Result URL -\n\n```\nhttps://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?p1=123&p2=345&ik-t=1658899345&ik-s=8f03aca28432d4e87f697a48143efb4497bbed9e\n```\n\n**4. Adding overlays**\n\nImageKit.io enables you to apply overlays to [images](https://docs.imagekit.io/features/image-transformations/overlay-using-layers) and [videos](https://docs.imagekit.io/features/video-transformation/overlay) using the raw parameter with the concept of [layers](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#layers). The raw parameter facilitates incorporating transformations directly in the URL. A layer is a distinct type of transformation that allows you to define an asset to serve as an overlay, along with its positioning and additional transformations.\n\n**Text as overlays**\n\nYou can add any text string over a base video or image using a text layer (l-text).\n\nFor example:\n\n```python\nimage_url = imagekit.url({\n    \"path\": \"/default-image\",\n    \"url_endpoint\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/\",\n    \"transformation\": [{\n        \"height\": \"300\",\n        \"width\": \"400\",\n        \"raw\": \"l-text,i-Imagekit,fs-50,l-end\"\n    }],\n})\n```\n**Sample Result URL**\n```\nhttps://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-text,i-Imagekit,fs-50,l-end/default-image.jpg\n```\n\n**Image as overlays**\n\nYou can add an image over a base video or image using an image layer (l-image).\n\nFor example:\n\n```python\nimage_url = imagekit.url({\n    \"path\": \"/default-image\",\n    \"url_endpoint\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/\",\n    \"transformation\": [{\n        \"height\": \"300\",\n        \"width\": \"400\",\n        \"raw\": \"l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end\"\n    }],\n})\n```\n**Sample Result URL**\n```\nhttps://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end/default-image.jpg\n```\n\n**Solid color blocks as overlays**\n\nYou can add solid color blocks over a base video or image using an image layer (l-image).\n\nFor example:\n\n```python\nimage_url = imagekit.url({\n    \"path\": \"/img/sample-video\",\n    \"url_endpoint\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/\",\n    \"transformation\": [{\n        \"height\": \"300\",\n        \"width\": \"400\",\n        \"raw\": \"l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end\"\n    }],\n})\n```\n**Sample Result URL**\n```\nhttps://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end/img/sample-video.mp4\n```\n\n**5. Arithmetic expressions in transformations**\n\nImageKit allows use of [arithmetic expressions](https://docs.imagekit.io/features/arithmetic-expressions-in-transformations) in certain dimension and position-related parameters, making media transformations more flexible and dynamic.\n\nFor example:\n\n```python\nimage_url = imagekit.url({\n    \"path\": \"/default-image.jpg\",\n    \"url_endpoint\": \"https://ik.imagekit.io/your_imagekit_id/endpoint/\",\n    \"transformation\": [{\n        \"height\": \"ih_div_2\",\n        \"width\": \"iw_div_4\",\n        \"border\": \"cw_mul_0.05_yellow\"\n    }],\n})\n```\n\n**Sample Result URL**\n```\nhttps://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-iw_div_4,h-ih_div_2,b-cw_mul_0.05_yellow\n```\n\n**List of transformations**\n\nThe complete list of transformations supported and their usage in ImageKit is available [here](https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations).\nThe SDK gives a name to each transformation parameter, making the code simpler, more straightforward, and readable. If a transformation is supported in ImageKit, though it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using the `URL` function.\n\nIf you want to generate transformations in your application and add them to the URL as it is, use the raw parameter.\n\n| Supported Transformation Name | Translates to parameter         |\n| ----------------------------- | ------------------------------- |\n| height                        | h                               |\n| width                         | w                               |\n| aspect_ratio                  | ar                              |\n| quality                       | q                               |\n| crop                          | c                               |\n| crop_mode                     | cm                              |\n| x                             | x                               |\n| y                             | y                               |\n| focus                         | fo                              |\n| format                        | f                               |\n| radius                        | r                               |\n| background                    | bg                              |\n| border                        | b                               |\n| rotation                      | rt                              |\n| blur                          | bl                              |\n| named                         | n                               |\n| progressive                   | pr                              |\n| lossless                      | lo                              |\n| trim                          | t                               |\n| metadata                      | md                              |\n| color_profile                 | cp                              |\n| default_image                 | di                              |\n| dpr                           | dpr                             |\n| effect_sharpen                | e-sharpen                       |\n| effect_usm                    | e-usm                           |\n| effect_contrast               | e-contrast                      |\n| effect_gray                   | e-grayscale                     |\n| effect_shadow                 | e-shadow                        |\n| effect_gradient               | e-gradient                      |\n| original                      | orig                            |\n| raw                           | replaced by the parameter value |\n\n## File Upload\n\nThe SDK provides a simple interface using the `.upload_file()` method to upload files to the ImageKit Media library. It\naccepts all the parameters supported by\nthe [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).\n\nThe `upload_file()` method requires at least the `file` as (URL/Base64/Binary) and the `file_name` parameter to upload a\nfile. The method returns a dict data in case of success, or it will throw a custom exception in case of failure.\nUse the `options` parameter to pass other parameters supported by\nthe [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload). Use the same\nparameter name as specified in the upload API documentation.\n\nSimple usage\n\n```python\nfrom imagekitio.models.UploadFileRequestOptions import UploadFileRequestOptions\n\nextensions = [\n    {\n        'name': 'remove-bg',\n        'options': {\n            'add_shadow': True,\n            'bg_color': 'pink'\n        }\n    },\n    {\n        'name': 'google-auto-tagging',\n        'minConfidence': 80,\n        'maxTags': 10\n    }\n]\n\ntransformation = {\n    'pre': 'l-text,i-Imagekit,fs-50,l-end', \n    'post': [\n        {\n            'type': 'transformation', \n            'value': 'w-100'\n        }\n    ]\n}\n\noptions = UploadFileRequestOptions(\n    use_unique_file_name=False,\n    tags=['abc', 'def'],\n    folder='/testing-python-folder/',\n    is_private_file=False,\n    custom_coordinates='10,10,20,20',\n    response_fields=['tags', 'custom_coordinates', 'is_private_file',\n                     'embedded_metadata', 'custom_metadata'],\n    extensions=extensions,\n    webhook_url='https://webhook.site/c78d617f-33bc-40d9-9e61-608999721e2e',\n    overwrite_file=True,\n    overwrite_ai_tags=False,\n    overwrite_tags=False,\n    overwrite_custom_metadata=True,\n    custom_metadata={'testss': 12},\n    transformation=transformation\n)\n\nresult = imagekit.upload_file(file='<url|base_64|binary>', # required\n                              file_name='my_file_name.jpg', # required\n                              options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print that uploaded file's ID\nprint(result.file_id)\n```\n\nIf the upload succeeds, the `result` will be the `UploadFileResult` class.\n\nIf the upload fails, the custom exception will be thrown with:\n\n-   `response_help` for any kind of help\n-   `response_metadata` with `raw`, `http_status_code` and `headers`\n-   `message` can be called to get the error message received from ImageKit's servers.\n\n## File Management\n\nThe SDK provides a simple interface for all\nthe [media APIs mentioned here](https://docs.imagekit.io/api-reference/media-api)\nto manage your files. This also returns `result`.\n\n**1. List & Search Files**\n\nAccepts an object specifying the parameters used to list and search files. All parameters specified\nin\nthe [documentation here](https://docs.imagekit.io/api-reference/media-api/list-and-search-files#list-and-search-file-api)\ncan be passed with the correct values to get the results.\n\n```Python\nfrom imagekitio.models.ListAndSearchFileRequestOptions import ListAndSearchFileRequestOptions\n\noptions = ListAndSearchFileRequestOptions(\n    type='file',\n    sort='ASC_CREATED',\n    path='/',\n    search_query=\"created_at >= '2d' OR size < '2mb' OR format='png'\",\n    file_type='all',\n    limit=5,\n    skip=0,\n    tags='Software, Developer, Engineer',\n)\n\nresult = imagekit.list_files(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the first file's ID\nprint(result.list[0].file_id)\n```\n\n**2. Get File Details**\n\nAccepts the file ID and fetches the details as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-details)\n\n```python\nfile_id = \"your_file_id\"\nresult = imagekit.get_file_details(file_id=file_id)  # file_id required\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print that file's id\nprint(result.file_id)\n```\n\n**3. Get File Versions**\n\nAccepts the file ID and fetches the details as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-versions)\n\n```python\nfile_id = \"your_file_id\"\nresult = imagekit.get_file_versions(file_id=file_id)  # file_id required\n\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print that file's version id\nprint(result.list[0].version_info.id)\n```\n\n**4. Get File Version details**\n\nAccepts the `file_id` and `version_id` and fetches the details as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-version-details)\n\n```python\nresult = imagekit.get_file_version_details(\n    file_id='file_id',\n    version_id='version_id'\n)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print that file's id\nprint(result.file_id)\n\n# print that file's version id\nprint(result.version_info.id)\n```\n\n**5. Update File Details**\n\nAccepts all the parameters as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).\nThe first argument to the `update_file_details()` method is the file ID, and a second argument is an object with the\nparameters to be\nupdated.\n\n```python\nfrom imagekitio.models.UpdateFileRequestOptions import UpdateFileRequestOptions\n\nextensions = [\n    {\n        'name': 'remove-bg',\n        'options': {\n            'add_shadow': True,\n            'bg_color': 'red'\n        }\n    },\n    {\n        'name': 'google-auto-tagging',\n        'minConfidence': 80,\n        'maxTags': 10\n    }\n]\n\noptions = UpdateFileRequestOptions(\n    remove_ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'],\n    webhook_url='url',\n    extensions=extensions,\n    tags=['tag-1', 'tag-2'],\n    custom_coordinates='10,10,100,100',\n    custom_metadata={'test': 11},\n)\n\nresult = imagekit.update_file_details(file_id='62cfd39819ca454d82a07182'\n        , options=options)  # required\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print that file's id\nprint(result.file_id)\n```\n\n**6. Add tags**\n\nAccepts a list of `file_ids` and `tags` as a parameter to be used to add tags. All parameters specified in\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/add-tags-bulk) can be passed to\nthe `.add_tags()` functions to get the results.\n\n```python\nresult = imagekit.add_tags(file_ids=['file-id-1', 'file-id-2'], tags=['add-tag-1', 'add-tag-2'])\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# list successfully updated file ids\nprint(result.successfully_updated_file_ids)\n\n# print the first file's id\nprint(result.successfully_updated_file_ids[0])\n```\n\n**7. Remove tags**\n\nAccepts a list of `file_ids` and `tags` as a parameter to be used to remove tags. All parameters specified in\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-tags-bulk) can be passed to\nthe `.remove_tags()` functions to get the results.\n\n```python\nresult = imagekit.remove_tags(file_ids=['file-id-1', 'file-id-2'], tags=['remove-tag-1', 'remove-tag-2'])\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# list successfully updated file ids\nprint(result.successfully_updated_file_ids)\n\n# print the first file's id\nprint(result.successfully_updated_file_ids[0])\n```\n\n**8. Remove AI tags**\n\nAccepts a list of `file_ids` and `ai_tags` as a parameter to remove AI tags. All parameters specified in\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-aitags-bulk) can be passed to\nthe `.remove_ai_tags()` functions to get the results.\n\n```python\nresult = imagekit.remove_ai_tags(file_ids=['file-id-1', 'file-id-2'], ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'])\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# list successfully updated file ids\nprint(result.successfully_updated_file_ids)\n\n# print the first file's id\nprint(result.successfully_updated_file_ids[0])\n```\n\n**9. Delete File**\n\nDelete a file according to the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file). It accepts the file ID of the File that has to be\ndeleted.\n\n```python\nfile_id = \"file_id\"\nresult = imagekit.delete_file(file_id=file_id)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n```\n\n**10. Delete FileVersion**\n\nDelete a file version as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file-version).\nThe method accepts the `file_id` and particular version id of the file that has to be deleted.\n\n```python\nresult = imagekit.delete_file_version(file_id=\"file_id\", version_id=\"version_id\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n```\n\n**11. Bulk File Delete by IDs**\n\nDelete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-files-bulk).\nThe method accepts a list of file IDs that have to be deleted.\n\n```python\nresult = imagekit.bulk_file_delete(file_ids=[\"file_id1\", \"file_id2\"])\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# list successfully deleted file ids\nprint(result.successfully_deleted_file_ids)\n\n# print the first file's id\nprint(result.successfully_deleted_file_ids[0])\n```\n\n**12. Copy file**\n\nCopy a file according to the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-file).\nThe method accepts `source_file_path`, `destination_path`, and `include_file_versions` of the file that has to be copied.\n\n```python\nfrom imagekitio.models.CopyFileRequestOptions import CopyFileRequestOptions\n\noptions = \\\n    CopyFileRequestOptions(source_file_path='/source_file_path.jpg',\n                           destination_path='/destination_path',\n                           include_file_versions=True)\nresult = imagekit.copy_file(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n```\n\n**13. Move File**\n\nMove a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-file).\nThe method accepts `source_file_path` and `destination_path` of the file that has to be moved.\n\n```python\nfrom imagekitio.models.MoveFileRequestOptions import MoveFileRequestOptions\n\noptions = \\\n    MoveFileRequestOptions(source_file_path='/source_file_path.jpg',\n                           destination_path='/destination_path')\nresult = imagekit.move_file(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n```\n\n**14. Rename File**\n\nRename a file per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/rename-file).\nThe method accepts the `file_path`, `new_file_name`, and `purge_cache` boolean that has to be renamed.\n\n```python\nfrom imagekitio.models.RenameFileRequestOptions import RenameFileRequestOptions\n\noptions = RenameFileRequestOptions(file_path='/file_path.jpg',\n                                   new_file_name='new_file_name.jpg',\n                                   purge_cache=True)\nresult = imagekit.rename_file(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the purge request id\nprint(result.purge_request_id)\n```\n\n**15. Restore file Version**\n\nRestore a file as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/restore-file-version).\nThe method accepts the `file_id` and `version_id` of the file that has to be restored.\n\n```python\nresult = imagekit.restore_file_version(file_id=\"file_id\", version_id=\"version_id\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print that file's id\nprint(result.file_id)\n```\n\n**16. Create Folder**\n\nCreate a folder per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/create-folder).\nThe method accepts `folder_name` and `parent_folder_path` as options that must be created.\n\n```Python\nfrom imagekitio.models.CreateFolderRequestOptions import CreateFolderRequestOptions\n\noptions = CreateFolderRequestOptions(folder_name='test',\n                                     parent_folder_path='/')\nresult = imagekit.create_folder(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n```\n\n**17. Delete Folder**\n\nDelete a folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder).\nThe method accepts `folder_path` as an option that must be deleted.\n\n```python\nfrom imagekitio.models.DeleteFolderRequestOptions import DeleteFolderRequestOptions\n\noptions = DeleteFolderRequestOptions(folder_path='/test/demo')\nresult = imagekit.delete_folder(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n```\n\n**18. Copy Folder**\n\nCopy a folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-folder).\nThe method accepts the `source_folder_path`, `destination_path`, and `include_file_versions` boolean as options that\nhave to be copied.\n\n```python\nfrom imagekitio.models.CopyFolderRequestOptions import CopyFolderRequestOptions\noptions = \\\n    CopyFolderRequestOptions(source_folder_path='/source_folder_path',\n                             destination_path='/destination/path',\n                             include_file_versions=True)\nresult = imagekit.copy_folder(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the job's id\nprint(result.job_id)\n```\n\n**19. Move Folder**\n\nMove a folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-folder).\nThe method accepts the `source_folder_path` and `destination_path` of a folder as options that must be moved.\n\n```python\nfrom imagekitio.models.MoveFolderRequestOptions import MoveFolderRequestOptions\noptions = \\\n    MoveFolderRequestOptions(source_folder_path='/source_folder_path',\n                             destination_path='/destination_path')\nresult = imagekit.move_folder(options=options)\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the job's id\nprint(result.job_id)\n```\n\n**20. Get Bulk Job Status**\n\nAccepts the `job_id` to get bulk job status as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status).\nThe method takes only jobId.\n\n```python\nresult = imagekit.get_bulk_job_status(job_id=\"job_id\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the job's id\nprint(result.job_id)\n\n# print the status\nprint(result.status)\n```\n\n**21. Purge Cache**\n\nProgrammatically issue an explicit cache request as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache).\nAccepts the full URL of the File for which the cache has to be cleared.\n\n```python\nresult = imagekit.purge_file_cache(file_url=\"full_url_of_file\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the purge file cache request id\nprint(result.request_id)\n```\n\n**22. Purge Cache Status**\n\nGet the purge cache request status using the `cache_request_id` returned when a purge cache request gets submitted as per the\n[API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache-status)\n\n```python\nresult = imagekit.get_purge_file_cache_status(purge_cache_id=\"cache_request_id\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the purge file cache status\nprint(result.status)\n```\n\n**23. Get File Metadata**\n\nAccepts the `file_id` and fetches the metadata as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-for-uploaded-media-files)\n\n```python\nresult = imagekit.get_file_metadata(file_id=\"file_id\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the file metadata fields\nprint(result.width)\nprint(result.exif.image.x_resolution)\n```\n\n**24. Get File Metadata from remote URL**\n\nAccepts the `remote_file_url` and fetches the metadata as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-from-remote-url)\n\n```python\nresult = imagekit.get_remote_file_url_metadata(remote_file_url=\"remote_file_url\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the file metadata fields\nprint(result.width)\nprint(result.exif.image.x_resolution)\n```\n\n**25. Create CustomMetaDataFields**\n\nAccepts an option specifying the parameters used to create custom metadata fields. All parameters specified in\nthe [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)\ncan be passed as it is with the correct values to get the results.\n\nCheck for the [allowed values in the schema](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field#allowed-values-in-the-schema-object).\n\n**Example:**\n\n```python\n# Example for the type number\n\nfrom imagekitio.models.CreateCustomMetadataFieldsRequestOptions import CreateCustomMetadataFieldsRequestOptions\nfrom imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema\nfrom imagekitio.models.CustomMetaDataTypeEnum import CustomMetaDataTypeEnum\nschema = CustomMetadataFieldsSchema(type=CustomMetaDataTypeEnum.Number,\n                                    min_value=100,\n                                    max_value=200)\noptions = CreateCustomMetadataFieldsRequestOptions(name='test',\n                                                   label='test',\n                                                   schema=schema)\nresult = imagekit.create_custom_metadata_fields(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the id of created custom metadata fields\nprint(result.id)\n\n# print the schema's type of created custom metadata fields\nprint(result.schema.type)\n\n```\n\n```python\n# MultiSelect type Example\n\nfrom imagekitio.models.CreateCustomMetadataFieldsRequestOptions import CreateCustomMetadataFieldsRequestOptions\nfrom imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema\nfrom imagekitio.models.CustomMetaDataTypeEnum import CustomMetaDataTypeEnum\n\nschema = \\\n    CustomMetadataFieldsSchema(type=CustomMetaDataTypeEnum.MultiSelect,\n                               is_value_required=True,\n                               default_value=['small', 30, True],\n                               select_options=[\n                                    'small',\n                                    'medium',\n                                    'large',\n                                    30,\n                                    40,\n                                    True,\n                                ])\noptions = \\\n    CreateCustomMetadataFieldsRequestOptions(name='test-MultiSelect',\n        label='test-MultiSelect', schema=schema)\nresult = imagekit.create_custom_metadata_fields(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the name of created custom metadata fields\nprint(result.name)\n\n# print the schema's select options of created custom metadata fields\nprint(result.schema.select_options)\n\n```\n\n```python\n# Date type Example\n\nfrom imagekitio.models.CreateCustomMetadataFieldsRequestOptions import CreateCustomMetadataFieldsRequestOptions\nfrom imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema\nfrom imagekitio.models.CustomMetaDataTypeEnum import CustomMetaDataTypeEnum\n\nschema = CustomMetadataFieldsSchema(type=CustomMetaDataTypeEnum.Date,\n                                    min_value='2022-11-29T10:11:10+00:00',\n                                    max_value='2022-11-30T10:11:10+00:00')\noptions = CreateCustomMetadataFieldsRequestOptions(name='test-date',\n                                                   label='test-date',\n                                                   schema=schema)\nresult = imagekit.create_custom_metadata_fields(options=options)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the label of created custom metadata fields\nprint(result.label)\n\n# print the schema's min value of created custom metadata fields\nprint(result.schema.min_value)\n\n```\n\n**26. Get CustomMetaDataFields**\n\nAccepts the `include_deleted` boolean as the initial parameter and fetches the metadata as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/get-custom-metadata-field)\n.\n\n```python\nresult = imagekit.get_custom_metadata_fields()  # in this case, it will consider includeDeleted as a False\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the first customMetadataField's id\nprint(result.list[0].id)\n\n# print the first customMetadataField schema's type\nprint(result.list[0].schema.type)\n```\n\n```python\nresult = imagekit.get_custom_metadata_fields(include_deleted=True)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the first customMetadataField's name\nprint(result.list[0].name)\n\n# print the first customMetadataField schema's default value\nprint(result.list[0].schema.default_value)\n```\n\n**27. Update CustomMetaDataFields**\n\nAccepts a `field_id` and options for specifying the parameters to be used to edit custom metadata fields\nas per\nthe [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field)\n.\n\n```python\n\nfrom imagekitio.models.CustomMetadataFieldsSchema import CustomMetadataFieldsSchema\nfrom imagekitio.models.UpdateCustomMetadataFieldsRequestOptions import UpdateCustomMetadataFieldsRequestOptions\n\nschema = CustomMetadataFieldsSchema(min_value=100, max_value=200)\noptions = UpdateCustomMetadataFieldsRequestOptions(\n    label='test-update',\n    schema=schema\n)\nresult = imagekit.update_custom_metadata_fields(\n    field_id='id_of_custom_metadata_field',\n    options=options\n)\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n\n# print the label of updated custom metadata fields\nprint(result.label)\n\n# print the schema's min value of updated custom metadata fields\nprint(result.schema.min_value)\n```\n\n**28. Delete CustomMetaDataFields**\n\nAccepts the id to delete the custom metadata fields as per\nthe [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field)\n.\n\n```python\nresult = imagekit.delete_custom_metadata_field(field_id=\"id_of_custom_metadata_field\")\n\n# Final Result\nprint(result)\n\n# Raw Response\nprint(result.response_metadata.raw)\n```\n\n## Utility functions\n\nWe have included the following commonly used utility functions in this package.\n\n**Authentication parameter generation**\n\nSuppose one wants to implement client-side file upload. In that case, one will need a token, expiry timestamp, and a valid signature for that upload. The SDK provides a simple method that one can use in their code to generate these authentication parameters.\n\n<em>Note: Any client-side code should never expose The Private API Key. One must always generate these authentications parameters on the server-side</em>\n\nauthentication\n\n`authentication_parameters = imagekit.get_authentication_parameters(token, expire)`\n\nReturns\n\n```python\n{\n    \"token\": \"unique_token\",\n    \"expire\": \"valid_expiry_timestamp\",\n    \"signature\": \"generated_signature\"\n}\n```\n\nBoth the `token` and `expire` parameters are optional. If not specified, the SDK uses the UUID to generate a random token and internally generates a valid expiry timestamp. The `token` and `expire` used to generate `signature` is part of a response returned by the server.\n\n**Distance calculation between two `pHash` values**\n\nPerceptual hashing allows you to construct a has value that uniquely identifies an input image based on the contents\nof an image. [imagekit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the `pHash`\nvalue of an image in the response. You can use this value\nto [find a duplicate or similar image](https://docs.imagekit.io/api-reference/metadata-api#using-phash-to-find-similar-or-duplicate-images)\nby calculating the distance between the two images.\n\nThis SDK exposes the `phash_distance` function to calculate the distance between two `pHash` values. It accepts two `pHash`\nhexadecimal\nstrings and returns a numeric value indicative of the difference between the two images.\n\n```python\ndef calculate_distance():\n    # fetch metadata of two uploaded image files\n    ...\n    # extract pHash strings from both: say 'first_hash' and 'second_hash'\n    ...\n    # calculate the distance between them:\n\n    distance = imagekit.phash_distance(first_hash, second_hash)\n    return distance\n\n```\n\n**Distance calculation examples**\n\n```Python\nimagekit.phash_distance('f06830ca9f1e3e90', 'f06830ca9f1e3e90')\n# output: 0 (same image)\n\nimagekit.phash_distance('2d5ad3936d2e015b', '2d6ed293db36a4fb')\n# output: 17 (similar images)\n\nimagekit.phash_distance('a4a65595ac94518b', '7838873e791f8400')\n# output: 37 (dissimilar images)\n```\n\n**HTTP response metadata of Internal API**\n\nHTTP response metadata of the internal API call can be accessed using the \\_response_metadata on the Result object.\nExample:\n\n```Python\nresult = imagekit.upload_file(\n    file=\"<url|base_64|binary>\",\n    file_name=\"my_file_name.jpg\",\n)\n\n# Final Result\nprint(result)\nprint(result.response_metadata.raw)\nprint(result.response_metadata.http_status_code)\nprint(result.response_metadata.headers)\n```\n\n### Sample Code Instruction\n\nTo run `sample` code go to the code samples here are hosted on GitHub - https://github.com/imagekit-samples/quickstart/tree/master/python and run.\n\n```shell\npython sample.py\n```\n\n## Handling errors\n\nCatch and respond to invalid data, internal problems, and more.\n\nImageKit Python SDK raises exceptions for many reasons, such as not found, invalid parameters, authentication, and\ninternal server errors. Therefore, we recommend writing code that gracefully handles all possible API exceptions.\n\n#### Example:\n\n```Python\nfrom imagekitio.exceptions.BadRequestException import BadRequestException\nfrom imagekitio.exceptions.UnauthorizedException import UnauthorizedException\nfrom imagekitio.exceptions.ForbiddenException import ForbiddenException\nfrom imagekitio.exceptions.TooManyRequestsException import TooManyRequestsException\nfrom imagekitio.exceptions.InternalServerException import InternalServerException\nfrom imagekitio.exceptions.PartialSuccessException import PartialSuccessException\nfrom imagekitio.exceptions.NotFoundException import NotFoundException\nfrom imagekitio.exceptions.UnknownException import UnknownException\n\ntry:\n\n    # Use ImageKit's SDK to make requests...\n    print('Run image kit api')\nexcept BadRequestException, e:\n    # Missing or Invalid parameters were supplied to Imagekit.io's API\n    print('Status is: ' + e.response_metadata.http_status_code)\n    print('Message is: ' + e.message)\n    print('Headers are: ' + e.response_metadata.headers)\n    print('Raw body is: ' + e.response_metadata.raw)\nexcept UnauthorizedException, e:\n    print(e)\nexcept ForbiddenException, e:\n    # No valid API key was provided.\n    print(e)\nexcept TooManyRequestsException, e:\n    # Can be for the following reasons:\n    # ImageKit could not authenticate your account with the keys provided.\n    # An expired key (public or private) was used with the request.\n    # The account is disabled.\n    # If you use the upload API, the total storage limit (or upload limit) is exceeded.\n    print(e)\nexcept InternalServerException, e:\n    # Too many requests made to the API too quickly\n    print(e)\nexcept PartialSuccessException, e:\n    # Something went wrong with ImageKit.io API.\n    print(e)\nexcept NotFoundException, e:\n    # Error cases on partial success.\n    print(e)\nexcept UnknownException, e:\n    # If any of the field or parameter is not found in the data\n    print(e)\n\n# Something else happened, which can be unrelated to ImageKit; the reason will be indicated in the message field\n```\n\n## Development\n\n### Tests\n\nTests are powered by [Tox](https://tox.wiki/en/latest/).\n\n```bash\n$ git clone https://github.com/imagekit-developer/imagekit-python && cd imagekit-python\n$ pip install tox\n$ tox\n```\n\n### Sample\n\n#### Get & Install local ImageKit Python SDK\n\n```bash\n$ git clone https://github.com/imagekit-developer/imagekit-python && cd imagekit-python\n$ pip install -e .\n```\n\n#### Get samples\n\nTo integrate ImageKit Samples in the Python, the code samples covered here are hosted on GitHub - https://github.com/imagekit-samples/quickstart/tree/master/python.\n\nOpen the `python/sample.py` file and replace placeholder credentials with actual values. You can get the value of [URL-endpoint](https://imagekit.io/dashboard#url-endpoints) from your ImageKit dashboard. API keys can be obtained from the [developer](https://imagekit.io/dashboard/developer/api-keys) section in your ImageKit dashboard.\n\nIn the `python/sample.py` file, set the following parameters for authentication:\n\n```python\nfrom imagekitio import ImageKit\nimagekit = ImageKit(\n    private_key='your private_key',\n    public_key='your public_key',\n    url_endpoint = 'your url_endpoint'\n)\n```\n\nTo install dependencies that are in the `python/requirements.txt` file, can fire this command to install them:\n\n```shell\npip install -r python/requirements.txt\n```\n\nNow run `python/sample.py`. If you are using CLI Tool (Terminal/Command prompt), open the project in CLI and execute it.\n\n```shell\n# if not installed already\npip install imagekitio\n\n# if installing local sdk\npip install -e <path_to_local_sdk>\n\n# to run sample.py file\npython3 python/sample.py\n```\n\n## Support\n\nFor any feedback or to report any issues or general implementation support, please reach out\nto [support@imagekit.io](https://github.com/imagekit-developer/imagekit-python)\n\n## Links\n\n-   [Documentation](https://docs.imagekit.io/)\n\n-   [Main Website](https://imagekit.io/)\n\n## License\n\nReleased under the MIT license.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python wrapper for the ImageKit API",
    "version": "4.0.0",
    "project_urls": {
        "Homepage": "https://github.com/imagekit-developer/imagekit-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5023f120bdf60eaf0b0868532292f9794c011527455e4e4fae28122936a858b7",
                "md5": "8b594ddc3a8a5fafe82c58192238c3c4",
                "sha256": "0d698119b35d96dda74eadb71fca3e93ab1da33a019c9368b0fd12c9031371c6"
            },
            "downloads": -1,
            "filename": "imagekitio-4.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b594ddc3a8a5fafe82c58192238c3c4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 319837,
            "upload_time": "2024-02-09T06:44:34",
            "upload_time_iso_8601": "2024-02-09T06:44:34.753689Z",
            "url": "https://files.pythonhosted.org/packages/50/23/f120bdf60eaf0b0868532292f9794c011527455e4e4fae28122936a858b7/imagekitio-4.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25f3fe3394109bc150e13ccb26259f0c3e1a7d2253fef2992880f7db6636c67f",
                "md5": "06694704cd8bc5403e0bdf13fe97e34c",
                "sha256": "2b059a2ea0485c9874e60c276ff8e4b8704be3324166dd9b58610b214c953585"
            },
            "downloads": -1,
            "filename": "imagekitio-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "06694704cd8bc5403e0bdf13fe97e34c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 312659,
            "upload_time": "2024-02-09T06:44:36",
            "upload_time_iso_8601": "2024-02-09T06:44:36.753782Z",
            "url": "https://files.pythonhosted.org/packages/25/f3/fe3394109bc150e13ccb26259f0c3e1a7d2253fef2992880f7db6636c67f/imagekitio-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-09 06:44:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "imagekit-developer",
    "github_project": "imagekit-python",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "imagekitio"
}
        
Elapsed time: 0.18531s