Skip to main content

PyVoIP is a pure python VoIP/SIP/RTP library.

Project description

pyVoIP

PyVoIP is a pure python VoIP/SIP/RTP library. Currently, it supports PCMA, PCMU, and telephone-event.

This library does not depend on a sound library, i.e. you can use any sound library that can handle linear sound data i.e. pyaudio or even wave. Keep in mind PCMU/PCMA only supports 8000Hz, 1 channel, 8 bit audio.

Getting Started

Simply run pip install pyVoIP, or if installing from source:

git clone https://github.com/tayler6000/pyVoIP.git
cd pyVoIP
pip install .

Don't forget to check out the documentation!

Basic Example

This basic code will simple make a phone that will automatically answer then hang up.

from pyVoIP.VoIP import VoIPPhone, InvalidStateError


def answer(call):  # This will be your callback function for when you receive a phone call.
    try:
        call.answer()
        call.hangup()
    except InvalidStateError:
        pass


if __name__ == "__main__":
    phone = VoIPPhone(
        <SIP Server IP>,
        <SIP Server Port>,
        <SIP Server Username>,
        <SIP Server Password>,
        callCallback=answer,
        myIP=<Your computer's local IP>,
        sipPort=<Port to use for SIP (int, default 5060)>,
        rtpPortLow=<low end of the RTP Port Range>,
        rtpPortHigh=<high end of the RTP Port Range>,
    )
    phone.start()
    input("Press enter to disable the phone")
    phone.stop()

Using an outbound SIP proxy

If your provider requires a separate outbound proxy, keep server pointed at the SIP domain / registrar and pass the proxy host separately.

phone = VoIPPhone(
    "sip.example.com",
    5060,
    "alice",
    "secret",
    myIP="192.0.2.10",
    proxy="pbx.example.net",
    proxyPort=5060,
    auth_username="alice-auth-id",  # Optional: used for Proxy-Authorization
    callCallback=answer,
)

proxy may be a hostname, host:port, or a SIP URI such as sip:pbx.example.net:5060.

TCP/TLS SIP transport with RFC 3263-compliant resolution

# TCP, explicit URI transport wins.
phone = VoIPPhone(
    "sip:registrar.example.com;transport=tcp",
    None,
    "alice",
    "secret",
    myIP="192.0.2.10",
)

# TLS via sips: and RFC 3263 DNS if no explicit port is present.
phone = VoIPPhone(
    "sips:registrar.example.com",
    None,
    "alice",
    "secret",
    myIP="192.0.2.10",
    tls_server_name="registrar.example.com",
)

# Legacy host + explicit port stays simple unless transport is supplied.
phone = VoIPPhone(
    "registrar.example.com",
    5060,
    "alice",
    "secret",
    myIP="192.0.2.10",
    transport="tcp",
)

Inspecting supported codecs

Parsed SIP/SDP messages and active calls can report the codecs offered by the remote endpoint and the codecs supported by PyVoIP.

import pyVoIP


def answer(call):
    report = call.codec_support_report()

    print("Remote codecs:", report["remote"])
    print("PyVoIP codecs:", report["pyvoip"])
    print("Compatible codecs:", report["compatible"])
    print("Unsupported remote codecs:", report["unsupported"])


# Also available for any parsed SIPMessage containing SDP:
remote_codecs = sip_message.supported_codecs()
report = sip_message.codec_support_report()

# And at module level:
pyvoip_codecs = pyVoIP.supported_codecs()

Pre-call codec inspection

Local codec information is available without an active SIP session. Remote codec information can be probed before starting a call with SIP OPTIONS when the peer/provider returns SDP in its OPTIONS response.

from pyVoIP.VoIP import VoIPPhone


phone = VoIPPhone(
    "sip.example.com",
    5060,
    "alice",
    "secret",
    myIP="192.0.2.10",
)

# Purely local; this works before phone.start().
local_report = phone.available_codecs()
print("Local codec offer:", local_report["local_offer"])

# Remote probing requires SIP signalling, so start/register first.
phone.start()
remote_report = phone.available_codecs("1001")
print("Remote codecs:", remote_report["remote"])
print("Call-compatible audio:", remote_report["call_compatible"])
print("Can start call from codec data:", remote_report["can_start_call"])

If the remote side does not include SDP in the OPTIONS response, remote_report["remote"] will be empty and can_start_call will be None.

Sponsors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rfcvoip-2.7.7.tar.gz (88.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rfcvoip-2.7.7-py3-none-any.whl (72.1 kB view details)

Uploaded Python 3

File details

Details for the file rfcvoip-2.7.7.tar.gz.

File metadata

  • Download URL: rfcvoip-2.7.7.tar.gz
  • Upload date:
  • Size: 88.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for rfcvoip-2.7.7.tar.gz
Algorithm Hash digest
SHA256 aaac7cf951239fe218d113ddd6a9d6a5daea1fb2ff557974d65b74659c6f4a41
MD5 b902da16164ffb223d4c1bd183a4a0fa
BLAKE2b-256 a1e76a378a10a5c7e2f003f762a28992a44b2a9becec35a53adbb1d9b49c11cf

See more details on using hashes here.

File details

Details for the file rfcvoip-2.7.7-py3-none-any.whl.

File metadata

  • Download URL: rfcvoip-2.7.7-py3-none-any.whl
  • Upload date:
  • Size: 72.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for rfcvoip-2.7.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2812e6f2624d4e48e72924cd233cd09e4afb219fb9601cbd435105aa8bbecc71
MD5 f51e676ded4ac7dbce7807eca8138b85
BLAKE2b-256 3e08dd8de1acac9f9994a1e20f9eb88839110ab423103d62cffab371a48b40f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page