A simple Python AMI client

Python AMI Client
A simple Python AMI client
See the code of conduct.
Install
Install asterisk-ami
pip install asterisk-ami
Install latest asterisk-ami
pip install git+https://github.com/ettoreleandrotognoli/python-ami
Usage
Connect
from asterisk.ami import AMIClient
client = AMIClient(address='127.0.0.1',port=5038)
client.login(username='username',secret='password')
Disconnect
client.logoff()
Send an action
from asterisk.ami import SimpleAction
action = SimpleAction(
'Originate',
Channel='SIP/2010',
Exten='2010',
Priority=1,
Context='default',
CallerID='python',
)
client.send_action(action)
Send an action with adapter
from asterisk.ami import AMIClientAdapter
adapter = AMIClientAdapter(client)
adapter.Originate(
Channel='SIP/2010',
Exten='2010',
Priority=1,
Context='default',
CallerID='python',
)
Synchronous Response
#without adapter
future = client.send_action(action)
response = future.response
#with adapter
future = adapter.Originate(...)
response = future.response
Asynchronous Response
def callback_response(response):
print(response)
#without adapter
future = client.send_action(action,callback=callback_response)
#with adapter
future = adapter.Originate(...,_callback=callback_response)
#you can use the future to