[Python-Dev] Ctypes and the stdlib

Guido van Rossum guido at python.org
Tue Aug 30 01:48:11 CEST 2011


On Mon, Aug 29, 2011 at 2:39 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Guido van Rossum, 29.08.2011 04:27:
>> Hm, the main use that was proposed here for ctypes is to wrap existing
>> libraries (not to create nicer APIs, that can be done in pure Python
>> on top of this).
>
> The same applies to Cython, obviously. The main advantage of Cython over
> ctypes for this is that the Python-level wrapper code is also compiled into
> C, so whenever the need for a thicker wrapper arises in some part of the
> API, you don't loose any performance in intermediate layers.

Yes, this is a very nice advantage. The only advantage that I can
think of for ctypes is that it doesn't require a toolchain -- you can
just write the Python code and get going. With Cython you will always
have to invoke the Cython compiler. Another advantage may be that it
works *today* for PyPy -- I don't know the status of Cython for PyPy.

Also, (maybe this was answered before?), how well does Cython deal
with #include files (especially those you don't have control over,
like the ones typically required to use some lib<foo>.so safely on all
platforms)?

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list