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 pylibsrtpVerified import paths — ran on the pinned version, not inferred.
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.
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.
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).
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`.
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.
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`.
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.
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).