Python/c++ Interface Library Comparison (Swig,boost.python, Pycxx, py++, sip, Weave, Pyrex)

Source: Internet
Author: User
Tags python script

"Python/c++ Interface Library comparison" (Swig,boost.python, Pycxx, py++, sip, Weave, Pyrex) http://blog.csdn.net/lainegates/article/details /19565823

There are many open-source python/c++ binding tools, search a lot of 岾, here a little summary.

SWIG

    • Supports Python 2 and 3
    • Properly configured, the package can be fully automated (*.i files need to be written by themselves)
    • When it is not fully automatic, it will mostly repeat your. h file and give hints
    • In addition to Python, other languages are supported (Java, Ruby, Lua, etc.)
    • Output a local file (this file will be compiled into a. PYD) and a package (this package is a Python script that calls the corresponding generated. PYD)
    • The performance of bindings (Bindings) is not very good and does not support encapsulation of internal classes (inner classes)
    • Attribute not supported (Access values via Getter/setters)
    • Documentation is complete and easy to learn
    • Google has used
    • C + + support not very good

Boost::P Ython

    • Support for Python 2, 3, and C + + bindings
    • For beginners, it is difficult to learn the grammar. But these grammars are intuitive.
    • The large use of C + + templates (which may or may not be a good thing) can significantly increase compilation time
    • Released with the Boost library, and the boost library is useful, but large
    • The various errors that occur when you first compile a C + + code that uses Boost.python encapsulation
    • Some syntax is not easy to learn, like the rule when a function returns a value
    • Very reliable, stable, well-tested libraries (the components in the Boost library have this feature)
    • Attribute not supported
    • Support documents are poorly written, and some feature documents are not even written.
    • The compiled PYD file is somewhat large, which is not conducive to the use of mobile phones or embedded platforms
    • With py++, it can be used in almost automatic packaging projects.

py++

    • Support for Python 2, 3, and C + + bindings
    • It calls Boost.python to automatically complete project bindings, equivalent to Boost.python's advanced tools

Pycxx

    • Support for Python 2, 3, and C + + bindings
    • Lightweight packaging library, with a lot of people
    • Support for C + + only
    • There is currently no automatic binding tool

Python C API (available in Python's help document)

    • High performance
    • Flexible
    • Suitable for embedded
    • Poor C + + support
    • Complex

cTYPES (Python's own library)

    • Flexible
    • The code for C almost seamlessly calls
    • It's more cumbersome to use.
    • Only C language is supported

Sip

    • Support for Python 2, 3, and C + + bindings
    • Used in pyqt, seldom seen in other places.

Weave

    • High performance
    • Rarely seen

Pyrex

    • Rarely seen
    • There are no mature projects yet.
    • High performance
    • Close to Python syntax

Reference: Http://stackoverflow.com/questions/1492755/python-c-binding-library-comparison

Http://web.archive.org/web/20090604182721/http://www.suttoncourtenay.org.uk/duncan/accu/integratingpython.html

Https://wiki.python.org/moin/IntegratingPythonWithOtherLanguages

"Python extension methods and tools comparison" http://www.cdadata.com/4224

To extend using tools:
Although the extension process is not complex, you can use many known tools to simplify the scaling process.
(1) SWIG
Created by David Beazley, is an automatic extension construction tool. It reads in the commented C + + header file and generates wrap code for a variety of scripting languages, such as Python, Tcl, and Perl. Swig can wrap a lot of C + + features into Python's extension modules. Please refer to http://www.swig.org for details.
Rating: Swig simple, can support a variety of script files, but the supported C + + features are not complete.

(2) SIP
Created by Phil Thompson, is a C + + module builder that specifically creates wrapper for C + + classes. It has been used to create PYQT and PYKDE extension modules and is therefore more famous. Please refer to http://www.riverbankcomputing.co.uk/sip/for details.
Evaluation: Support C + + features are complete, but more complex.

(3) BGen
The tool is included in the module build toolset in the standard Python release package and is maintained by Jack Jansen. It is used to produce Python extensions that are available in the Macintosh version.

(4) Pyfort
Created by Paul Dubois to produce an extension module for FORTRAN language generation. See Http://pyfortran.sourceforge.net.

(5) Cxx
Also created by Paul Dubois, is a library that provides a friendly API for Python's C + + extensions. CXX allows many Python objects, such as list and tuple, to be used in STL operations. The library also provides a conversion of C + + exception handling to Python exception handling. See Http://cxx.sourceforge.net.

(6) Wrappy
Created by Greg Couch to generate the extension module by reading the C + + header file. See http://www.cgl.ucsf.edu/home/gregc/wrappy/index.html.

(7) Boost Python Library
Created by David Abrahams. The library provides more distinctive C + + wrap to Python extensions, and only requires little additional information on the C + + classes to be extended. See Http://www.boost.org/libs/python/doc.
Evaluation: Boost provides a number of useful libraries for C + +, such as the Regex (regular expression library), graph (graph component and algorithm), concept check (concept in generic programming), Thread (Portable C + + multiline libraries), Python (c + + classes and functions mapped into Python), pool (memory pool management), and so on.
Boost overall is a high-value, high-quality library. and emphasis on cross-platform support. But there are a lot of things that are experimental in boost, and they need to be cautious in practical development.
Boost.python supports more C + + features, but is more complex.

Python/c++ Interface Library Comparison (Swig,boost.python, Pycxx, py++, sip, Weave, Pyrex)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.