Writing Python extensions in C
log in to bookmark this presentaton
While Python comes with batteries attached, it is sometimes necessary to drop down to lower levels for performance reasons or simply because an existing library already does all the low level work. The ability to "wrap" C libraries as Python modules makes Python a very effective "glue language".
There are many ways to wrap such libraries so as to make them accessible from within Python. This presentation will discuss the raw Python-C API and how it can be used to accomplish this.
We will take a simple C library (libcsv) and write a wrapper for it enabling to be imported and used from within the Python interpreter as if it were a regular Python module. A sizeable fraction of the tutorial will be devoted to making the module a well behaved Python object (proper exceptions, string representations, object oriented handling etc.).
The presentation is designed to be practically useful rather than an in-depth technical discussion. The focus will be on getting the module to work rather than on all the details of the Python-C API.
All participants are expected to be comfortable with C and with Python itself. Lack of experience with C will make it hard to follow the tutorial. The presentation will be in a Gnu/Linux environment.
This tutorial will not cover ctypes, swig and any of the other extension writing tools. It will focus purely on the vanilla Python-C API.