Embedding and extending Python


Embedding Python in C/C++ applications gives you an inbuilt scripting language that end-users can use to customise and expand your application.

The embedded interpreter can execute simple Python commands or complete scripts (as files or strings).

Once Python has been embedded, it is trivial to initialise and shut down the interpreter, and it is possible to share classes between Python and C++.


There are three good reasons for extending Python (calling C/C++ from Python):

  1. Adding new data types to Python
  2. Speeding up Python routines with C/C++ replacements
  3. Creating wrappers around existing C/C++ libraries (SWIG is a great tool for this, and it works with Perl and TCL as well)

When extending, you have access to Python's types and the C/C++ libraries are loadable as modules from within Python.

[Previous] [Next]