Calling C libraries from a Python script

Dave Kuhlman dkuhlman at
Sat Apr 5 19:48:40 CEST 2003

Tim Gahnström /Bladerman wrote:

> "Joshua Goodlett" <joshua at> wrote in message
>> I'm trying to find examples of calling C library functions from within
>> a Python script.  Any advice or pointers on where to look for examples
>> would be appreciated.
> There is a whole chapter in the docs dedicated to the subject,
> Have a look at

Also look at SWIG.  It attempts to generate for you what the above doc tells 
you how to do.  If you use SWIG, you may be able to write/generate that 
code without learning anything, except how to use SWIG of course.  Feed 
SWIG a C header file (or a SWIG interface definition file) that describes 
the functions you want to call and SWIG will generate the C wrappers that 
enable you to call those functions from Python.

  - Dave

Dave Kuhlman
dkuhlman at

More information about the Python-list mailing list