Skip to content

Commit

Permalink
modules: readme files regenerated - app_python3 ... [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
kamailio-dev committed Dec 5, 2022
1 parent 0f36ffb commit ca48d23
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
18 changes: 18 additions & 0 deletions src/modules/app_python3/README
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Maxim Sobolev
5.1. app_python.reload
5.2. app_python.api_list

6. KEMI Usage

List of Examples

1.1. Set load parameter
Expand Down Expand Up @@ -70,6 +72,8 @@ Chapter 1. Admin Guide
5.1. app_python.reload
5.2. app_python.api_list

6. KEMI Usage

1. Overview

This module is a port of the 'app_python' module to Python 3. It is
Expand Down Expand Up @@ -238,3 +242,17 @@ def mod_init():
...
kamcmd app_python.api_list
...

6. KEMI Usage

The module exports KEMI engine with id "python".

Example:
...
loadmodule "app_python3.so"
...
cfgengine "python"
...

For more details about KEMI, see:
https://www.kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/
65 changes: 51 additions & 14 deletions src/modules/app_python3s/README
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Edited by

Daniel-Constantin Mierla

Copyright 2022 kamailio.org
Copyright © 2022 kamailio.org
__________________________________________________________________

Table of Contents
Expand All @@ -26,6 +26,7 @@ Daniel-Constantin Mierla
3. Parameters

3.1. load (string)
3.2. script_init (string)

4. Functions

Expand All @@ -36,10 +37,13 @@ Daniel-Constantin Mierla
5.1. app_python.reload
5.2. app_python.api_list

6. KEMI Usage

List of Examples

1.1. Set load parameter
1.2. app_python3s_exec usage
1.2. Set script_init parameter
1.3. app_python3s_exec usage

Chapter 1. Admin Guide

Expand All @@ -54,6 +58,7 @@ Chapter 1. Admin Guide
3. Parameters

3.1. load (string)
3.2. script_init (string)

4. Functions

Expand All @@ -64,15 +69,16 @@ Chapter 1. Admin Guide
5.1. app_python.reload
5.2. app_python.api_list

6. KEMI Usage

1. Overview

This module is an alternative 'app_python3' module with static export
of 'KSR' object and functions.
of 'KSR' object and functions, without instantiating the SIP message
object.

This module cannot be loaded together with 'app_python3' as global
symbols have not been renamed. To ease transition, the functions, KEMI
exports, and RPC commands have the same names as 'app_python3', which
also means the two modules cannot coexist.
This module cannot be loaded together with 'app_python3' as some global
symbols conflict.

This module allows executing Python3 scripts from the config file,
exporting functions to access the SIP message from Python3.
Expand Down Expand Up @@ -107,32 +113,49 @@ Chapter 1. Admin Guide
3. Parameters

3.1. load (string)
3.2. script_init (string)

3.1. 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".
Default value is /usr/local/etc/kamailio/kamailio.py.

Example 1.1. Set load parameter
...
modparam("app_python3s", "load", "/usr/local/etc/kamailio/myscript.py")
...

3.2. script_init (string)

The name of the Python function to be executed when the script is
loaded or reloaded.

Default value is “” (not set).

Example 1.2. Set script_init parameter
...
modparam("app_python3s", "script_init", "ksr_script_init")
...
def ksr_script_init():
KSR.info("init python script\n")
return 1
...

4. Functions

4.1. app_python3s_exec(method [, param])

4.1. app_python3s_exec(method [, param])
4.1. app_python3s_exec(method [, param])

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

Both parameters can contain pseudo-variables.

Example 1.2. app_python3s_exec usage
Example 1.3. app_python3s_exec usage
...
app_python3s_exec("my_python_function");
app_python3s_exec("my_python_function", "my_params");
Expand All @@ -144,7 +167,7 @@ app_python3s_exec("my_python_function", "$rU");
5.1. app_python.reload
5.2. app_python.api_list

5.1. app_python.reload
5.1. app_python.reload

IMPORTANT: this is not thread-safe. In your Python script do not use C
extensions with threads that call into apy_exec().
Expand All @@ -168,14 +191,14 @@ kamcmd app_python3s.reload

Note that reload is done for the Python script provided as parameter to
this Kamailio module. To reload the Python libraries imported in this
script, use something like:
script, leverage "script_init" and use something like:
...
import mod1
...
import modN
from importlib import reload

def mod_init():
def ksr_script_init():
reload(mod1)
...
reload(modN)
Expand All @@ -184,7 +207,7 @@ def mod_init():

Where "modX" are the modules imported at the top.

5.2. app_python.api_list
5.2. app_python.api_list

List the functions available via Kemi framework.

Expand All @@ -196,3 +219,17 @@ def mod_init():
...
kamcmd app_python3s.api_list
...

6. KEMI Usage

The module exports KEMI engine with id "python".

Example:
...
loadmodule "app_python3s.so"
...
cfgengine "python"
...

For more details about KEMI, see:
https://www.kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/

0 comments on commit ca48d23

Please sign in to comment.