To create a simple example how to extend Python with C++ extensions.
python3-dev
orpython3-devel
python development packageC++
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 ofSieveOfEratosthenes
functionsrc/setup.py
-setuptools
file to easily build and install the extensionsrc/cython_wrapper/
- Cython wrappersrc/cpython_wrapper.cpp
/ CPython wrapper
tests/test_benchmark.py
- simple file to benchmark the extension
ExtendingPythonTalk project