Python C++

F

Francois Fernandes

Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?

thx
 
M

Mike Thompson

Francois said:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?

thx

Your choices are:
- SWIG http://www.swig.org/
- SIP (Phil Thompson has already provided the URL)
- Boost.Python (you already know about this it appears)
 
H

Humpdydum

Is it possible to easyly integrate c++ classes in python?
SWIG used to be pretty poor for wrapping C++. Has it got better?

A couple of months ago when I looked at SWIG, it seemed to support almost
every C++ feature (templates and all), but I ended up not needing it so I
can't say how that translates in practice.

One problem with Boost is that it is such a big library and you have to get
the whole thing even if you just need a couple of "packages".

Oliver
 
H

Helmut Jarausch

Francois said:
Hi!

Is it possible to easyly integrate c++ classes in python?

I don't want to use boost c++.

Does anyone know how to start or where to find documentation for this?

I prefer PyCXX http://cxx.sourceforge.net


--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
N

Neal D. Becker

Helmut said:

Looks interesting. I want to expose lots of signal processing algorithms
written in C++ to python. I want to use std::vector for containers,
because they are fast. I need to create python types for
std::vector<double> and std::vector<std::complex<double>> at minimum. The
Python interface doesn't need to know much about these types, just be able
to create vectors of a given size.

Would PyCXX be a good choice for this? Are there any samples of code
similar to this?
 
H

Helmut Jarausch

Neal said:
Helmut Jarausch wrote:




Looks interesting. I want to expose lots of signal processing algorithms
written in C++ to python. I want to use std::vector for containers,
because they are fast. I need to create python types for
std::vector<double> and std::vector<std::complex<double>> at minimum. The
Python interface doesn't need to know much about these types, just be able
to create vectors of a given size.

Would PyCXX be a good choice for this? Are there any samples of code
similar to this?

I think, yes. PyCXX allows for use of the STL.
For each type FOO in your module you provide a new_FOO which is called when you
create an object. There you can call any C++ code including class constructors.
PyCXX helps you in filling out these long structs needed for a new type.
It helps with exception handling and reference counting.
I am new to PyCXX myself, but it worked very soon. There is a rather general
example in the Demo directory. I've just copied and modified the code and it
worked like expected - GREAT! The documentation is not too long but suffucient
and very readable. It does NOT (try to) wrap your C++ classes automatically like
other tools. I prefer this (since I don't have hundreds of classes). One can
easily fully understand what's going on and if something is missing (e.g. I think
conversion of an unsigned int to a Python long int) one can easily add this
feature using calls from the C-API himself.


--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
H

Helmut Jarausch

Neal said:
Helmut Jarausch wrote:




Looks interesting. I want to expose lots of signal processing algorithms
written in C++ to python. I want to use std::vector for containers,
because they are fast. I need to create python types for
std::vector<double> and std::vector<std::complex<double>> at minimum. The
Python interface doesn't need to know much about these types, just be able
to create vectors of a given size.

Would PyCXX be a good choice for this? Are there any samples of code
similar to this?

I think, yes. PyCXX allows for use of the STL.
For each type FOO in your module you provide a new_FOO which is called when you
create an object. There you can call any C++ code including class constructors.
PyCXX helps you in filling out these long structs needed for a new type.
It helps with exception handling and reference counting.
I am new to PyCXX myself, but it worked very soon. There is a rather general
example in the Demo directory. I've just copied and modified the code and it
worked like expected - GREAT! The documentation is not too long but suffucient
and very readable. It does NOT (try to) wrap your C++ classes automatically like
other tools. I prefer this (since I don't have hundreds of classes). One can
easily fully understand what's going on and if something is missing (e.g. I think
conversion of an unsigned int to a Python long int) one can easily add this
feature using calls from the C-API himself.


--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top