Thursday, March 18, 2004

Python Scripting for C/C++ Applications

Applications can and are written in Python, but people are slow to change, so the vast majority are still done using C/C++ on Linux and Windows and a combination of C++ and Objective-C on Mac OS X. I've noticed a growing trend of using Python to provide user automation or scripting, sometimes called macros, for C/C++ applications. This makes a lot of sense:

  • developers don't have to waste time and money inventing their own scripting language and users don't have to learn a new automation language for every application they use
  • Python is an Open Source solution and can be embedded and distributed for free so there are no royalty payments or licensing hassles
  • Python is simple to learn, yet Python and its standard libraries are much more powerful than a proprietary language like VBScript
  • Python is cross-platform
  • tools like SWIG make it easy to expose part or all of the application programming interface (API)
  • Python scripting can be added to legacy projects just as well as new ones so developers don't have to abandon their old C/C++ code libraries
  • On the Windows platform, Python has an excellent interface to COM (also known as ActiveX) and can be used to interface to almost any COM program (such as the MS-Office suite). Again, Python scripting can be added to enhance a project without change to the existing COM components.
  • PyObjC can be used to add scripting to any Cocoa app on Mac OS X

For many of the same reasons, Python is often used as the "glue" language for a project. In the Java world, people are using Jython as the glue and scripting language.

I started a wiki page on to help track C/C++ applications that support Python for scripting. If you know of an application that wasn't written in Python, but supports Python or Jython for scripting or as a glue language feel free to update the wiki page.

12:43:37 PM    comment []