
Kamailio Embedded Interpreter Interface (KEMI) framework was added first in Kamailio v5.0.0 to enable other scripting languages to write the SIP routing logic instead of using the native routing blocks. The interpreters for these scripting languages are embedded in Kamailio, initialized at startup, in this way also being as fast as possible during runtime execution.
The purpose of the KEMI framework is:-
1) Reload configuration without Kamailio restart.
2) Enhance Kamailio’s capability by using more flexible and feature-rich scripting languages.
Kamailio configuration file/s can be divided into two parts:-
1) Static part where we define the tokens (also called variables), load modules, global settings, and module parameters. This part is parsed by Kamailio at startup and loaded in memory.
2) Dynamic part where we define routing logic. Kamailio runs this part every time a message is received.
The idea of using KEMI is to detach the dynamic part and write its code using well-known languages (like python, lua, etc.). In other words, the routing blocks are now functions written in a KEMI-supported scripting language.
Python KEMI Interpreter
There is a module for each supported programming language. For python, there is “app_python” ( for python 2.5 and 2.6), “app_python3”, and “app_python3s” (for python 3.x). The “app_python3s” module is an alternate version of “app_python3” module where the boilerplate code to instantiate the SIP message object is moved in the C code, making it easy to understand and a bit more performant as we don’t spend CPU cycles to instantiate the python object.
To use python 3.x with Kamailio we need to add the following configuration in kamailio.cfg file:-
loadmodule "app_python3.so"
modparam("app_python3","load","/path/to/script.py")
cfgengine "python"
Now create a python script and add the path in the modparam above.
Sample python scripts for python and python3 can be found on the Kamailio GitHub repository here. You can find the core and module python functions here.
In the following article, we will dive deep in KEMI scripting with python, where I will discuss how to build a registrar, so stay tuned!.
Update:- Here is the next article.
Build a SIP Registrar using Python with KEMI framework for Kamailio
Enter your email below to subscribe and get the upcoming article links right in your inbox.
Akash Gupta
Senior VoIP Engineer and AI Enthusiast

AI and VoIP Blog
Thank you for visiting the Blog. Hit the subscribe button to receive the next post right in your inbox. If you find this article helpful don’t forget to share your feedback in the comments and hit the like button. This will helps in knowing what topics resonate with you, allowing me to create more that keeps you informed.
Thank you for reading, and stay tuned for more insights and guides!
Leave a comment