{"id":3757,"library":"pylibsrtp","title":"pylibsrtp","description":"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.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/aiortc/pylibsrtp","tags":["SRTP","RTP","security","cryptography","telephony","networking","real-time"],"install":[{"cmd":"pip install pylibsrtp","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"pylibsrtp 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.","package":"libsrtp","optional":false},{"reason":"Development headers for libsrtp (Debian/Ubuntu systems).","package":"libsrtp2-dev","optional":true},{"reason":"Development headers for libsrtp (Fedora/CentOS systems).","package":"libsrtp-devel","optional":true},{"reason":"libsrtp via Homebrew (macOS systems).","package":"srtp","optional":true}],"imports":[{"symbol":"Policy","correct":"from pylibsrtp import Policy"},{"symbol":"Session","correct":"from pylibsrtp import Session"},{"symbol":"Error","correct":"from pylibsrtp import Error"}],"quickstart":{"code":"from pylibsrtp import Policy, Session\n\nkey = (b'\\x00' * 30)\nrtp_packet = b'\\x80\\x08\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00' + (b'\\xd4' * 160)\n\n# Create an outbound policy and session for protection\ntx_policy = Policy(key=key, ssrc_type=Policy.SSRC_ANY_OUTBOUND)\ntx_session = Session(policy=tx_policy)\nsrtp_packet = tx_session.protect(rtp_packet)\n\n# Create an inbound policy and session for unprotection\nrx_policy = Policy(key=key, ssrc_type=Policy.SSRC_ANY_INBOUND)\nrx_session = Session(policy=rx_policy)\nunprotected_rtp_packet = rx_session.unprotect(srtp_packet)\n\n# Verify roundtrip\nassert unprotected_rtp_packet == rtp_packet\nprint(\"SRTP protection and unprotection successful!\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":"libsrtp 2.x and newer when interacting with older libsrtp versions (1.5, 2.0)"},{"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).","message":"pylibsrtp 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"When 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.","severity":"gotcha","affected_versions":"All versions, specifically macOS builds"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}