This chapter explained one of the most advanced topics in the book. We discussed the reasons and tools for building Python extensions. We started by writing pure C extensions that depend only on Python/C API and then reimplemented it with Cython to show how easy it can be if you only choose the proper tool.
There are still some reasons for doing things the hard way and using nothing more than the pure C compiler and the Python.h headers. Anyway, the best recommendation is to use tools such as Cython or Pyrex (not featured here) because this will make your code base more readable and maintainable. It will also save you from most of the issues caused by incautious reference counting and memory mismanagement.
Our discussion of extensions ended with the presentation of ctypes and CFFI as alternative ways to solve the problems of integrating shared libraries. Because they do...