1app_python Module 2 3Maxim Sobolev 4 5Edited by 6 7Maxim Sobolev 8 9 Copyright © 2010 Maxim Sobolev 10 __________________________________________________________________ 11 12 Table of Contents 13 14 1. Admin Guide 15 16 1. Overview 17 2. Dependencies 18 19 2.1. Kamailio Modules 20 2.2. External Libraries or Applications 21 22 3. Parameters 23 24 3.1. load (string) 25 3.2. script_name (string) 26 3.3. mod_init_function (string) 27 3.4. child_init_method (string) 28 29 4. Functions 30 31 4.1. python_exec(method [, args]) 32 33 5. RPC Commands 34 35 5.1. app_python.reload 36 5.2. app_python.api_list 37 38 List of Examples 39 40 1.1. Set load parameter 41 1.2. Set mod_init_function parameter 42 1.3. Set child_init_method parameter 43 1.4. python_exec usage 44 45Chapter 1. Admin Guide 46 47 Table of Contents 48 49 1. Overview 50 2. Dependencies 51 52 2.1. Kamailio Modules 53 2.2. External Libraries or Applications 54 55 3. Parameters 56 57 3.1. load (string) 58 3.2. script_name (string) 59 3.3. mod_init_function (string) 60 3.4. child_init_method (string) 61 62 4. Functions 63 64 4.1. python_exec(method [, args]) 65 66 5. RPC Commands 67 68 5.1. app_python.reload 69 5.2. app_python.api_list 70 711. Overview 72 73 This module allows executing Python scripts from config file, exporting 74 functions to access the SIP message from Python. 75 76 For some basic examples of Python scripts that can be used with this 77 module, look at the files inside source tree located at 78 'modules/app_python/python_examples/'. 79 802. Dependencies 81 82 2.1. Kamailio Modules 83 2.2. External Libraries or Applications 84 852.1. Kamailio Modules 86 87 The following modules must be loaded before this module: 88 * none. 89 902.2. External Libraries or Applications 91 92 The following libraries or applications must be installed before 93 running Kamailio with this module loaded: 94 * python-dev - Python devel library. 95 963. Parameters 97 98 3.1. load (string) 99 3.2. script_name (string) 100 3.3. mod_init_function (string) 101 3.4. child_init_method (string) 102 1033.1. load (string) 104 105 The path to the file with Python code to be executed from configuration 106 file. 107 108 Default value is “/usr/local/etc/kamailio/handler.py”. 109 110 Example 1.1. Set load parameter 111... 112modparam("app_python", "load", "/usr/local/etc/kamailio/myscript.py") 113... 114 1153.2. script_name (string) 116 117 This is same as "load" parameter, kept for backward compatibility with 118 the older versions of the module. 119 1203.3. mod_init_function (string) 121 122 The Python function to be executed by this module when it is 123 initialized by Kamailio. 124 125 Default value is “mod_init”. 126 127 Example 1.2. Set mod_init_function parameter 128... 129modparam("app_python", "mod_init_function", "my_mod_init") 130... 131 1323.4. child_init_method (string) 133 134 The Python function to be executed by this module when a new worker 135 process (child) is initialized by Kamailio. 136 137 Default value is “child_init”. 138 139 Example 1.3. Set child_init_method parameter 140... 141modparam("app_python", "child_init_method", "my_child_init") 142... 143 1444. Functions 145 146 4.1. python_exec(method [, args]) 147 1484.1. python_exec(method [, args]) 149 150 Execute the Python function with the name given by the parameter 151 'method'. Optionally can be provided a second string with parameters to 152 be passed to the Python function. 153 154 Both parameters can contain pseudo-variables. 155 156 Example 1.4. python_exec usage 157... 158python_exec("my_python_function"); 159python_exec("my_python_function", "my_params"); 160python_exec("my_python_function", "$rU"); 161... 162 1635. RPC Commands 164 165 5.1. app_python.reload 166 5.2. app_python.api_list 167 1685.1. app_python.reload 169 170 Marks the need to reload the Python script. The actual reload is done 171 by each worker when the next Python method is invoked. 172 173 Name: app_python.reload 174 175 Parameters: none 176 177 Example: 178... 179kamcmd app_python.reload 180... 181 1825.2. app_python.api_list 183 184 List the functions available via Kemi framework. 185 186 Name: app_python.api_list 187 188 Parameters: none 189 190 Example: 191... 192kamcmd app_python.api_list 193... 194