Cairo with python Ctypes
Posted by stu at January 9th, 2012
Uploaded some experiments with python and ctypes to here:
https://gitorious.org/pycairo-ctypes/pycairo-ctypes
This is a really rough proof of concept that the pycairo API can be implemented with ctypes + metclasses.
So far only ImageSurface is supported on the SVG backend, along with Contexts. The nice thing about this is that you can use a pycairo like API on pypy, where things should be faster (in theory).
There’s a test that can be run to show the outputs the same for pycairo and cairo ctypes.

see my version on http://cairo-ctypes.googlecode.com
maxim
Hi Maxim,
Your library looks useful, it’s slightly different to this one at the moment – yours provides the cairo C.
What I’m interested in is providing the pycairo API where you get classes for things like Context, Surface, ImageSurface etc.
This is achieved by importing a ctypes style binding then using metaclasses to bind the functions to classes using their names (e.g. a prefix of cairo_image_surface_ goes to ImageSurface).
I could save a lot of the nastier code by just building on your library.
I haven’t worked on this for a little while though so feel free to take the ideas/code. A pycairo compatible library might be useful for running pycairo style code on pypy for instance.
stu