Web - CGI (Common Gateway Interface)


Common Gateway Interface (CGI) is the oldest interface, and is supported by nearly every web server out of the box.

The web server will called a script that is CGI compatible. This script will handle the whole request.

Programs using CGI to communicate with their web server need to be started by the server for every request. So, every request starts a new process (for python, a new Python interpreter) – which takes some time to start up – thus making the whole interface only usable for low load situations.

Writing CGI programs, while still possible, is no longer recommended.

The upside of CGI is that it is simple, one file, one request, one response.


  • You may need to save this code with a .py or .cgi extension.
  • Additionally, this file may also need to be in a cgi-bin folder, for security reasons.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# cgitb enable debugging
# nice call trace vs “Internal Server Error”  
import cgitb

print "Content-Type: text/plain;charset=utf-8"

print "Hello World!"

Documentation / Reference

Powered by ComboStrap