Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

other languages API to python

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


rmorgan466 at gmail

May 24, 2012, 4:58 AM

Post #1 of 3 (325 views)
Permalink
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.--


rosuav at gmail

May 24, 2012, 5:25 AM

Post #2 of 3 (305 views)
Permalink
Re: other languages API to python [In reply to]

On Thu, May 24, 2012 at 9:58 PM, Rita <rmorgan466 [at] gmail> 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


fabiofz at gmail

Jun 1, 2012, 5:27 PM

Post #3 of 3 (289 views)
Permalink
Re: other languages API to python [In reply to]

On Thu, May 24, 2012 at 9:25 AM, Chris Angelico <rosuav [at] gmail> wrote:
> On Thu, May 24, 2012 at 9:58 PM, Rita <rmorgan466 [at] gmail> 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

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.