Skip to main content

Python ESL


The Python ESL module allows for native interaction with FreeSWITCH over the event socket interface. It allows for sending commands, receiving output and sending and receiving events and IVR interaction from the FreeSWITCH server.
The Python ESL module is an auto-generated swig python module with a binary component to it.
You CANNOT just copy the PM file and use that, you must properly compile the module and get the file generated also (which must be kept in the same directory as the

NOTE: any time a change to libesl occurs you will need to re-make and install the python ESL module or else things may break or work un-expectedly.

In the FreeSWITCH source directory change to libs/esl and run:

make pymod
make pymod-install

This should install the ESL module into your python site-packages folder. If for some reason you want to manually install it or keep it locally you still must run the make pymod command to compile it but then can copy the libs/esl/ and libs/esl/ to a folder of your choosing.

See the "Pre-requisites" section at the ESL page for the libraries needed.

Install from PyPi

You can alternatively install a specific well tested version of this module from the Python Package Index.
The libesl code is directly from FreeSWITCH 1.4.18 and is packaged using setuptools native SWIG support.
It can be downloaded using pip:

pip install python-ESL


The python module provides two classes: ESLconnection and ESLevent. They are documented generally (non-python specific) at the ESL page, in the "ESL Object" section.

You will want to first include the module:

import ESL

You can then establish a connection using:

con = ESL.ESLconnection("", "8021", "ClueCon")


#!/usr/bin/env python

''' - subscribe to all events and print them to stdout
import ESL

con = ESL.ESLconnection('localhost', '8021', 'ClueCon')

if con.connected():'plain', 'all')
while 1:
e = con.recvEvent()
if e:
print e.serialize()
#!/usr/bin/env python

import SocketServer
import ESL

class ESLRequestHandler(SocketServer.BaseRequestHandler):
def setup(self):
print self.client_address, 'connected!'

fd = self.request.fileno()
print fd

con = ESL.ESLconnection(fd)
print 'Connected: ', con.connected()
if con.connected():

info = con.getInfo()

uuid = info.getHeader("unique-id")
print uuid
con.execute("answer", "", uuid)
con.execute("playback", "/ram/swimp.raw", uuid);

# server host is a tuple ('host', port)
server = SocketServer.ThreadingTCPServer(('', 8040), ESLRequestHandler)

#!/usr/bin/env python

''' - execute a single command over ESL
from optparse import OptionParser
import sys

import ESL

def main(argv):
parser = OptionParser()
parser.add_option('-a', '--auth', dest='auth', default='ClueCon',
help='ESL password')
parser.add_option('-s', '--server', dest='server', default='',
help='FreeSWITCH server IP address')
parser.add_option('-p', '--port', dest='port', default='8021',
help='FreeSWITCH server event socket port')
parser.add_option('-c', '--command', dest='command', default='status',
help='command to run, surround multi-word commands in ""s')

(options, args) = parser.parse_args()

con = ESL.ESLconnection(options.server, options.port, options.auth)

if not con.connected():
print 'Not Connected'

# Run command
e = con.api(options.command)
if e:
print e.getBody()

if __name__ == '__main__':