Aug-09-2021, 08:50 AM
(This post was last modified: Aug-09-2021, 08:56 AM by Gribouillis.)
I'm not an expert in interfacing Python and C but I think the default API already works the way you described above. Extension modules use Python-aware C functions that get arguments in the form Python works with and parse them with the C macro PyArg_ParseTuple. When they return Python values they use the macro Py_BuildValue to create them. The problem with this API is that it forces you to write a lot of hybrid code, take care of reference counts, etc, so it is a slow process.
Before you jump into this, it would be a good idea to review existing tools that already interface Python and C as it is an old problem and many solutions have been developped, starting with the ctypes module, the Cython language, the Swig module. In my bookmarks, there are 3 modern modules that try to minimize the amount of boilerplate code and could be worth exploring, cffi, cppyy and pybind11.
Before you jump into this, it would be a good idea to review existing tools that already interface Python and C as it is an old problem and many solutions have been developped, starting with the ctypes module, the Cython language, the Swig module. In my bookmarks, there are 3 modern modules that try to minimize the amount of boilerplate code and could be worth exploring, cffi, cppyy and pybind11.