In this chapter, we'll discuss how to integrate compiled code into Python programs. We'll take a look at the benefits and drawbacks of our compiled code and see two ways of making a connection between Python's managed environment and code that runs directly on the hardware.
We'll see how to use the ctypes package and tie it to the interface of a C dynamic library, calling its functions and receiving their output from within our Python code. We'll also look at an easy way to write compiled code modules so that they could be imported and called directly from Python.
We'll cover the following topics in detail:
- Advantages and disadvantages of compiled code
- Accessing a dynamic library using ctypes
- Interfacing with C code using Cython