How I migrated from Sirv To ImageKit using Python
I've always hosted my photographs on Sirv since I started using this domain. It's an image CDN that optimises and delivers your images faster.
Why leave Sirv
I've been using Sirv to optimise the photos on my website since I started blogging, and it's been fantastic. It has everything I expected and more: picture optimization, url scaling and cropping, image overlays, caching, and more. The monthly bandwidth on Sirv's free plan was insufficient for my website, therefore I opted to move away from them. It was fine for me at first, but as my website grew and I received more and more visits, my bandwidth usage soared.
The free plan provides 500 MB of storage and a monthly bandwidth of 2GB.
Coding The Migration Script
As a developer, I tend to automate most things. I could have migrated image by image, but that would take a century before I was done, so I decided to use Python to quicken the process.
How The Script Will Work
The graphic above demonstrates how our programme will operate. We will first retrieve a list of all our photographs from Sirv, then crawl through each file and upload it to ImageKit. It is quite simple.
Getting list of files
The first method is very easy, we are going to make Sirv export a CSV file which will contain a list of all the files on their server. Head over to your My files directory on Sirv. Then you right-click an empty area and select "Export file list to CSV".

Now, this will download a CSV file onto your device.
Installing Required Packages
Obviously, we will need to install some packages in order to make our script work. The only package which we will be installing is the ImageKit SDK.
In order to install it, just open your terminal and paste in the following code.
pip install imagekitio
Create a new Python file and put the following code inside after the package has been successfully installed.
import csv
from imagekitio import ImageKit
imagekit = ImageKit(
private_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
public_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
url_endpoint = "https://ik.imagekit.io/your_endpoint/"
)
with open("file-list.csv") as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
line = dict(row)
folder = line["File"].split("/")[:-1]
folder.append("")
folder = "/".join(folder)
if line['Type'] != "folder":
imagekit.upload_file(
file = line["URL"],
file_name = line["Name"],
options = {
"use_unique_file_name": False,
"folder": folder
}
)
print("Uploaded " + line["Name"])
You only need the code above. First, we included the csv and ImageKit packages. Then we built an ImageKit instance. You must replace private key and public key with the private key and public key of your account, accordingly. Then you replace the url endpoint with the endpoint for your account.
On the following line, we opened the CSV file (which I renamed 'file-list.csv' after downloading it from Sirv) and built a CSV reader.
The files are then uploaded to ImageKit once we go over the data in the CSV file.
Outro
So this is how I transferred all of my photographs from Sirv to ImageKit. The procedure described here will also move your photographs to ImageKit. If you run across any issues, please post them in the comments area..
👋