| 1 |
app_python Module |
| 2 |
|
| 3 |
Maxim Sobolev |
| 4 |
|
| 5 |
Edited by |
| 6 |
|
| 7 |
Maxim 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 |
|
| 45 |
Chapter 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 |
|
| 71 |
1. 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 |
|
| 80 |
As python2 is deprecated in Debian and other distributions, please use |
| 81 |
the “app_python3” module instead. This module will be removed in a |
| 82 |
future release. |
| 83 |
|
| 84 |
2. Dependencies |
| 85 |
|
| 86 |
2.1. Kamailio Modules |
| 87 |
2.2. External Libraries or Applications |
| 88 |
|
| 89 |
2.1. Kamailio Modules |
| 90 |
|
| 91 |
The following modules must be loaded before this module: |
| 92 |
* none. |
| 93 |
|
| 94 |
2.2. External Libraries or Applications |
| 95 |
|
| 96 |
The following libraries or applications must be installed before |
| 97 |
running Kamailio with this module loaded: |
| 98 |
* python-dev - Python devel library. |
| 99 |
|
| 100 |
3. Parameters |
| 101 |
|
| 102 |
3.1. load (string) |
| 103 |
3.2. script_name (string) |
| 104 |
3.3. mod_init_function (string) |
| 105 |
3.4. child_init_method (string) |
| 106 |
|
| 107 |
3.1. load (string) |
| 108 |
|
| 109 |
The path to the file with Python code to be executed from configuration |
| 110 |
file. |
| 111 |
|
| 112 |
Default value is “/usr/local/etc/kamailio/handler.py”. |
| 113 |
|
| 114 |
Example 1.1. Set load parameter |
| 115 |
... |
| 116 |
modparam("app_python", "load", "/usr/local/etc/kamailio/myscript.py") |
| 117 |
... |
| 118 |
|
| 119 |
3.2. script_name (string) |
| 120 |
|
| 121 |
This is same as "load" parameter, kept for backward compatibility with |
| 122 |
the older versions of the module. |
| 123 |
|
| 124 |
3.3. mod_init_function (string) |
| 125 |
|
| 126 |
The Python function to be executed by this module when it is |
| 127 |
initialized by Kamailio. |
| 128 |
|
| 129 |
Default value is “mod_init”. |
| 130 |
|
| 131 |
Example 1.2. Set mod_init_function parameter |
| 132 |
... |
| 133 |
modparam("app_python", "mod_init_function", "my_mod_init") |
| 134 |
... |
| 135 |
|
| 136 |
3.4. child_init_method (string) |
| 137 |
|
| 138 |
The Python function to be executed by this module when a new worker |
| 139 |
process (child) is initialized by Kamailio. |
| 140 |
|
| 141 |
Default value is “child_init”. |
| 142 |
|
| 143 |
Example 1.3. Set child_init_method parameter |
| 144 |
... |
| 145 |
modparam("app_python", "child_init_method", "my_child_init") |
| 146 |
... |
| 147 |
|
| 148 |
4. Functions |
| 149 |
|
| 150 |
4.1. python_exec(method [, args]) |
| 151 |
|
| 152 |
4.1. python_exec(method [, args]) |
| 153 |
|
| 154 |
Execute the Python function with the name given by the parameter |
| 155 |
'method'. Optionally can be provided a second string with parameters to |
| 156 |
be passed to the Python function. |
| 157 |
|
| 158 |
Both parameters can contain pseudo-variables. |
| 159 |
|
| 160 |
Example 1.4. python_exec usage |
| 161 |
... |
| 162 |
python_exec("my_python_function"); |
| 163 |
python_exec("my_python_function", "my_params"); |
| 164 |
python_exec("my_python_function", "$rU"); |
| 165 |
... |
| 166 |
|
| 167 |
5. RPC Commands |
| 168 |
|
| 169 |
5.1. app_python.reload |
| 170 |
5.2. app_python.api_list |
| 171 |
|
| 172 |
5.1. app_python.reload |
| 173 |
|
| 174 |
Marks the need to reload the Python script. The actual reload is done |
| 175 |
by each worker when the next Python method is invoked. |
| 176 |
|
| 177 |
Name: app_python.reload |
| 178 |
|
| 179 |
Parameters: none |
| 180 |
|
| 181 |
Example: |
| 182 |
... |
| 183 |
kamctl rpc app_python.reload |
| 184 |
... |
| 185 |
|
| 186 |
5.2. app_python.api_list |
| 187 |
|
| 188 |
List the functions available via Kemi framework. |
| 189 |
|
| 190 |
Name: app_python.api_list |
| 191 |
|
| 192 |
Parameters: none |
| 193 |
|
| 194 |
Example: |
| 195 |
... |
| 196 |
kamctl rpc app_python.api_list |
| 197 |
... |