Is it possible to use C++ libraries within a Python application? I am planning to write an encryption program and want to use GnuPG C++ libraries.elementFontfont-familyfont-sizefont-stylefont-variantfont-weightletter-spacingline-heighttext-decorationtext-aligntext-indenttext-transformwhite-spaceword-spacingcolorBackgroundbg-attachmentbg-colorbg-imagebg-positionbg-repeatBoxwidthheightborder-topborder-rightborder-bottomborder-leftmarginpaddingmax-heightmin-heightmax-widthmin-widthoutline-coloroutline-styleoutline-widthPositioningpositiontopbottomrightleftfloatdisplayclearz-indexListlist-style-imagelist-style-typelist-style-positionTablevertical-alignborder-collapseborder-spacingcaption-sideempty-cellstable-layoutEffectstext-shadow-webkit-box-shadowborder-radiusOtheroverflowcursorvisibility
You don't need to reinvent the wheel:
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
I am just asking. In future I may need to import any C++ library, not a Crypto, but some other. Is it possible?
There are at least five possible ways:
- Handcode the interface and glue code ( http://docs.python.org/extending )
- use SWIG to autogenerate (mostly) the interface ( http://www.swig.org )
- using BOOST's python interface
( http://www.boost.org/doc/libs/1_45_0/libs/python/doc/index.html )
- using ctypes module for runtime interaction (like and use it a _lot_,
very cool for rapid prototyping :-) http://docs.python.org/library/ctypes.html )
- cython (different approach, implements a python subset, http://cython.org )
I used SWIG and ctypes in the past, as it seems (for me) the easiest way.
Stefan Sonnenberg-Carstens, 06.01.2011 07:08:
None of these is worth recommending. Too much work, too hard to build a
good interface with them and simply too slow for the invested effort.
Their main drawback is that they distract you from designing wrappers and
require you to think about lots of C/C++ problems.
IMHO, these are the two ways to do it nowadays. Cython wrappers are
obviously much faster than anything you could ever write in ctypes, but
both are similarly easy to use and allow users to focus on good wrapper design.