Sideloading EPUB files using Python SimpleHTTPServer

RSS  •  Permalink  •  Created 02 Jun 2014  •  Written by Alberto Pettarin

I often need to sideload EPUB eBooks to Menestrello (or iBooks), on both iOS and Android devices. However, my preferred machines run Debian: booting the Mac Mini just to use iTunes, or even connecting the USB cable, would be really annoying. The same goes for using Dropbox or similar services.

Fortunately, there is a better option. To sideload my EPUB files, I instantiate a light HTTP request handler (Python SimpleHTTPServer) on my Debian machine, serving the directory where the EPUB file I want to sideload is, and downloading it onto the device using a Web browser.

It sounds complicated, but actually it is just as simple as issuing the command:

$ python -m SimpleHTTPServer 8000

It will respond the following:

$ python -m SimpleHTTPServer 8000
Serving HTTP on port 8000 ...

Now open a browser (e.g., Safari on iOS), and point it to (replace with the local IP of your PC). You will see something like this:

Blog Image 20140602-sc1.png

Click/tap on the link to the EPUB file to download it. On your console a log of the HTTP requests will appear:

$ python -m SimpleHTTPServer 8000
Serving HTTP on port 8000 ... - - [02/Jun/2014 10:45:39] "GET / HTTP/1.1" 200 - - - [02/Jun/2014 10:45:46] "GET /jerome01.epub HTTP/1.1" 200 -

In the above example, is the local IP of my iPad, and jerome01.epub is the name of the file being downloaded.

At the end of the file transfer, just select the app to sideload the EPUB file to:

Blog Image 20140602-sc2.png

Once you are done, just hit CTRL+C to terminate the SimpleHTTPServer.

Note: you can replace 8000 with the port number of your choice. Make sure your LAN/firewall settings allow HTTP traffic through it.

For the lazy: creating a Bash alias

Remembering the correct syntax (python -m SimpleHTTPServer 8000) is annoying, so a better solution consists in defining an easy-to-remember Bash alias, for example sideload.

My .bashrc has the following:

alias sideload='echo "Open your browser at "`hostname -I`": 8000"; python -m SimpleHTTPServer 8000'

The hostname -I reminds me of the local IP of the current machine.

Once you setup this alias, all you need to do to sideload your EPUB files is:

$ cd /path/to/dir/containing/your/ebook/
$ sideload 
Open your browser at : 8000
Serving HTTP on port 8000 ...