Python 與 C/C++ 之間互相溝通的方式


Python 與 C/C++ 之間互相溝通的方式:

1. pybind11 - Seamless operability between C++11 and Python
1.1 export C/C++ functions to Python
把 C code compile 成 shared libray, 讓 Python 可以 import 這個 module.

A simple example of exporting a C function which is invoked in Python.
1.2 export Python functions to C/C++
把 Python interpreter embed 在 C program, 並且能夠在 C code 裡 import Python modules.

A simple example of exporting a Python function which is invoked in C.
Source code repositories of pybind11.
2. Cython - C-Extensions for Python
Cython 是一種 programming language, 是 Python 的 superset.

Cython code 需要先被 compile 成 C code,然後再以 C compiler 產生 shared librarry。

2.1 export C/C++ functions to Python
Tutorial: Calling C functions.
2.2 export Python functions to C/C++
Tutorial: Embedding Cython modules in C/C++ applications.
Source code repositories of Cython.
3. ctypes - A foreign function library for Python
透過 ctypes,可以在 Python 裡 import C/C++ shared libraries.
4. Python/C API
Extending and Embedding the Python Interpreter.
5. gRPC - A high-performance, open source universal RPC framework