To create a simple example how to extend Python with C++ extensions.
- python3-devor- python3-develpython development package
- C++compiler
pip3 install src/ will build and install C++ extension.
First, install the extension. Then you can use it like this:
import cpp_python_extension
print(cpp_python_extension.sieve_of_eratosthenes(11))This will print all the prime numbers from 1 to 11 (inclusive).
python3 -m pytest tests/test_benchmark.py --verbose
- src/cpp_impl/- C++ implementation and header file with declaration of- SieveOfEratosthenesfunction
- src/setup.py-- setuptoolsfile to easily build and install the extension
- src/cython_wrapper/- Cython wrapper
- src/cpython_wrapper.cpp/ CPython wrapper
tests/test_benchmark.py - simple file to benchmark the extension
ExtendingPythonTalk project