I got a Kobo Glo eBook reader some time ago. I find it quite awesome: With numerous public libraries in Paris and this device (together with sources of free books like FeedBooks, Baen Free Library or less authoritative sources), it is hard to think I will ever buy another physical book again.

I was recently looking for a way to convert .mobi files to .epub: The Kobo supports .mobi ebooks natively but the support is not as good as with .epub. It turns out Calibre allows just that: It is an open source e-book application for managing a library of ebooks and it does a lot of stuff. It is possible to use the GUI to perform the conversion but Calibre also provides some command-line tools to perform (among other things) conversions in batch. Here is an example of a Python script that uses the ebook-convert tool to convert all .mobi files in a directory to .epub:

# -*- coding: utf-8 *-*

import sys, os, subprocess

_, dirPath = sys.argv

convertedDirPath = os.path.join(dirPath, "__converted")
if not os.path.exists(convertedDirPath):

for fileName in os.listdir(dirPath):
    if fileName.endswith(".mobi"):
        rootFileName, _ = os.path.splitext(fileName)
        epubFileName = rootFileName + ".epub"
        mobiFilePath = os.path.join(dirPath, fileName)
        convertedMobiFilePath = os.path.join(convertedDirPath, fileName)
        epubFilePath = os.path.join(dirPath, epubFileName)
        conversionResult = subprocess.call(["ebook-convert", mobiFilePath, epubFilePath])
        if conversionResult == 0:
            os.rename(mobiFilePath, convertedMobiFilePath)

It is then possible to copy the converted files directly to the eReader after plugging it into the computer.

One more nice thing with the Kobo is that it stores its settings in a SQLite database on the device. Therefore there are many tools available to manipulate the content. For example, I saw this Python library that can do just that (although I haven’t tested yet with my version of Kobo).