I wish to wrap an existing C (pure C that is. No C++) library into Python so that I can call it from Python scripts. Which approach among the various available (C Api, SWIG etc.) would be the most suitable?
+4
A:
SWIG is great for doing this. Here is a sample tutorial: http://www.swig.org/Doc1.3/Python.html.
Kyle Lutz
2010-01-27 04:20:44
+8
A:
go with Ctypes, it is part of standard distribution and works very well. basically you can wrap C structures and types in python classes, as well as functions. Some types and functionality is already provided by library.
couple caveats though: passing triple pointers to C routines is not obvious (if you have to), and I could not get it to work with static libraries on Linux, DLL and shared objects are fine.
aaa
2010-01-27 04:24:56
Thanks unknown. I didn't even know ctypes existed. It looks simpler to use and yet just as effective as others.
Frederick
2010-01-27 14:11:09