Extending Python with C or C++

Stefan Behnel stefan_ml at behnel.de
Tue Jan 6 05:25:59 EST 2009


Ryan wrote:
> 3. Extending CPython by connecting it to Python-oblivious code written
> in C with Ctypes (Ralf's suggestion is good for this)
> 4. Extending CPython by connecting it to Python-aware (and specific)
> code using the CPython C-API functions (http://docs.python.org/c-api/)

For extending CPython (and possibly connecting it to external C
code/libraries) without learning too many new things (Python + a little C
should be enough), you can use ctypes if you can accept the runtime
overhead and the dependency on the ctypes module (which does not exist in
all CPython releases). However, I'd recommend Cython instead, as it gives
you very fast and portable code that works with all CPython versions. And
Cython code is not any harder to write at all.

http://cython.org/

Stefan



More information about the Python-list mailing list