# &adminguide;

## Overview

This module allows executing Python scripts from config file, exporting functions to access the SIP message from Python.

For some basic examples of Python scripts that can be used with this module, look at the files inside source tree located at 'modules/app_python/python_examples/'.

As python2 is deprecated in Debian and other distributions, please use the app_python3 module instead. This module will be removed in a future release.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- none.

### External Libraries or Applications

The following libraries or applications must be installed before running &kamailio; with this module loaded:

- python-dev - Python devel library.

## Parameters

### `load` (string)

The path to the file with Python code to be executed from configuration file.

Default value is /usr/local/etc/kamailio/handler.py.

#### Set `load` parameter

    ...
    modparam("app_python", "load", "/usr/local/etc/kamailio/myscript.py")
    ...

### `script_name` (string)

This is same as "load" parameter, kept for backward compatibility with the older versions of the module.

### `mod_init_function` (string)

The Python function to be executed by this module when it is initialized by &kamailio;.

Default value is mod_init.

#### Set `mod_init_function` parameter

    ...
    modparam("app_python", "mod_init_function", "my_mod_init")
    ...

### `child_init_method` (string)

The Python function to be executed by this module when a new worker process (child) is initialized by &kamailio;.

Default value is child_init.

#### Set `child_init_method` parameter

    ...
    modparam("app_python", "child_init_method", "my_child_init")
    ...

## Functions

### `python_exec(method [, args])`

Execute the Python function with the name given by the parameter 'method'. Optionally can be provided a second string with parameters to be passed to the Python function.

Both parameters can contain pseudo-variables.

#### `python_exec` usage

    ...
    python_exec("my_python_function");
    python_exec("my_python_function", "my_params");
    python_exec("my_python_function", "$rU");
    ...

## RPC Commands

### `app_python.reload`

Marks the need to reload the Python script. The actual reload is done by each worker when the next Python method is invoked.

Name: app_python.reload

Parameters: none

Example:

    ...
    &kamcmd; app_python.reload
    ...

### `app_python.api_list`

List the functions available via Kemi framework.

Name: app_python.api_list

Parameters: none

Example:

    ...
    &kamcmd; app_python.api_list
    ...