WWWCGI
small and simple Python based web server with cgi support
- What is it?
- Tiny Python script (~25kB) which is using standard Python libraries to launch a web server. The server is capable to handle requests for files, directory listings, as well as to run cgi scripts.
- What is it good for?
-
- If you ever wanted to run easily local command line program from a web browser, then this is the right tool.
- If you want to create easily GUI interface for you command line tool, then this is the right tool.
- If you want to browse a local copy of a web site which uses havily directory URLs, expecting index.html or so, and do not want to install some real web server, or you want to browse the files from the current directory, then this is the right tool.
- How to start it?
-
If you do not have installed Python version 2.4 or higher, download the installation file from Python website and install it.
When the Python is installed, copy the wwwcgi.py file to any folder you want and from command line prompt enter:
wwwcgi.py 80 or python wwwcgi.py 80
whatever works for you, where 80 is a number of the port where the server will be listening. Then start your web browser and point it to http://localhost.If you run any other webserver on your computer, or the port 80 is blocked by some other application (Skype), you have to use other free port number, e.g. 8000. Then you have to specify the port number also in your browser address line, e.g. http://localhost:8000. With script and query parameters the address will be e.g. http://localhost:8000/wwwcgi.py&action=info
The server tries to locate wwwcgi.html file (containing this text) and displays it. If it can not find this file, it looks for index.html, index.htm and if those are not found displays a folder listing of the folder from which it was started.
- How to stop it?
- Just press Ctrl-C or Ctrl-Break in the server window or issue request from web browser: http://localhost:8000/wwwcgi.py?action=exit (or just http://localhost:8000/action=exit but do not expect to get any nice answer :-)
- How to use it to run python CGI scripts, command line utilities and Python modules functions?
- The same script, i.e. wwwcgi.py, is actually also a functional cgi script which can be called and which can execute command line utilities and call a function from any Python module. Just run http://localhost/wwwcgi.py to see output which generates the wwwcgi.py if invoked with some other parameters than just a port number (i.e. in this case it behaves like a CGI script).
The only files which are considered to be CGI scripts (and executed) are those, which are specified in cgiscripts list variable which you can find at the beginning of the wwwcgi.py script.
To run a command line utility (or system command), use the syntax:
http://localhost/wwwcgi.py?action=run&cmd=NAME_OF_THE_COMMANDLINE_UTILITY
The output of the utility is returned to the server.To call function FUNCTION in Python module MODULE use:
http://localhost/wwwcgi.py?action=call&module=MODULE&function=FUNCTION
All query parameters will be forwarded to the FUNCTION in a dictionary as the function's keyword parameters. Anything written to stdout during the FUNCTION call is sent to the browser.

