In this book, the term integration has largely meant mixing Python with components written in C or C++ (or other C-compatible languages) in extending and embedding modes. But from a broader perspective, integration also includes any other technology that lets us mix Python components into larger systems. This last section briefly looks at a handful of integration technologies beyond the C API tools we’ve seen in this part of the book.
We met JPython in Chapter 15but it is worth another mention in the context of integration at large. As we saw earlier, JPython supports two kinds of integration:
JPython uses Java’s reflection API to allow Python programs to call out to Java class libraries automatically (extending). The Java reflection API provides Java type information at runtime, and serves the same purpose as the glue code we’ve generated to plug C libraries into Python in this part of the book. In JPython, however, this runtime type information allows largely automated resolution of Java calls in Python scripts -- no glue code has to be written or generated.
JPython also provides a Java
PythonInterpreter class API that allows Java
programs to run Python code in a namespace (embedding), much like the
C API tools we’ve used to run Python code strings from C
programs. In addition, because JPython implements all Python objects
as instances of a Java
PyObject class, it is straightforward for the Java layer that encloses ...