py_cpp*
The source code for py_cpp, including a MSVC demo project is available here.
Synopsis
py_cpp is a system for quickly and easily interfacing C++ code with Python such that the Python interface is
very similar to the C++ interface. It is designed to be minimally
intrusive on your C++ design. In most cases, you should not have to alter
your C++ classes in any way in order to use them with py_cpp. The system
should simply “reflect” your C++ classes and functions into
Python. The major features of py_cpp include support for:
among others.
Supported Platforms
py_cpp has been tested in the following configurations:
- Against Python 1.5.2 using the following compiler/library:
- Against Python 2.0 using the following compiler/library combinations:
Py_cpp requires the boost libraries, and is
has been accepted for inclusion into the boost libraries pending “boostification“
(completion of the documentation, change in some naming conventions and
resolution of some namespace issues).
Credits
- David Abrahams originated
and wrote py_cpp.
- Ullrich Koethe
had independently developed a similar system. When he discovered py_cpp,
he generously contributed countless hours of coding and much insight into
improving it. He is responsible for an early version of the support for function overloading and wrote the support for
reflecting C++ inheritance
relationships. He has helped to improve error-reporting from both
Python and C++, and has designed an extremely easy-to-use way of
exposing numeric operators, including
a way to avoid explicit coercion by means of overloading.
- The members of the boost mailing list and the Python community supplied
invaluable early feedback. In particular, Ron Clarke, Mark Evans, Anton
Gluck, Ralf W. Grosse-Kunstleve, Prabhu Ramachandran, and Barry Scott took
the brave step of trying to use py_cpp while it was still in early stages
of development.
- The development of py_cpp wouldn't have been
possible without the generous support of Dragon Systems/Lernout and
Hauspie, Inc who supported its development as an open-source project.
Table of Contents
- A Brief Introduction to writing Python
extension modules
- Comparisons between py_cpp and other
systems for extending Python
- A Simple Example Using py_cpp
- Overridable Virtual Functions
- Function Overloading
- Inheritance
- Special Method and Operator Support
- A Peek Under the Hood
- Building a Module with Py_cpp
- Advanced Topics
- class_builder<>
- enums
- References
- Pointers and Smart Pointers
- Built-in Python Types
- Other Extension Types
- Templates
More sophisticated examples are given in
extclass_demo.cpp, extclass_demo.h, and
test_extclass.py in the source code
archive. There's much more here, and much more documentation to
come...
Questions should be directed to the boost mailing list.
Naming Contest
Yes, I know py_cpp is a lousy name. Problem is, the best names my puny
imagination can muster (IDLE and GRAIL) are taken, so I'm holding a
naming contest. First prize? You get to pick the name<0.2wink> and
you will be credited in the documentation. Names that have been suggested
so far include:
-
Py++
-
Python++
-
Coil
-
SnakeSkin
-
CCCP - Convert C++
Classes to Python
-
C3PO - Convert C++
Classes to Python
Objects
-
PALIN - Python
Augmented-Language
INtegration
-
CLEESE - C++ Language Extension Environment
Supremely Easy
-
JONES - Just Obscenely Neat Extension
System
-
C-thru
-
SeamlessC
-
BorderCrossing
-
Perseus (because he solved a hairy problem involving snakes by using
reflection and was invisible most of the time).
Please post or send me your suggestions!
© Copyright David Abrahams 2000. Permission to copy, use, modify,
sell and distribute this document is granted provided this copyright
notice appears in all copies. This document is provided “as is” without
express or implied warranty, and with no claim as to its suitability for
any purpose.
Updated: Nov 25, 2000