other languages API to python

Chris Angelico rosuav at gmail.com
Thu May 24 08:25:09 EDT 2012


On Thu, May 24, 2012 at 9:58 PM, Rita <rmorgan466 at gmail.com> wrote:
> Hello,
>
> A vendor provided a C, C++ and Java API for a application. They dont support
> python so I would like to create a library for it. My question is, how
> hard/easy would it be to create something like this? Is there a simple HOWTO
> or examples I can follow? Can someone shed home light on this?

The best way would be to write something in C that exposes the API to
Python. Check out the docs on "Extending and Embedding Python":

For Python 2.x: http://docs.python.org/extending/
For Python 3.x: http://docs.python.org/py3k/extending/

You'll need to learn Python's own API, of course, but if you're a
competent C programmer, you should find it fairly straightforward.

There's an alternative, too, though I haven't personally used it. The
ctypes module allows you to directly call a variety of C-provided
functions.

http://docs.python.org/library/ctypes.html
http://docs.python.org/py3k/library/ctypes.html

The resulting code isn't nearly as Pythonic as it could be if you
write a proper wrapper, but you save the work of writing C code.

Chris Angelico



More information about the Python-list mailing list