To compile a Pyrex module you will need:
For this tutorial you will need two libraries:
Wrapping a C library is a process of rewriting
.h file in Pyrex,
with additional Python code to make things nice.
Here we will work through a couple of worked examples of
wrapping up C libraries in Pyrex to create two Python
Instead of making up a library and using that as an example, I decided to use a real library as a running example. Unfortunately I could not quickly find a single library that required all the features of Pyrex, so I used two libraries.
X On-Screen Display (XOSD) is a library that displays text much like a TV on-screen display. When an example is based on XOSD it will be written in a purple box, with the letters XOSD in the top-left corner, much like this box.
The Common Unix Printing System
a portable and extensible printing system for
It has a library that provides many printing functions, and
all examples that use the CUPS library will be
placed in a khaki box, with the letters CUPS in the
The background colour of example code will change, depending on the language.
/* C code will be written in boxes with a "aqua" background. */
# Pyrex code will be written with a grey background, with # keywords written like this.
# Python code will have a lime background.
# Bourne-Shell code will have a yellow background.
If you do not see any fancy formating then your browser
does not follow the
Change your browser to either
Yes, I know, I should make these pages accessible to everyone.
However, I was also looking for an excuse to play with
CSS when I wrote these pages, hence the heavy
dependence on style-sheets.