SimpleHTTPServer: A simple lightweight web server in python

If you have Python 2.x installed along with module SimpleHTTPServer you can run a lightweight HTTP server in your machine as below:

 

$ python -m SimpleHTTPServer 

By default the web server serves  HTTP request/response on port 8000 as defined in python source below:
/usr/lib/python2.6/BaseHTTPServer.py

 

If you decide to change the port setting with SimpleHTTPServer you can just pass the port number as below:

$ python -m SimpleHTTPServer 8008

Once web server is up and running you can open web browser with local ipaddress:port or localhost:port as url. The By default the console shows http logs by the web server as below:

$ python -m SimpleHTTPServer 8008
Serving HTTP on 0.0.0.0 port 8008 …
c-x-x-x-x.hsd1.ca.comcast.net – – [06/Jun/2013 01:48:28] “GET / HTTP/1.1” 200 –
c-x-x-x-x.hsd1.ca.comcast.net – – [06/Jun/2013 01:50:21] “GET / HTTP/1.1” 200 –

 

To make sure you have SimpleHTTPServer part of your python install you can verify as below:

$python –version
Python 2.7.3
$ python
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

>>> import SimpleHTTPServer

If this setup does not return any error means you have SimpleHTTPServer installed and working in your machine.
>>> SimpleHTTPServer.__version__
‘0.6’

>>>help(‘modules’)

This will list all the modules installed with python and SimpleHTTPServer will be part of the list.

>>> exit()

 

Keywords: Python, Web Server

Advertisements

One thought on “SimpleHTTPServer: A simple lightweight web server in python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s