PyCClass

PyCClass is a library to aid in the task of making object oriented python bindings to an object oriented C API. It is free software, and released under the GNU General Public License.

The latest release of PyCClass is availible in the PyCClass release directory.

PyCClass's Savannah page.

Developed by Mark Jenkins of ParIT Worker Co-operative

Why?

Many modern C programmers create interfaces that are object oriented; for example, the graphics toolkit GTK+.

SWIG provides a way to access C APIs in other languages. For python it makes C functions availible as python functions, and C structs as python classes and objects. Consider the following C interface:

    typedef struct {
	int x;
	int y;
    } Point;
    
    Point * point_new();
    void point_set_x(Point * p, int x);
    int point_get_x(Point *p);
    void point_set_y(Point * p, int y);
    int point_get_y(Point *p);
    void point_move_up_right(Point *p);
    void point_move_left(Point *p, int by);

Here is what interaction with this interface would look like if you used SWIG to generate python bindings:

    from point_module import point_new, point_set_x, point_move_up_right, \
			     point_move_left

    p = point_new()
    point_set_x(p, 2)
    point_move_up_right(p)
    point_move_left(p, 5)

An interface like this would be more useful:

    from point_module import Point

    p = Point()
    p.set_x(2)
    p.move_up_right()
    p.move_left(5)

PyCClass exists to help you make a python interface like this from an object oriented C api.