[Python-ideas] discouraging direct use of the C-API

Stefan Behnel stefan_ml at behnel.de
Fri May 8 12:17:40 CEST 2015


David Wilson schrieb am 07.05.2015 um 14:32:
> On Wed, May 06, 2015 at 10:23:09AM -0600, Eric Snow wrote:
>> put a big red note at the top of every page of the C-API docs that
>> encourages folks to either use CFFI or Cython.
> 
> One of CPython's traditional strongholds is its use as an embedded
> language. I've worked on a bunch of commercial projects using it in this
> way, often specifically for improved performance/access to interpreter
> internals, and this is not to mention the numerous free software
> projects doing similar: gdb, uwsgi, mod_python, Freeswitch, and so on.

Ah, yes, there is a big wall in the CPython docs between "extending" and
"embedding" that gives users the impression that they are really different
concepts. But that's just marketing. They are not. The only difference is
that in one case, it's the CPython interpreter that starts up and then
calls into native user code, and in the other case, it's user code that
starts up and then launches a CPython interpreter. From the moment on where
both the user code and the CPython interpreter are running, there is
exactly zero difference between the two, and you can use the same tools for
interfacing native code with Python code in both cases.

What this means is that even in an embedding scenario, user code will
typically only need to call a tiny set of C-API functions to start up and
shut down the interpreter, and then leave all the rest, all the interesting
stuff, to tools that do it better.

Stefan




More information about the Python-ideas mailing list