Python EAGI with modules

Is it possible to use custom python modules when using EAGI in my dialplan?
I have broken down a script into modules and it no longer works.

if I do a python I see that the file executes without import errors, crashing at a point where I am trying to read from the file descriptor 3, because that would be available only if it were running as an EAGI script.

Short answer: yes.

I followed this doc:

and tried to avoid using the while 1 logic here:

while 1:
   line = sys.stdin.readline().strip()

   if line == '':
   key,data = line.split(':')
   if key[:4] <> 'agi_':
      #skip input that doesn't begin with agi_
      sys.stderr.write("Did not work!\n");
   key = key.strip()
   data = data.strip()
   if key <> '':
      env[key] = data


while line != '':
    key, data = line.split(':')
    key = key.strip()
    data = data.strip()

    if 'agi_' != key[:4]:
        __console.err('Did not work for ' + key)

    env[key] = data
    line = sys.stdin.readline().strip() # I had forgotten to add this line leading to an infinite loop
  • I didn’t add my python code as this would be the wrong place for solving those issues.
  • The script worked when I used python because there was nothing for the stdin to read.

If your file structure is so:


and you have imported any of the modules, then while AGI/EAGI runs the file at root ( the imports just work.

You example code does not show any module usage examples. This also seems more a question about python not AGI/EAGI. Best guess, your picking up some environment variable from the CLI that lets you access the module, and environment variable which Asterisk does not provide.

You probably want to explicitly call a module as a class.

import module_1
import module_1/module_1.1

# your code

At the end, the documentation references pyst, which has not been maintained since 2013. But you should consider using pyst2, instead of reinventing the wheel.


At a minimum, look to pyst2 for code examples. pyst2 should solve most of your problems.

1 Like