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

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

This is a python wrapper for the FastCGI library from 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.

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.


  1. download 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 (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
  7. should work
EXPLANATION 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.

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.

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.