Skip to main content

siphon-control (Python)

Python client for the SIPhon external control plane (siphon-control.v1) — an ARI/ESL-class rail for driving handed-over calls out of process. Built with PyO3 over the async Rust client, so the wire is hidden: no manual JSON, no request-id bookkeeping.

Two connection modes

The plane runs in one of two modes; both are exposed here and share the SAME @on_call decorator and the SAME Call handle — only the transport differs.

  • Inbound-persistent (ControlClient) — the app dials siphon and holds one long-lived socket (does the hello handshake). Simplest to reason about; use it for development and single-process controllers.
  • Per-call-connect (ControlServer) — siphon dials the app per handed-over call, so the app is a WebSocket server. Each accepted connection owns exactly one call and the first frame is a pushed StasisStart (no hello). This is the documented production default for multi-pod controllers: because the accepting socket is the call, "the audio lands on the wrong pod" can't happen.

Inbound-persistent

import asyncio
from siphon_control import ControlClient, ControlError

client = ControlClient(app="ivr-app", token="s3cr3t",
                       url="ws://siphon:9090/control/ws")

@client.on_call
async def handle(call):
    await call.answer()
    try:
        await call.transfer("sip:agent@pbx")   # REFER, awaits correlated reply
    except ControlError as error:
        print("transfer rejected:", error.code)

async def main():
    async with client:          # closes on the way out — see Shutdown below
        await client.run()

asyncio.run(main())

Application-level events

Events an app opts into with control.apps[].events (RegistrationChanged, DialogStateChanged) concern no call, so they never reach on_call. Register a handler for them; run() installs it:

@client.on_app_event
async def on_app_event(event, payload):
    if event == "DialogStateChanged":
        print(payload["aor"], payload["state"])   # early / confirmed / terminated

Per-call-connect

import asyncio
from siphon_control import ControlServer, ControlError

server = ControlServer(app="ivr-app", token="s3cr3t", bind="0.0.0.0:8790")

@server.on_call
async def handle(call):
    await call.answer()
    try:
        await call.transfer("sip:agent@pbx")
    except ControlError as error:
        print("transfer rejected:", error.code)

async def main():
    async with server:
        await server.serve()

asyncio.run(main())

Shutdown

Both classes are async context managers, and async with is the recommended shape. close() is the same thing explicitly.

It matters more than it looks. run() / serve() are driven by a background tokio task, and every handed-over call is dispatched from another one. Nothing joins those tasks and the runtime outlives the interpreter, so an app that finishes without closing leaves them delivering results into an asyncio loop — and then into a Python — that is no longer there. Closing first means there is nothing in flight to strand.

Not closing is handled rather than fatal: a handover arriving after the loop or interpreter has gone is dropped, and a handler cancelled during teardown is not reported as a failure. That is damage control, not a substitute for closing.

API

ControlClient (inbound-persistent)

  • ControlClient(app, token, url=…, protocol=1, reply_timeout_ms=…, reconnect_backoff_ms=…)
  • @client.on_call — register an async (or sync) per-call handler.
  • await client.connect() / await client.run() — connect / drive (reconnect + resync).
  • await client.command(verb, module=None, target=None, args=None) — the generic {module, verb, target, args} primitive for any adapter (SIP today; SMPP/SS7 later).
  • await client.originate(channel, to=None, *, aor=None, strategy=None, total_timeout=None, media=False, sdp=None, body=None, content_type=None, …, session_timer=None) — place an outbound call under a channel id you choose; resolves to {"channel", "call_id", "sip_call_id"} once the INVITE is on the wire. Exactly one media plan (media=True, sdp= or body=). session_timer={"expires", "min_se", "refresher"} runs an RFC 4028 session timer on the call, each key left out taking the server's default. What the server would refuse raises ValueError before a frame goes out.
  • await client.describe() — adapter schema.
  • client.shutdown() — stop the client and unblock run().
  • client.close() — shutdown, plus drop the handler so nothing else is dispatched. async with client: does this on the way out. See Shutdown above.

ControlServer (per-call-connect)

  • ControlServer(app, token, bind="0.0.0.0:8790", reply_timeout_ms=…) — bind is the address the app listens on for siphon to dial; the token is validated on the incoming upgrade.
  • @server.on_call — the SAME decorator + Call handle as ControlClient.
  • await server.bind() — bind the listener; resolves to the bound address string (bind to …:0 to learn the ephemeral port before siphon dials in).
  • server.local_addr — the bound address once bind() / serve() has run, else None.
  • await server.serve() / await server.run() — accept siphon's per-call dials forever (stop by cancelling the task).
  • server.close() — drop the handler so no further accepted call is dispatched, one accepted while serve() is still running included. async with server: does this on the way out. See Shutdown above.

Call (shared by both modes)

  • Call verbs: answer(), answer_with(code, …), answer_anchored(profile=None, ws_uri=None), ring(reason=None), progress(), reject(code, reason), hangup(reason=None), refer(to) / transfer(to), route(targets, strategy="sequential", headers=None), set_header(name, value), get_header(name), remove_header(name), set_var(key, value), get_var(key), command(verb, args=None), next_event().
  • await call.dial(targets, strategy=None, timeout=None, headers=None, profile=None, from_uri=None, from_display=None, p_asserted_identity=None, privacy=None, on_answer=None, ringback=None) rings B-legs while the caller stays unanswered and this app keeps the channel. Each target is a dict: {"uri": ...} is dialed as written, {"aor": ...} is forked to every registered contact over that contact's own captured flow, which is the only way to reach a phone registered on TCP, TLS or WSS behind NAT. A bare string is refused, because it does not say which of the two was meant. With on_answer="bridge" it instead rings phones for a caller the app already answered and anchored (after a greeting or a menu), plays ringback (a tone preset or cadence, True for the default, False for none) while they alert, and bridges the first to pick up; the result adds group_id, total_timeout and the branches rung.
  • await call.cancel_dial(reason=None) gives up on the dial that is ringing and leaves the caller as the dial found it. Every phone still ringing is CANCELled, each reported by DialBranchFailed with cause cancelled, and the dial ends in DialFailed with code 487; reason is the cause of a bridging dial's DialFailed (default cancelled). Raises ControlError (invalid_state) when nothing is ringing, and once a phone has answered and is being bridged.
  • await call.accept_refer(target=None, next_hop=None, mode=None, profile=None, *, aor=None, from_uri=None, from_display=None, p_asserted_identity=None, privacy=None, headers=None, timeout=None, number_policy=None, format=None) accepts a pending inbound REFER (a TransferRequested event). mode is "terminate" (siphon dials the target), "transparent" (siphon relays the REFER) or "controller": siphon answers 202 and dials nothing, this app moves the parties itself and then reports with await call.complete_refer(code, reason=None), within timeout seconds (default 60, at most 180). aor= names the target by its registered address-of-record in place of a URI: it is dialled over the flow its phone registered on, every registered contact rings and the first to answer is kept. The identity arguments are the ones dial takes, for the leg the transfer dials; number_policy names a number policy configured on the server for the numbers in them, or format gives one format ("e164", "plain", "international", "national"). A target URI together with aor=, mode="controller" with any argument that describes a leg, and timeout with another mode each raise ValueError before a frame goes out. await call.reject_refer(code, reason=None) declines the REFER.
  • await call.replace_peer(target=None, next_hop=None, replace_a_leg=None, profile=None, timeout=None, *, aor=None, from_uri=None, from_display=None, p_asserted_identity=None, privacy=None, headers=None, number_policy=None, format=None) swaps one party of an answered call for a freshly dialled target, with no REFER involved; the replaced leg stays up while the target rings. Exactly one of target and aor= (ValueError otherwise). The reply says the INVITE is on the wire; PeerReplaced / ReplaceFailed is the outcome.
  • await call.bridge(with_channel, on_peer_hangup=None) joins this call to another leg the app owns, and await call.unbridge(reason=None) parts them, both legs staying answered and held. The outcome arrives as ChannelBridged / BridgeFailed.
  • await call.play(file=None, db_id=None, blob=None, repeat=None, start_ms=None, duration_ms=None, to_tag=None, *, tone=None, url=None, gain_decibels=None) plays an announcement on the caller's media. Exactly one source: a file, a db_id, a blob, a tone (a preset such as "ringback_eu" or a cadence) or a url (HTTP or HTTPS). repeat is a total play count, or "inf" to play until stopped; anything else raises ValueError. gain_decibels plays louder (positive) or quieter (negative). play_file(file), stop(), dtmf(digits, …), hold() and unhold() are the other media verbs. hold is a media gate, not a SIP hold, and is refused (invalid_state) on a call the engine only relays.
  • await call.stream_start(ws_uri, direction=None, channels=None, *, mode="tee", sample_rate=None, profile=None) streams the call's audio to a WebSocket server, as a copy ("tee") or a takeover ("bridge"), and await call.stream_stop(*, mode="tee") detaches it. siphon-rtp backend only.
  • await client.originate(channel, aor=..., strategy=None, total_timeout=None, …) rings every phone registered at the AoR, each over its own flow and Path; the first to answer becomes the channel's call. Exactly one of to and aor, and strategy / total_timeout only with aor. Resolves to {"channel", "group_id", "aor", "strategy", "total_timeout", "branches"}.
  • await call.record_start(direction=None, channels=None, max_duration_ms=None, silence_ms=None, path=None) records the call's decoded audio to a wav file and returns the recording_id that await call.record_stop(recording_id=None) addresses (no id stops every recording on the call). The reply is the accept; the RecordingFinished event says the file is closed. siphon-rtp backend only.
  • await call.drop(reason=None, *, ban=False) abandons an unanswered call with nothing on the wire — no final response, no CANCEL — and releases it. Use it for traffic addressed to nothing your controller serves: a 404 confirms the number to an enumeration sweep, silence does not. An answered call raises ControlError with code == "invalid_state" (its dialog is owed a BYE — that is hangup); the reason reaches siphon's log and the CDR, not the peer. ban=True also scores the caller's source toward an auto-ban (security.failed_auth_ban), so a source the controller keeps dropping is refused at the transport.
  • unsupported_verb is what a verb raises when the configured media backend cannot carry it out: the stream and record verbs on rtpengine or rtpproxy, and play(repeat="inf") there.

Errors

A rejected command raises ControlError carrying a stable .code (not_found, forbidden, unsupported_verb, unauthorized, …).

Build

maturin develop        # into the active venv
maturin build --release

The target interpreter is free-threaded CPython 3.14t (the SIPhon runtime); the wheel also loads on a standard GIL build.

License

MIT

Metadata

Release files for siphon-control 0.8.0

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

Source distribution (sdist)

Source distribution for siphon-control 0.8.0
File Size Uploaded
siphon_control-0.8.0.tar.gz 160.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for siphon-control 0.8.0
File
siphon_control-0.8.0-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
siphon_control-0.8.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details
siphon_control-0.8.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
siphon_control-0.8.0-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
siphon_control-0.8.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
siphon_control-0.8.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
siphon_control-0.8.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details
siphon_control-0.8.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details

Total release size: 17.3 MB

Release files / siphon_control-0.8.0.tar.gz

Download URL siphon_control-0.8.0.tar.gz
Size 160.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0b626f3666a0734bcaaca4ebabdba7ae4bdcee8daa81e5a52d67383cc1af8946
BLAKE2b-256 checksum
How to use checksums
faab9aa1bddf0f0c7eaf211bdb4c135b99897a70c58a693560a9c88b265c42c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314t-win_amd64.whl

Download URL siphon_control-0.8.0-cp314-cp314t-win_amd64.whl
Size 2.0 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
a6b1288acc44ae28916d6bd9ccf009b98d05bf6c8e0bcbf2d4da55353d54b427
BLAKE2b-256 checksum
How to use checksums
d3007f09c80bafc39b2d54742b76e6d1b34ffff79f694a0c77671e4823b34f16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL siphon_control-0.8.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a893da63b7028e5248055e96141fdc1ad3666e4c7cfede30b11fca5f308ed478
BLAKE2b-256 checksum
How to use checksums
b1312447a3cca70ae176b16db8416b2dc84b71670e35ca73ddc9454c31dd6ab6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL siphon_control-0.8.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.4 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
44a875f40f8c93c74fbb5c197255dddfc38eace029243ad57652eb81c3b11235
BLAKE2b-256 checksum
How to use checksums
a97fdcba2d4fc6379554fc1817b64887df6f7f4b1f1faba70df6b924f087de29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314t-macosx_11_0_arm64.whl

Download URL siphon_control-0.8.0-cp314-cp314t-macosx_11_0_arm64.whl
Size 2.1 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ef59969759486216ce6e1fce276be29d82e881ca4624221d71ef7675234e3fcc
BLAKE2b-256 checksum
How to use checksums
0c032a3a7d12f12c7599e921f3fd065e372094d979470b1cea06558604f3218b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314-win_amd64.whl

Download URL siphon_control-0.8.0-cp314-cp314-win_amd64.whl
Size 2.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
4cbf39b3e854161c4dab257a4e760a999c5ecda98f4737c646e1f3af35242ca5
BLAKE2b-256 checksum
How to use checksums
5ff1987409205486a526e3345938ab7cbedac092eeb28ea8196b95808fb75813
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL siphon_control-0.8.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c926a33b273184a34760cfadaf0d324a8fdc91760db0261d52c2242962b2474a
BLAKE2b-256 checksum
How to use checksums
44a871d363fb138280374674f8d07208e3043ba5638687231291614f08d8c42d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL siphon_control-0.8.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.4 MB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
f2e02f1c0195f149238e87f7e2a48194a391be2621951a882e4bed86837396fb
BLAKE2b-256 checksum
How to use checksums
a83235b77eda0e2e882591627d93670070d57fb2266db22e84297b30eb27165f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release files / siphon_control-0.8.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL siphon_control-0.8.0-cp314-cp314-macosx_11_0_arm64.whl
Size 2.1 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d80548556565b70484433ad8d94c4ca3d34a83f8f97fc93e4f2da3b89d01c4c5
BLAKE2b-256 checksum
How to use checksums
ffd7cef4dda4f461cbf8877ca409fec74ab82c77d2a77f6b588beb42a6926db7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.0 This release

9 release files

0.7.0

9 release files

0.6.0

9 release files

0.5.0

9 release files

0.4.0

9 release files

0.3.0

9 release files

0.2.0

9 release files

0.1.3

9 release files

0.1.2

9 release files

0.1.1

9 release files

0.1.0

2 release files

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