Mailing List Archive

other languages API to python
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?

TIA

--
--- Get your facts first, then you can distort them as you please.--
Re: other languages API to python [ In reply to ]
On Thu, May 24, 2012 at 9:58 PM, Rita <rmorgan466@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
--
http://mail.python.org/mailman/listinfo/python-list
Re: other languages API to python [ In reply to ]
On Thu, May 24, 2012 at 9:25 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Thu, May 24, 2012 at 9:58 PM, Rita <rmorgan466@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
> --
> http://mail.python.org/mailman/listinfo/python-list

There are some wrapping libraries that may help in wrapping C/C++ for
Python... Take a look at Boost::Python, Swig, Sip and Cython
(personally, I like Boost::Python, but the generated code can be a bit
bloated -- but not a problem unless it's a really huge library --
Cython seems nice too, but I've only made few things with it, so, I
can't comment much).

Cheers,

Fabio
--
http://mail.python.org/mailman/listinfo/python-list