Python – Swiss Army Knife Web Server
By Ed Taekema in Jython, Python on November 5th, 2008
I use the following instant python test webserver in so many places… its quick to setup and makes sharing files a snap. I first saw a mention of it by Gary Robbins. Here it is:
If you enjoyed this post, make sure you subscribe to my RSS feed!python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"

11/05/2008 at 8:03 pm
I use a slight variation of the same tip. I did probably get it from the same source ages ago.
start python -c “import os;print os.getcwd();import SimpleHTTPServer;SimpleHTTPServer.test()”
I put this single line in a dirweb.cmd on Windows.
11/06/2008 at 5:34 am
There’s even simpler than that: just do
python -m SimpleHTTPServerand you’re done. No need to fiddle with-candSimpleHTTPServer.test()11/06/2008 at 11:38 am
The “-m” option is indeed beautiful!
Sadly, not the same luck in 3.0. I had hoped for:
python3.0 -m http.server
But it doesn’t run the file serving test first, so it has to be:
python3.0 -c ‘import http.server as h; h.test(HandlerClass=h.SimpleHTTPRequestHandler)’
Well, at least it works well.
11/06/2008 at 1:21 pm
Thanks guys, I’ve updated my original post with the results of this discussion!
11/06/2008 at 3:17 pm
@Gary Robinson -
Excellent. This is such a handy technique.
05/16/2009 at 1:13 pm
In python 3.1 “-m” option works again:
$ python3.1 -m http.server
Serving HTTP on 0.0.0.0 port 8000 …