Pure-Python SIP/RTP user-agent library (UAC + UAS) with asyncio
Project description
opensip
Pure-Python SIP/RTP user-agent library. Asyncio tabanlı, UAC + UAS + REGISTER + digest auth desteği ile. G.711 (PCMU/PCMA) codec'ler numpy varsa vektörize edilmiş LUT ile çalışır (~13–25× hızlanma, 20 ms ptime başına ~1 µs); opsiyonel sounddevice extras ile gerçek mikrofon/hoparlör.
Durum: erken alfa. API değişebilir. Gerçek bir Türk bulut-PBX provider'ı (netsantral.com) üzerinden uçtan uca iki yönlü ses ile test edildi; aşağıdaki "Bilinen sınırlamalar" bölümünü okumadan production'a almayın.
Kurulum
Henüz PyPI'de değil; doğrudan git'ten kurun:
pip install git+https://github.com/artan/opensip.git
pip install "git+https://github.com/artan/opensip.git#egg=opensip[audio]" # + ses
Hızlı başlangıç — giden arama
import asyncio
from opensip import UserAgent, Account
async def main():
ua = UserAgent(local_addr=("0.0.0.0", 5060))
await ua.start()
acc = Account(
username="alice",
domain="sip.example.com",
password="s3cret",
server=("sip.example.com", 5060),
)
await ua.register(acc)
call = await ua.invite(acc, "sip:bob@sip.example.com")
await call.wait_answered()
await asyncio.sleep(10)
await call.hangup()
await ua.stop()
asyncio.run(main())
Gelen arama
import asyncio
from opensip import UserAgent, Account
async def main():
ua = UserAgent(local_addr=("0.0.0.0", 5060))
@ua.on_incoming_call
async def handle(call):
await call.answer()
await call.wait_ended()
await ua.start()
acc = Account(username="alice", domain="sip.example.com",
password="s3cret", server=("sip.example.com", 5060))
await ua.register(acc)
await asyncio.Event().wait() # forever
asyncio.run(main())
Mimari
opensip/
├── message.py # SIP request/response parser + serializer
├── headers.py # Via, From, To, Contact, Call-ID, CSeq...
├── auth.py # Digest authentication (MD5, qop=auth, SHA-256)
├── sdp.py # SDP offer/answer
├── transport.py # asyncio UDP transport
├── ua.py # UserAgent — UAC + UAS facade, dialog state inline
├── rtp.py # RTP packetization + sender loop
├── codecs.py # G.711 µ-law / A-law (numpy hot path)
└── audio.py # sounddevice wrapper (opsiyonel)
Bilinen sınırlamalar
opensip v0.1 minimal-viable bir UA: gerçek bir provider ile çağrı yapar ama RFC 3261'in birkaç önemli parçası henüz yok. Bunlar üzerine bir telefon altyapısı kurmadan önce farkında olun.
- Transaction katmanı yok (RFC 3261 §17). UDP retransmission timer'ları (Timer A–K) yok — paket düşerse istek timeout'a düşer. LAN / kayıpsız ağda fark edilmez; internet üzerinden kaybedilen ilk INVITE'ı tekrar göndermez.
- Dialog state machine sınırlı. Re-INVITE (hold/resume), UPDATE, target refresh çalışmaz; route set INVITE/BYE/ACK'te kullanılmaz — uzun proxy zincirleri kırılır.
- NAT handling client-side yok. SDP
c=satırına LAN IP yazılır; iki yönlü RTP yalnızca provider symmetric-RTP / SBC NAT handling yapıyorsa çalışır (netsantral yapıyor, çoğu yapmaz). rport/received Contact'a yansıtılmaz, STUN/ICE yok. - Yalnızca UDP. TCP ve TLS yok; TLS-only provider'lar (örn. bazı Twilio konfigürasyonları) için kullanılamaz.
- RTCP yok. Jitter buffer yok — gelen RTP doğrudan callback'e gönderilir, out-of-order paket / sıralama boşluğu metrikleri yok.
- DTMF yok. RFC 2833 payload type 101 alınır ama sessizce düşürülür.
- Codec sınırlı. PCMU + PCMA + telephone-event (gönderme yok). Opus / G.722 / G.729 yok.
Authorizationre-use yok. Her INVITE/BYE'da yeniden challenge — küçük gecikme katar.
Tam yol haritası ve önceliklendirme için issue tracker'a bakın.
Geliştirme
python3.12 -m venv .venv
.venv/bin/pip install -e ".[dev,audio]"
.venv/bin/pytest
Python 3.10+ gerekiyor. macOS Homebrew kullanıyorsan brew install python@3.12.
G.711 codec mikrobenchmark'ı için:
.venv/bin/python tests/bench_codecs.py
Lisans
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opensip-0.1.0.tar.gz.
File metadata
- Download URL: opensip-0.1.0.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ad53806ada65035db9eaaead15e3207319e1104f1b1ccee7a9f8cce4b7d98f
|
|
| MD5 |
adab3be6473bf8db820f02d7dbaf8225
|
|
| BLAKE2b-256 |
4770acc3f880d838fb58a8ffec7498505d75c34a3582d42634c71eee4b00a932
|
File details
Details for the file opensip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opensip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d50fd057d7f011c62704b626c6b48feb939977085d4d80d83b94cbb8f727366
|
|
| MD5 |
f905889ce4ca3e225098a2f30c6c1f89
|
|
| BLAKE2b-256 |
86e70afe05bdae65a6b73b3b9764e24e1bf8e71a8d87845e56544fb197be4306
|