last update April 28 2010
fcgi-python
(Python port of C FastCGI library, works on windows)

TABLE OF CONTENTS
1. description
2. dev status
3. license
4. how to use
5. documentation (there isn't any yet)

DESCRIPTION
This is a python wrapper for the FastCGI library from fastcgi.com. I'm releasing source as well as windows binary (binary python library, .pyd file). I created this because it seemed to be less work than learning the python FCGI packages I found floating around the web.

You use my module to write a python program which a web server (like nginx, the server I use) hits up for dynamic content. More on this in the 'HOW TO USE' section below.

CURRENT DEVELOPMENT STATUS
As of 4/28/2010:
The .pyd file works on windows the way I use it but I suspect it's a little quirky, especially when it comes to cleanup and memory management (because I haven't written a delete method for the object). I don't know much about FastCGI or server stress testing. Perhaps some expert could recommend some tests.

This library is under active dev/test because I am using it to run a server. So expect at least some of the kinks to work themselves out in the next few days.

HOW TO USE
QUICKSTART

  1. download libfcgi-simple-example.py and libcfgi.pyd from downloads page
  2. copy both files into the same directory on your local machine
  3. set up a web server with fastcgi pointing to localhost:9000. Don't know how? you can download nginx from here (pick latest windows binary under 'stable versions'), it's easy to set up. Use this nginx conf file.
  4. start nginx.exe
  5. start libfcgi-simple-example.py (note: you can't ctrl+c out of this file -- just close the console to shut it off)
  6. if you used my conf file, point your web browser to http://127.0.0.1/anything.py
  7. should work
EXPLANATION
libfcgi-simple-example.py is pretty easy to understand: It's only 21 lines long, most of which is explanatory print statements. Key things to note:
  * call libfcgi.init_socket(port_number,backlog) before anything. not sure what backlog does, I use 10.
  * libfcgi.fcgi_request() creates an fcgi_request object.
  * call accept on the request object to wait for a connection
  * request object has dictionary named env with environment variables passed by web server. REQUEST_URI is the only important one. It's the URL, it tells you everything you need to know for dynamic web serving.

BIGGER EXAMPLE WITH THREADING
fcgi example with threads, plus it can be shut down by ctrl-c. 61 lines of code.

A note on threading in python: read about the GIL. I wrap the blocking call to accept() so the GIL is released. But if you're doing more work in python than C, you won't get much advantage from being parallel. caveat emptor.

DOCUMENTATION
For now, there is none. Sourceforge probably has some kind of a forum to ask questions, and we'll put together a FAQ section if demand grows.