This release is a pre-release and may not be stable for production use.
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 wait the callback execute
reponse = future.response
Listen Events
def event_listener(event,**kwargs):
print(event)
client.add_event_listener(event_listener)
Filter Events
With a custom class
from asterisk.ami import EventListener
class RegistryEventListener(EventListener):
def on_Registry(event,**kwargs):
print('Registry Event',event)
client.add_event_listener(RegistryEventListener())
class AllEventListener(EventListener):
def on_event(event,**kwargs):
print('Event',event)
client.add_event_listener(AllEventListener())
With black or white list
def event_listener(event,**kwargs):
print(event)
client.add_event_listener(
event_listener, white_list=['Registry','PeerStatus']
)
client.add_event_listener(
event_listener, black_list=['VarSet']
)
Like a custom class
def event_listener(event,**kwargs):
print(event)
client.add_event_listener(
on_VarSet=event_listener,
on_ExtensionStatus=event_listener
)
client.add_event_listener(
on_event=event_listener
)
Filter Event Value
def event_listener(event,**kwargs):
print('Ringing',event)
client.add_event_listener(
event_listener,
white_list='Newstate',
ChannelStateDesc='Ringing',
ConnectedLineNum='2004',
)
Filter with regex
import re
def event_listener(event,**kwargs):
print(event)
client.add_event_listener(
on_Newstate=event_listener,
white_list=re.compile('.*'),
ChannelStateDesc=re.compile('^Ring.*'),
)
Metadata
Release files for asterisk-ami 0.2.dev1649957067
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| asterisk-ami-0.2.dev1649957067.tar.gz | 9.7 kB | Without provenance | Details |
Release files / asterisk-ami-0.2.dev1649957067.tar.gz
| Download URL | asterisk-ami-0.2.dev1649957067.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21eee492cea7b4ea751f85593985f37824bf1664d8d3ea947cbbacaae27686b9
|
|
BLAKE2b-256 checksum How to use checksums |
c7e1a5a2519a556078e46c3866c76857514756a7454a0d2d0d71726655f364c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.2
|
Security for asterisk-ami 0.2.dev1649957067
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.