5.4.3 PythonImport

##
5.4.3 PythonImport

Syntax: PythonImport module interpreter_name
Context: server config
Module: mod_python.c

Tells the server to import the Python module module at process startup under the specified interpreter name. The import takes place at child process initialization, so the module will actually be imported once for every child process spawned.

The module can be a full module name (package dot notation is accepted) or an absolute path to a module code file. The module is loaded using the mod_python module importer as implemented by the `apache.import_module()` function. Reference should be made to the documentation of that function for further details of how module importing is managed.

The `PythonImport` directive is useful for initialization tasks that could be time consuming and should not be done at the time of processing a request, e.g. initializing a database connection. Where such initialization code could fail and cause the importing of the module to fail, it should be placed in its own function and the alternate syntax used:

`PythonImport module::function interpreter_name`

The named function will be called only after the module has been imported successfully. The function will be called with no arguments.

Note: At the time when the import takes place, the configuration is not completely read yet, so all other directives, including PythonInterpreter have no effect on the behavior of modules imported by this directive. Because of this limitation, the interpreter must be specified explicitly, and must match the name under which subsequent requests relying on this operation will execute. If you are not sure under what interpreter name a request is running, examine the `interpreter` member of the request object.

See also Multiple Interpreters.