python-extender
python-extender

Reputation:

How do I create a Python class in C?

I have a legacy C library that creates a tree of objects. I would like to convert the tree into a pre-existing Python class. How do I create the PyObject for that class?

Upvotes: 5

Views: 685

Answers (3)

Matt
Matt

Reputation: 747

Cython is capable of doing this. It's a semi-fork of Pyrex, and it can wrap existing data structures and expose them to Python. In fact, this is one of the sections in the user guide. Cython is relatively easy to use, and it includes an HTML-output format that shows all the generated code as well as highlighted hot spots where optimization could be applied.

Upvotes: 4

orip
orip

Reputation: 75427

I've had success using Robin in these scenarios.

Upvotes: 1

joshperry
joshperry

Reputation: 42227

Take a look at generating your Python bindings by using a tool such as pybindgen. These guys are trying to make a superior binding generator, they talk about the shortcomings of other tools (e.g. SWIG) on their front page.

Upvotes: 2

Related Questions