pylibsrtp

1.0.0 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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!")

view raw JSON →