Skip to main content

Python SDK for NetSIPCore SIP engine

Project description

NetSIP Python SDK

Python SDK for controlling the NetSIPCore SIP engine.

NetSIP is a Python interface for building SIP applications using the native NetSIPCore engine.

The SDK provides asynchronous control of SIP accounts, calls, audio devices and RTP audio playback.


Features

  • SIP account registration
  • SIP account disconnection
  • Incoming and outgoing calls
  • Call answering and hang up
  • Speaker control
  • Microphone control
  • WAV audio playback into RTP stream
  • Automatic conversation mode
  • NetSIPCore log access

Architecture

The Python SDK is a controller for the NetSIPCore native SIP engine.

Python Application
        |
        |
        | JSON over TCP
        |
        v
NetSIPCore
        |
        v
PJSUA2
        |
        v
PJSIP

The SDK does not communicate with PJSIP directly.

All SIP operations are performed by NetSIPCore.


Requirements

  • Python 3.10+
  • NetSIPCore binary
  • SIP server compatible with PJSIP

The Python package communicates with NetSIPCore using:

TCP 127.0.0.1:4890

Installation

Install from PyPI

pip install netsip

Install from source

git clone https://github.com/WildRogerr/NetSIPCore.git

cd NetSIPCore/python

pip install .

NetSIPCore binary

The NetSIPCore native SIP engine is included with the Python package.

After installation:

pip install netsip


---

# Windows requirements

Windows builds require Microsoft Visual C++ Runtime libraries.

Required files:

vcruntime140.dll msvcp140.dll ucrtbase.dll



Install Microsoft Visual C++ Redistributable 2015-2022:

https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist



---

# Microphone permissions

Some security software can block microphone access.

If microphone access is unavailable:

1. Add NetSIPCore executable to trusted applications.
2. Allow microphone access in Windows privacy settings.
3. Restart the application.


Windows:

Settings → Privacy & security → Microphone → Allow desktop apps



---

# Quick start

```python
import asyncio

from netsip import SIPManager


async def main():

    sip = SIPManager()


    await sip.subscriber_registration(
        server="192.168.1.10",
        number="1001",
        password="password"
    )


    if sip.registration_state:

        print("Registered")


        await sip.call(
            "1001",
            "1002"
        )


        await asyncio.sleep(10)


        await sip.hang_up(
            "1001"
        )


    sip.close_sipcore()



asyncio.run(main())

API

Create manager

sip = SIPManager()

Creates NetSIPCore process and initializes communication.


Registration

Register SIP account:

await sip.subscriber_registration(
    server,
    number,
    password
)

Disconnect account:

await sip.subscriber_disconnect(
    number
)

Calls

Make outgoing call:

await sip.call(
    number,
    remote_number
)

Answer incoming call:

await sip.answer(
    number
)

Hang up:

await sip.hang_up(
    number
)

Audio control

Speaker:

await sip.mute(number)

await sip.unmute(number)

Microphone:

await sip.micoff(number)

await sip.micon(number)

WAV playback

Send WAV audio into an active RTP call:

await sip.send_audio(
    number,
    wav_file
)

The path should be absolute.

Example:

from pathlib import Path


wav_file = Path(
    "audio/message.wav"
).resolve()


await sip.send_audio(
    "1001",
    str(wav_file)
)

Windows example:

from pathlib import Path


wav_file = Path(
    r"C:\Audio\message.wav"
).resolve()


await sip.send_audio(
    "1001",
    str(wav_file)
)

Automatic conversation mode

NetSIP supports automatic WAV playback during active calls.

Available files:

sip.wf_a
sip.wf_b
sip.wf_c

Enable:

sip.wf_a = "audio/message.wav"

sip.autospeak = True

Disable:

sip.autospeak = False

Client state

Registered accounts are available in:

sip.clients

Example:

sip.clients["1001"]

Possible fields:

server
username
current_state
audio_state
remote_number

Call states:

registered
incoming
ringing
confirmed
streaming
disconnected

Logs

NetSIPCore logs are available:

sip.sipcore_log

Example:

for line in sip.sipcore_log:
    print(line)

Examples

Example application:

examples/simplephone.py

The example demonstrates:

  • SIP registration
  • outgoing calls
  • incoming calls
  • RTP WAV playback
  • speaker control
  • microphone control
  • automatic conversation mode

Documentation

NetSIPCore documentation:

docs/
 ├── API.md
 ├── JSON.md
 ├── BUILD.md
 └── ARCHITECTURE.md

License

NetSIP Python SDK is distributed under the GNU General Public License version 2.

See:

LICENSE

for the full license text.

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

netsip-1.0.0.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

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

netsip-1.0.0-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file netsip-1.0.0.tar.gz.

File metadata

  • Download URL: netsip-1.0.0.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for netsip-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3cb3e37c8d648fe324a5bde0b406a86e88a0280d6045215607e7dc384934740e
MD5 32dfb2b200492eb2e3924cff8891f3ba
BLAKE2b-256 361879665bcab871716491f44f72a1dc5dbf40c982e51c9fae02e268592ed858

See more details on using hashes here.

File details

Details for the file netsip-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: netsip-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for netsip-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f3c70bb0bdabe326d216f1b52692ccfe0b1604509b240b433e7b537ae71ac1a
MD5 65e48f171952e7623e9fed8aa1bde2bc
BLAKE2b-256 e30cf76b46196e851e01610fa1a4aa37ad29d400e5f371fa8a854e992e571dbe

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