Other Integration Topics
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.
Jython: Java Integration
We met Jython in Chapter 18 but it is worth another mention in the context of integration at large. As we saw earlier, Jython supports two kinds of integration:
Jython 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 Jython, however, this runtime type information allows largely automated resolution of Java calls in Python scripts—no glue code has to be written or generated.
Jython also provides a Java
PythonInterpreterclass 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 Jython implements all Python objects as instances of a JavaPyObjectclass, it is straightforward for the Java layer that encloses embedded Python code to process ...