Module Development with Boost.Python and PyBind

Adam Gladstone · Apress eBooks · 2022

In the previous chapter, we saw how to create a basic Python extension module. We added code to expose functionality from the underlying C++ library of statistical functions. We saw how to perform the conversion between PyObject pointers and native C++ types. While not especially difficult, we saw that it is potentially error prone. In this chapter, we consider two frameworks – Boost.Python and PyBind – that overcome these difficulties, making the development of Python extension modules easier. We build two quite similar wrapper components, the first based on Boost.Python and the second on PyBind. The intention here is to compare the two frameworks. Following this, we look at a typical Python client and develop a script to measure the relative performance of the extension modules. We end the chapter with a simple Flask app that demonstrates using our PyBind module as part of a (limited) statistics service.

Read the paper · More papers on PaperTik