Accessing c objects in python

Alex Martelli aleax at
Fri Aug 8 15:00:10 CEST 2003

Dave Kuhlman wrote:
[snipped: C API usage directions]

> Is there an easier way?  I'm not sure, but I'd certainly read the
> following section of the Pyrex documentation.  It's about how to
> wrap C structures:
> Any Pyrex experts listening in?  Am I on the right track here?

I'm no pyrex expert, but I recently re-evaluated various options
for wrapping large existing C libraries: C API, Boost Python,
Pyste, pyrex, ctypes, and Swig.  Somewhat to my surprise (I had
bad memories about it from the past...), Swig came up on top in
terms of simplicity.  Pyste might easily be best for _C++_
libraries, already organized into classes and possibly using
templates &c -- it, in turn, "rests" om Boost Python.  Boost
itself -- or pyrex if you'd rather not use C++ for the purpose --
might likely be best if you want to code some significant amount
of fast logic, not just wrappers.  But for "just wrappers", and
C libraries as opposed to C++ ones, Swig rules.

I'd use the C API directly only if the other tools were ruled
out for some reason (e.g., licensing); it's by far the largest
amount of work -- all other tools rest on top of it and can be
seen as "code generators" for it that save you aggravation.


More information about the Python-list mailing list