2 ms·
SWIG can be easier than many cases of using ctypes. One of the examples when SWIG first came out was to wrap the entire OpenGL interface, in a few lines of code
by dalke 15y ago
SWIG can be easier than many cases of using ctypes. One of the examples when SWIG first came out was to wrap the entire OpenGL interface, in a few lines of code. This was possible because the SWIG processor could understand the OpenGL header files and generate interface code with the right number of parameters and type conversion.
With ctypes it's still a mostly manual operation. For example, if you want to call libc's "cos" then you'll need to declare the return type, as otherwise it assumes an integer.
There are additional advantages to using ctypes. For one, it's portable to Jython, pypy, and IronPython.
Also, cython can be easier than ctypes if you need access to any compile-time values, like #define values and other macros.