Skip to main content

aionecpbx

Async Python clients for NEC SL2100 and SV9100 phone systems, and for live calls through FreePBX.

  • SmdrClient keeps a connection to the phone system's SMDR (call log) port open, reconnects by itself, and hands over each line.
  • parse_line turns an SMDR line into an SmdrRecord: direction, start, ring and talk time, line, extension, number, and whether it was missed. It works on tokens rather than fixed columns, so the different 35-01 and 35-02 layouts read the same way, and it never raises.
  • AmiClient follows calls through FreePBX's Asterisk Manager Interface as they ring, are answered and end, and turns do-not-disturb on and off per extension.

Standard library only. Python 3.12 or later. It powers the NEC PBX integration for Home Assistant.

Install

pip install aionecpbx

Call log (SMDR)

Turn SMDR on in the phone system first (PC Pro or WebPro):

Program Setting
10-20, type 5 SMDR output TCP port: 4001 on Australian systems
35-01-01 Output port: LAN
35-02-08 Print incoming calls: on (or you won't see incoming or missed calls)

Only one program can hold the SMDR port at a time.

import asyncio
from aionecpbx import SmdrClient, parse_line


def on_line(line: str) -> None:
    record = parse_line(line, extensions={"103": "Kitchen"}, phonebook={"0491570156": "Alex"})
    if record:
        print(
            record.direction, record.station_name, record.number, record.caller_name, record.missed
        )


async def main() -> None:
    client = SmdrClient("192.168.0.10", 4001, on_line)
    client.start()
    await asyncio.sleep(3600)
    await client.stop()


asyncio.run(main())

A record is only written when a call ends. For calls as they ring, use FreePBX below.

Live calls (FreePBX)

In FreePBX, Settings > Asterisk Manager Users > Add Manager: permit your address, and give it at least read call and system, and write system for do-not-disturb.

from aionecpbx import AmiClient, LiveCall


def on_change(call: LiveCall, what: str) -> None:
    print(what, call.caller_number, call.caller_name, call.extension)  # ringing / answered / ended


client = AmiClient("192.168.0.20", 5038, "homeassistant", "secret", on_change)
client.start()
...
await client.set_dnd("103", True)

A rejected login stops the client rather than retrying, so it can't lock the manager user out. async_test_login() checks a login once.

Command line

aionecpbx parse "IC 0001  10:00  001   00:01:00  103   0491570156   0:08"
aionecpbx listen 192.168.0.10            # print each call as JSON as it ends
aionecpbx ami 192.168.0.20 --username homeassistant --secret ...

Development

pip install -e ".[test,lint]"
pytest --cov=aionecpbx
ruff check . && ruff format --check . && mypy

Releases are automatic: bump __version__ in src/aionecpbx/__init__.py, add a CHANGELOG.md section, and push to main.

Licence

MIT. See NOTICE for trademarks.

Metadata

Release files for aionecpbx 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aionecpbx 0.2.1
File Size Uploaded Provenance Actions
aionecpbx-0.2.1.tar.gz 22.2 kB With provenance Details for aionecpbx-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aionecpbx 0.2.1
File Interpreter ABI Platform Actions
aionecpbx-0.2.1-py3-none-any.whl Python 3 none any Details for aionecpbx-0.2.1-py3-none-any.whl

Total release size: 40.0 kB

Release files / aionecpbx-0.2.1.tar.gz

Download URL aionecpbx-0.2.1.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
43d9130b2b22acf1baf6ab372f56cafd05ae4ea315ea4e9fdce18f4f7a7a4f88
BLAKE2b-256 checksum
How to use checksums
0dbbd10b0288203c6d2f3b5a1309eb13cba47f568e5812cd564c78186fc680c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Release files / aionecpbx-0.2.1-py3-none-any.whl

Download URL aionecpbx-0.2.1-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c33d454beb9c1cd543d3bbf71a69b455551d28d800e1bc89901b5d5c18b02118
BLAKE2b-256 checksum
How to use checksums
ceae25ab09a77f46c8fba354aca53d0bb17286bf078a138fe5b2f53c8e80d3a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for aionecpbx 0.2.1

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aionecpbx-0.2.1.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 Nov 22, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page