Using SWIG makes connecting libraries written in C/C++ to Python very simple.
However you also need to compile the SWIG generated sources with all the right compiler flags (for finding the Python header files and libraries).
We can use distutils to save us this work as well.
Assume our C library is hello.c and our SWIG interface definition is in hello.i, write the following code in setup.py
from distutils.core import setup, Extension setup( ext_modules = [ Extension("_hello", sources=["hello.c", "hello.i"]) ] )
Note the underscore in the module name, SWIG generated a hello.py which will call import _hello somewhere.
To compile run python setup.py build_ext -i.
For a long article on SWIG and Python see here.
EDIT (3/2010): UnixReview is no longer with us, I'll try to locate the article.