pystrix
pystrix is a versatile Asterisk interface package for AMI and (Fast)AGI needs. Ivrnet, inc. published it as open source under the LGPLv3, and contributions from all users are welcome.
Overview
pystrix runs on Python 3.9+. It targets Asterisk 1.10+ and provides a rich, easy-to-extend set of bindings for three Asterisk integration protocols:
- AMI (Asterisk Manager Interface) — a persistent TCP connection for controlling and monitoring the whole server. Originate calls, hang them up, read channel status, and react to live events.
- AGI (Asterisk Gateway Interface) — per-call scripting over stdin and stdout. Drive the dialplan of a single call: play audio, collect digits, set variables.
- FastAGI — the same call scripting as AGI, served from a long-running threaded TCP server instead of a process spawned per call.
The package is a toolkit, not a framework. You can drop it into a larger project without adopting an async framework such as Twisted.
This repository is version 1.3.0. The canonical version lives in pystrix/__init__.py. New releases follow <major>.<minor>.<patch>, with a patch release cut for each bug fix.
Compatibility
| pystrix | Python |
|---|---|
| 1.3.x | 3.9 – 3.13 |
| 1.2.0 and earlier | 2.7, 3.4+ (legacy, unmaintained) |
From 1.3.0 on, the requires-python metadata makes pip resolve automatically: a project on an older Python receives 1.2.x. All versions target Asterisk 1.10+.
Installation
From PyPI:
pip install pystrix
From GitHub:
pip install git+https://github.com/IVRTech/pystrix.git#egg=pystrix
Quick start
AGI — script a single call
#!/usr/bin/env python
import pystrix
if __name__ == '__main__':
agi = pystrix.agi.AGI()
agi.execute(pystrix.agi.core.Answer()) # Answer the call
# Play a file; DTMF '1' or '2' interrupts playback
response = agi.execute(
pystrix.agi.core.StreamFile('demo-thanks', escape_digits=('1', '2'))
)
if response: # Playback was interrupted
(dtmf_character, offset) = response
agi.execute(pystrix.agi.core.Hangup()) # Hang up
FastAGI — serve many calls from one process
import re
import pystrix
server = pystrix.agi.FastAGIServer()
def demo_handler(agi, args, kwargs, match, path):
agi.execute(pystrix.agi.core.Answer())
agi.execute(pystrix.agi.core.StreamFile('demo-thanks'))
agi.execute(pystrix.agi.core.Hangup())
server.register_script_handler(re.compile('demo'), demo_handler)
server.register_script_handler(None, demo_handler) # default handler
server.serve_forever()
The FastAGI server sizes its listen backlog from the system SOMAXCONN value, so it absorbs large bursts of simultaneous calls. It reads that value with sysctl, so the server currently runs on Linux and macOS only. AMI and AGI have no such restriction.
AMI — control and monitor the server
import pystrix
manager = pystrix.ami.Manager()
manager.connect('localhost')
# Authenticate with an MD5 challenge to avoid sending the password in plain text
challenge = manager.send_action(pystrix.ami.core.Challenge())
manager.send_action(pystrix.ami.core.Login(
'username', 'password', challenge=challenge.result['Challenge'],
))
# React to events as Asterisk emits them
def on_hangup(event, manager):
print('Channel hung up:', event.get('Channel'))
manager.register_callback(pystrix.ami.core_events.Hangup, on_hangup)
Full, commented examples for all three protocols live in doc/examples/.
Documentation
Online documentation is available at http://pystrix.readthedocs.io/.
Inline documentation is complete and written in reStructuredText, so the source stays readable.
For an architecture overview and contributor guidance, see AGENTS.md.
Contributing
pystrix has no third-party runtime dependencies, so setup is short.
git clone https://github.com/IVRTech/pystrix.git
cd pystrix
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[test]'
The editable install (-e) means your local edits take effect without reinstalling.
A few things to know before you send a change:
- Run the tests with
pytest. CI runs them across Python 3.9 through 3.13 on every pull request. There is no live-Asterisk integration test, so socket-level behavior is still worth checking against a real server (AMI on port 5038, FastAGI on port 4573). - Lint and format with ruff.
ruff check .andruff format --check .must pass, and CI enforces both. Install the hooks to run them on each commit:pip install pre-commit && pre-commit install. - Target Python 3.9+. The codebase is Python 3 only; the old Python 2 compatibility shims have been removed, so don't reintroduce them.
- Build the docs when you touch them:
pip install -r doc/requirements.txt, thencd doc && make html. - Version bumps go in
pystrix/__init__.py.pyproject.tomlreadsVERSIONfrom there dynamically. - Keep docstrings complete and written in reStructuredText. The reference docs are generated from them.
License
pystrix is licensed under the GNU Lesser General Public License v3 or later (COPYING.LESSER). The LGPL extends the GNU General Public License v3 (COPYING), so both license texts ship with the project.
Credits
Neil Tallim created pystrix, and Ivrnet, inc. funded its initial development. For the full list of contributors, see the contributors page or the commit history.
Metadata
Release files for pystrix 1.3.0
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 | Actions |
|---|---|---|---|---|
| pystrix-1.3.0.tar.gz | 78.6 kB | With provenance | Details for pystrix-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pystrix-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for pystrix-1.3.0-py3-none-any.whl |
Total release size: 162.2 kB
Release files / pystrix-1.3.0.tar.gz
| Download URL | pystrix-1.3.0.tar.gz |
|---|---|
| Size | 78.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61afc0983808aff1b7763bbee5a5d3b746792f5e985168aed7352b8d7fae1c2f
|
|
BLAKE2b-256 checksum How to use checksums |
1117b8570a9bb5e8e4c47c4fe8cefcfeabb544a3c0a4b7f3e831438b87260e07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency logRelease files / pystrix-1.3.0-py3-none-any.whl
| Download URL | pystrix-1.3.0-py3-none-any.whl |
|---|---|
| Size | 83.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77819dea68f7d31eb78a5019f39256122a5e15f113899224fb9374e196ffdfff
|
|
BLAKE2b-256 checksum How to use checksums |
d11f2e21688d0455fb3bc4ff8872d705dc28a29d0d4f33516cc848344b19b178
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency logSecurity for pystrix 1.3.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pystrix-1.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency logA 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.