Extensibility

It is easy to add new built-in modules written in C to the Python interpreter. Extensions appear to the Python user as built-in modules. Using a built-in module is no different from using a module written in Python, but obviously the author of a built-in module can do things that cannot be implemented purely in Python.

In particular, built-in modules can contain Python-callable functions that call functions from particular system libraries (`wrapper functions'), and they can define new object types. In general, if a built-in module defines a new object type, it should also provide at least one function that creates such objects. Attributes of such object types are also implemented in C; they can return data associated with the object or methods, implemented as C functions.

For instance, an extension was created for Amoeba: it provides wrapper functions for the basic Amoeba name server functions, and defines a `capability' object type, whose methods are file server operations. Another extension is a built-in module called posix; it provides wrappers around post UNIX system calls. Extension modules also provide access to two different windowing/graphics interfaces: STDWIN [#!STDWIN!#] (which connects to X11 on UNIX and to the Mac Toolbox on the Macintosh), and the Graphics Library (GL) for Silicon Graphics machines.

Any function in an extension module is supposed to type-check its arguments; the interpreter contains a convenience function to facilitate extracting C values from arguments and type-checking them at the same time. Returning values is also painless, using standard functions to create Python objects from C values.

On some systems extension modules may be dynamically loaded, thus avoiding the need to maintain a private copy of the Python interpreter in order to use a private extension.