Models representing FreeSWITCH entities

class switchio.models.Call(uuid, session)

A collection of sessions which together compose a “phone call”.


Append a session to this call and update the ref to the last recently added session


A reference to the session making up the initial leg of this call


Convenience helper which can determine whether sess is one of first or last and returns the other when the former is true


Hangup up this call


A reference to the session making up the final leg of this call

class switchio.models.Events(event=None)

Event collection which for most intents and purposes should quack like a collections.deque. Data lookups are delegated to the internal deque of events in lilo order.

get(key, default=None)

Return default if not found Should be faster then handling the key error?


Print serialized event data in chronological order to stdout


Append an ESL.ESLEvent

class switchio.models.Job(future=None, sess_uuid=None, callback=None, event=None, client_id=None, con=None, kwargs={})

A background job future. The interface closely matches multiprocessing.pool.AsyncResult.

  • uuid (str) – job uuid returned directly by SOCKET_DATA event
  • sess_uuid (str) – optional session uuid if job is associated with an active FS session

Return True if this job was successfully cancelled or finished running.

fail(resp, *args, **kwargs)

Fail this job optionally adding an exception for its result


Get the result for this job waiting up to timeout seconds. Raises TimeoutError on if job does complete within alotted time.


Local logger instance.


Return bool indicating whether job has completed


The final result


Return bool determining whether job completed without error


Update job state/data using an event


Wait until job has completed or timeout has expired

exception switchio.models.JobError
class switchio.models.Session(event, event_loop=None, uuid=None, con=None)

Session API and state tracking.


Stop playback of media on this session and move on in the dialplan.

bridge(dest_url=None, profile=None, gateway=None, proxy=None, params=None)

Bridge this session using uuid_broadcast (so async). By default the current profile is used to bridge to the SIP Request-URI.

broadcast(path, leg='', delay=None, hangup_cause=None)

Execute an application async on a chosen leg(s) with optional hangup afterwards. If provided tell FS to schedule the app delay seconds in the future. Uses either of the uuid_broadcast or sched_broadcast commands.


Re-invite a bridged node out of the media path for this session


Clear all scheduled tasks for this session.


Send a refer to the client. The only parameter should be the SIP URI to contact (with or without “sip:”):

<action application="deflect" data="" />

Echo back all audio recieved.

execute(cmd, arg='', params='', loops=1)

Execute an application async.

get(key, default=None)

Get latest event header field for key.


Hangup this session with the provided cause hangup type keyword.


Return the hostname/ip address for the host which this session is currently active


Return bool indicating whether this is an inbound session


Return bool indicating whether this is an outbound session


Local logger instance.

mute(direction='write', level=1)

Mute the current session. level determines the degree of comfort noise to generate if > 1.


Park this session

playback(args, start_sample=None, endless=False, leg='aleg', params=None)

Playback a file on this session

  • args (str or tuple) – arguments or path to audio file for playback app
  • leg (str) – call leg to transmit the audio on
poll(events, timeout=None, return_when='FIRST_COMPLETED')

Poll for any of a set of event types to be received for this session.

record(action, path, rx_only=True)

Record audio from this session to a local file on the slave filesystem using the uuid_record command:

uuid_record <uuid> [start|stop|mask|unmask] <path> [<limit>]
recv(name, timeout=None)

Return an awaitable which resumes once the event-type name is received for this session.


Respond immediately with the following response code. see the FreeSWITCH respond dialplan application

sched_dtmf(delay, sequence, tone_duration=None)

Schedule dtmf sequence to be played on this channel.

  • delay (float) – scheduled future time when dtmf tones should play
  • sequence (str) – sequence of dtmf digits to play
sched_hangup(timeout, cause='NORMAL_CLEARING')

Schedule this session to hangup after timeout seconds.

send_dtmf(sequence, duration='w')

Send a dtmf sequence with constant tone durations

setvar(var, value)

Set variable to value


Set all variables in map params with a single command

speak(text, engine='flite', voice='kal', timer_name='')

Speak, young switch (alpha).

start_record(path, rx_only=False, stereo=False, rate=16000)

Record audio from this session to a local file on the slave filesystem using the record_session cmd. By default recordings are sampled at 16kHz.

stop_record(path='all', delay=0)

Stop recording audio from this session to a local file on the slave filesystem using the stop_record_session cmd.


Time stamp for the most recent received event


Unmute the write buffer for this session


Unset a channel var.


Update state/data using an ESL.ESLEvent


Time elapsed since the Session.create_ev to the most recent received event.

exception switchio.models.TimeoutError