Home » » Simplest python server using Python

Simplest python server using Python

If you want to use python to build a small server or just want to provide
web-base api with minimal efforts, you can just use python SimpleHTTPServer package as below:

import SimpleHTTPServer
SimpleHTTPServer.test()

With only two lines, that's really awesome. Right? 

Or you can do as follows: 
python -m SimpleHTTPServer
the default port is 8000. 

you can also alias it in your .bash_profile file 
alias http="python -m SimpleHTTPServer"

Notes:
1. For web-based server, you can just return a json file for communication. 

2. 

Flask 

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. 
Flask is as simple as SimpleHTTPServer, but it is more powerful in many ways. You can also find rich documentation on its official website. 

Popular Posts