ImageKit Python SDK

raw JSON →
5.4.0 verified Fri May 01 auth: no python

The official Python library for the ImageKit API. Version 5.4.0 supports image and video management, transformations, URL generation, and DAM operations. Requires Python >=3.9.

pip install imagekitio
error ImportError: cannot import name 'ImageKit' from 'imagekitio'
cause Trying to import the old class name from v4.x.
fix
Use from imagekitio import ImageKitClient (v5). If stuck on v4, pin version to 4.x: pip install imagekitio==4.2.0 and use from imagekitio import ImageKit.
error AttributeError: 'ImageKitClient' object has no attribute 'upload'
cause Using old method name from v4.x.
fix
Use client.upload_file(...) in v5.x, or downgrade to v4.x.
breaking Version 5.0.0 is a complete rewrite. The old SDK (v4.x) used `ImageKit` class and `imagekitio.ImageKit` import. New SDK uses `ImageKitClient` and different API methods.
fix Update imports to `from imagekitio import ImageKitClient` and adapt to new method signatures (e.g., `upload_file` instead of `upload`).
deprecated The `ImageKit` class from v4.x is deprecated and removed in v5. Use `ImageKitClient` instead.
fix Replace `from imagekitio import ImageKit` with `from imagekitio import ImageKitClient`.
gotcha Signed URL generation with diacritic characters can produce invalid signatures (fixed in v4.0.1 but still relevant). Ensure URLs are properly encoded if you encounter 401 errors.
fix Upgrade to v4.0.1+ and use URL-encoded strings when generating signed URLs.

Initialize the client with your credentials and upload a file.

import os
from imagekitio import ImageKitClient

client = ImageKitClient(
    private_key=os.environ.get('IMAGEKIT_PRIVATE_KEY', 'your_private_key'),
    public_key=os.environ.get('IMAGEKIT_PUBLIC_KEY', 'your_public_key'),
    url_endpoint=os.environ.get('IMAGEKIT_URL_ENDPOINT', 'https://ik.imagekit.io/your_imagekit_id')
)

# Upload a file
upload = client.upload_file(
    file=open('path/to/image.jpg', 'rb'),
    file_name='example.jpg'
)
print(upload.url)