Registry / auth-security / pylibsrtp

pylibsrtp

JSON →
library1.0.0pypypi✓ verified 26d ago

pylibsrtp is a Python wrapper around the native libsrtp library, enabling Python applications to encrypt and decrypt Secure Real-time Transport Protocol (SRTP) packets. SRTP, as defined by RFC 3711, provides essential confidentiality, message authentication, and replay protection for RTP streams. The library is currently at version 1.0.0, released on October 13, 2025, and maintains a periodic release schedule to incorporate updates and fixes.

pip install pylibsrtp
INSTALL
IMPORT
SIG · PYLIBSRTP
P
pylibsrtp
auth-securitypythonv1.0.0
Install
2.0s avg
Import
23ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.024s · 26.1MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.0s · import 0.022s · 27MB
24MB installed
● package 24MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Policy
✓ from pylibsrtp import Policy
Session
✓ from pylibsrtp import Session
Error
✓ from pylibsrtp import Error

This quickstart demonstrates how to initialize SRTP policies and sessions for both protecting (encrypting) and unprotecting (decrypting) an RTP packet using a shared master key. It then verifies that the unprotected packet matches the original.

from pylibsrtp import Policy, Session key = (b'\x00' * 30) rtp_packet = b'\x80\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + (b'\xd4' * 160) # Create an outbound policy and session for protection tx_policy = Policy(key=key, ssrc_type=Policy.SSRC_ANY_OUTBOUND) tx_session = Session(policy=tx_policy) srtp_packet = tx_session.protect(rtp_packet) # Create an inbound policy and session for unprotection rx_policy = Policy(key=key, ssrc_type=Policy.SSRC_ANY_INBOUND) rx_session = Session(policy=rx_policy) unprotected_rtp_packet = rx_session.unprotect(srtp_packet) # Verify roundtrip assert unprotected_rtp_packet == rtp_packet print("SRTP protection and unprotection successful!")
Debug
Known issues
breakingThe underlying libsrtp library, which pylibsrtp wraps, introduced breaking changes in versions 2.x, specifically concerning initialization vectors for AES 256 ICM and AES GCM ciphers when used with OpenSSL for RTCP. Ensure your libsrtp version is compatible with your usage patterns to avoid unexpected decryption failures or security issues.
fix
Review the libsrtp changelog for compatibility notes. Upgrade all endpoints to a consistent and recent version of libsrtp (2.0 or newer) to ensure interoperability and correct cipher behavior, especially for RTCP with AES 256 ICM or AES GCM.
affects: libsrtp 2.x and newer when interacting with older libsrtp versions (1.5, 2.0)
gotchapylibsrtp requires the native libsrtp library (version 2.0 or better) to be installed on your system. `pip install pylibsrtp` only installs the Python bindings; it does not install the underlying C library. Failure to install libsrtp beforehand will result in build errors during pip installation or runtime errors due to missing shared libraries.
fix
Before installing pylibsrtp, install libsrtp 2.0 or higher using your system's package manager (e.g., `apt install libsrtp2-dev` on Debian/Ubuntu, `dnf install libsrtp-devel` on Fedora/CentOS, `brew install srtp` on macOS).
affects: All versions
gotchaWhen building pylibsrtp on macOS after installing `srtp` via Homebrew, you might need to set specific environment variables for the build process to correctly link against the installed libsrtp and OpenSSL libraries.
fix
Set `CFLAGS` and `LDFLAGS` environment variables before installation: `export CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix srtp)/include"` and `export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix srtp)/lib"`. Then proceed with `pip install pylibsrtp`.
affects: All versions, specifically macOS builds
Errors
Common errors & fixes
OSError: libsrtp.so: cannot open shared object file: No such file or directory
The underlying native `libsrtp` C library is not found by the Python wrapper at runtime, usually because it's not installed or not in the system's library search path.
fix
Install `libsrtp` on your system (e.g., `sudo apt-get install libsrtp2-dev` on Debian/Ubuntu, `brew install libsrtp` on macOS) and ensure it's discoverable by the linker, or set `LD_LIBRARY_PATH` on Linux.
ModuleNotFoundError: No module named 'pylibsrtp._srtp_c'
The C extension module that `pylibsrtp` relies on failed to compile or install correctly, often due to missing `libsrtp` development headers or a C compiler issue during `pip install`.
fix
Ensure `libsrtp` development headers are installed (e.g., `sudo apt-get install libsrtp2-dev`) and a C compiler (like `gcc`) is available before running `pip install pylibsrtp`.
pylibsrtp.SRTPError: SRTP context initialization failed
`pylibsrtp` failed to create or initialize an SRTP context, often due to invalid configuration parameters passed to the `SRTPContext` constructor or an underlying `libsrtp` error.
fix
Verify that the parameters passed to `pylibsrtp.SRTPContext` (e.g., cipher, key_len, auth_tag_len) are valid and consistent with the SRTP specification and `libsrtp` capabilities.
pylibsrtp.SRTPError: Authentication failure during decryption
The SRTP packet's authentication tag does not match the computed tag, indicating either data corruption, tampering, or incorrect SRTP keys being used for decryption.
fix
Ensure that the correct master key and salt are being used for decryption, that the packet has not been tampered with, and that the SRTP context is properly synchronized (e.g., sequence numbers).
Upgrade
Version history
1.0.0latest on PyPI · released Oct 13, 2025
Audit
Dependencies
libsrtprequiredpylibsrtp is a Python wrapper for the native libsrtp library. libsrtp version 2.0 or better is required to be installed on the system for pylibsrtp to build and function correctly.
libsrtp2-devoptionalDevelopment headers for libsrtp (Debian/Ubuntu systems).
libsrtp-developtionalDevelopment headers for libsrtp (Fedora/CentOS systems).
srtpoptionallibsrtp via Homebrew (macOS systems).
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
pylibsrtp — pip install pylibsrtp · libregistry