If you want to be sure that both python and C++ implementations are aligned, you could rely on a pure C++ implementation that you could bind in python with a tool like pybind11 for instance.